add initial version
This commit is contained in:
parent
faa181f9c5
commit
eae77f8ff6
|
@ -0,0 +1,4 @@
|
|||
include MANIFEST.in
|
||||
include COPYING
|
||||
include README
|
||||
include VERSION
|
|
@ -0,0 +1,18 @@
|
|||
Adaption of Passerelle Cart@DS CS plugin for Grand Lyon environment
|
||||
===================================================================
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
This program is free software: you can redistribute it and/or modify it under
|
||||
the terms of the GNU Affero General Public License as published by the Free
|
||||
Software Foundation, either version 3 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License along
|
||||
with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
@ -0,0 +1,42 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.12 on 2019-03-21 08:20
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
('base', '0012_job'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='GLCartaDSCS',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('title', models.CharField(max_length=50, verbose_name='Title')),
|
||||
('description', models.TextField(verbose_name='Description')),
|
||||
('slug', models.SlugField(unique=True, verbose_name='Identifier')),
|
||||
('wsdl_base_url', models.URLField(help_text='ex: https://example.net/adscs/webservices/', verbose_name='WSDL Base URL')),
|
||||
('username', models.CharField(max_length=64, verbose_name='Username')),
|
||||
('password', models.CharField(max_length=64, verbose_name='Password')),
|
||||
('iv', models.CharField(max_length=16, verbose_name='Initialisation Vector')),
|
||||
('secret_key', models.CharField(max_length=16, verbose_name='Secret Key')),
|
||||
('ftp_server', models.CharField(max_length=128, verbose_name='FTP Server')),
|
||||
('ftp_username', models.CharField(max_length=64, verbose_name='FTP Username')),
|
||||
('ftp_password', models.CharField(max_length=64, verbose_name='FTP Password')),
|
||||
('ftp_client_name', models.CharField(max_length=64, verbose_name='FTP Client Name')),
|
||||
('token_url', models.URLField(max_length=256, verbose_name='Token URL')),
|
||||
('token_authorization', models.CharField(max_length=128, verbose_name='Token Authorization')),
|
||||
('verify_cert', models.BooleanField(default=True, verbose_name='Check HTTPS Certificate validity')),
|
||||
('users', models.ManyToManyField(blank=True, to='base.ApiUser')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Cart@DS CS (@ Grand Lyon)',
|
||||
},
|
||||
),
|
||||
]
|
|
@ -0,0 +1,65 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# passerelle-grandlyon-cartads-cs
|
||||
# support for Cart@DS CS connector in Grand Lyon environment
|
||||
# Copyright (C) 2019 Entr'ouvert
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU Affero General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from django.core.cache import cache
|
||||
from django.db import models
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from passerelle.apps.cartads_cs.models import AbstractCartaDSCS
|
||||
from passerelle.utils import SOAPTransport
|
||||
|
||||
class Transport(SOAPTransport):
|
||||
def post(self, address, message, headers):
|
||||
headers['Authorization'] = self.resource.get_api_manager_token()
|
||||
response = super(Transport, self).post(address, message, headers)
|
||||
if response.status_code == 401:
|
||||
# ask for a new token and retry
|
||||
headers['Authorization'] = self.resource.get_api_manager_token(renew=True)
|
||||
response = super(Transport, self).post(address, message, headers)
|
||||
return response
|
||||
|
||||
|
||||
class GLCartaDSCS(AbstractCartaDSCS):
|
||||
category = 'Grand Lyon'
|
||||
soap_transport_class = Transport
|
||||
|
||||
token_url = models.URLField(_('Token URL'), max_length=256)
|
||||
token_authorization = models.CharField(_('Token Authorization'), max_length=128)
|
||||
verify_cert = models.BooleanField(default=True,
|
||||
verbose_name=_('Check HTTPS Certificate validity'))
|
||||
|
||||
class Meta:
|
||||
verbose_name = 'Cart@DS CS (@ Grand Lyon)'
|
||||
|
||||
def get_api_manager_token(self, renew=False):
|
||||
cache_key = 'cartads-%s-token' % self.id
|
||||
if not renew:
|
||||
token = cache.get(cache_key)
|
||||
if token:
|
||||
return token
|
||||
headers = {'Authorization': 'Basic %s' % self.token_authorization}
|
||||
resp = self.requests.post(
|
||||
self.token_url,
|
||||
headers=headers,
|
||||
data={'grant_type': 'client_credentials'},
|
||||
verify=self.verify_cert).json()
|
||||
token = '%s %s' % (resp.get('token_type'), resp.get('access_token'))
|
||||
timeout = int(resp.get('expires_in'))
|
||||
cache.set(cache_key, token, timeout)
|
||||
self.logger.debug('new token: %s (timeout %ss)', token, timeout)
|
||||
return token
|
|
@ -0,0 +1,57 @@
|
|||
#! /usr/bin/env python
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
from setuptools import setup, find_packages
|
||||
from distutils.command.sdist import sdist
|
||||
|
||||
class eo_sdist(sdist):
|
||||
def run(self):
|
||||
if os.path.exists('VERSION'):
|
||||
os.remove('VERSION')
|
||||
version = get_version()
|
||||
version_file = open('VERSION', 'w')
|
||||
version_file.write(version)
|
||||
version_file.close()
|
||||
sdist.run(self)
|
||||
if os.path.exists('VERSION'):
|
||||
os.remove('VERSION')
|
||||
|
||||
|
||||
def get_version():
|
||||
'''Use the VERSION, if absent generates a version with git describe, if not
|
||||
tag exists, take 0.0- and add the length of the commit log.
|
||||
'''
|
||||
if os.path.exists('VERSION'):
|
||||
with open('VERSION', 'r') as v:
|
||||
return v.read()
|
||||
if os.path.exists('.git'):
|
||||
p = subprocess.Popen(['git','describe','--dirty=.dirty','--match=v*'],
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
result = p.communicate()[0]
|
||||
if p.returncode == 0:
|
||||
result = result.decode('ascii').strip()[1:] # strip spaces/newlines and initial v
|
||||
if '-' in result: # not a tagged version
|
||||
real_number, commit_count, commit_hash = result.split('-', 2)
|
||||
version = '%s.post%s+%s' % (real_number, commit_count, commit_hash)
|
||||
else:
|
||||
version = result
|
||||
return version
|
||||
else:
|
||||
return '0.0.post%s' % len(
|
||||
subprocess.check_output(
|
||||
['git', 'rev-list', 'HEAD']).splitlines())
|
||||
return '0.0'
|
||||
|
||||
|
||||
setup(
|
||||
name='passerelle-grandlyon-cartads-cs',
|
||||
version=get_version(),
|
||||
author="Entr'ouvert",
|
||||
author_email="info@entrouvert.com",
|
||||
packages=find_packages(),
|
||||
cmdclass={
|
||||
'sdist': eo_sdist,
|
||||
}
|
||||
)
|
Reference in New Issue