Commit ec59c09e authored by Kostas Papadimitriou's avatar Kostas Papadimitriou
Browse files

Store service access url in database

parent 1ee1c1a3
...@@ -38,7 +38,7 @@ from astakos.im.models import Service ...@@ -38,7 +38,7 @@ from astakos.im.models import Service
class Command(BaseCommand): class Command(BaseCommand):
args = "<name> <endpoint URL>" args = "<name> <service URL> <API URL> "
help = "Register a service" help = "Register a service"
def handle(self, *args, **options): def handle(self, *args, **options):
...@@ -47,6 +47,7 @@ class Command(BaseCommand): ...@@ -47,6 +47,7 @@ class Command(BaseCommand):
name = args[0] name = args[0]
api_url = args[1] api_url = args[1]
url = args[2]
try: try:
s = Service.objects.get(name=name) s = Service.objects.get(name=name)
...@@ -61,7 +62,7 @@ class Command(BaseCommand): ...@@ -61,7 +62,7 @@ class Command(BaseCommand):
raise CommandError(m) raise CommandError(m)
try: try:
s = Service.objects.create(name=name, api_url=api_url) s = Service.objects.create(name=name, api_url=api_url, url=url)
except BaseException as e: except BaseException as e:
raise CommandError("Failed to create service.") raise CommandError("Failed to create service.")
else: else:
......
...@@ -43,10 +43,11 @@ class Command(ListCommand): ...@@ -43,10 +43,11 @@ class Command(ListCommand):
FIELDS = { FIELDS = {
"id": ("id", "ID"), "id": ("id", "ID"),
"name": ("name", "Service Name"), "name": ("name", "Service Name"),
"url": ("api_url", "Service API url"), "url": ("url", "Service url"),
"api_url": ("api_url", "Service API url"),
"token": ("auth_token", "Authentication token"), "token": ("auth_token", "Authentication token"),
"created": ("auth_token_created", "Token creation date"), "created": ("auth_token_created", "Token creation date"),
"expires": ("auth_token_expires", "Token expiration date"), "expires": ("auth_token_expires", "Token expiration date"),
} }
fields = ["id", "name", "url", "token", "created", "expires"] fields = ["id", "name", "url", "api_url", "token", "created", "expires"]
...@@ -50,6 +50,10 @@ class Command(BaseCommand): ...@@ -50,6 +50,10 @@ class Command(BaseCommand):
dest='name', dest='name',
default=None, default=None,
help="Set service name"), help="Set service name"),
make_option('--url',
dest='url',
default=None,
help="Set service url"),
make_option('--api-url', make_option('--api-url',
dest='api_url', dest='api_url',
default=None, default=None,
...@@ -77,6 +81,7 @@ class Command(BaseCommand): ...@@ -77,6 +81,7 @@ class Command(BaseCommand):
name = options.get('name') name = options.get('name')
api_url = options.get('api_url') api_url = options.get('api_url')
url = options.get('url')
auth_token = options.get('auth_token') auth_token = options.get('auth_token')
renew_token = options.get('renew_token') renew_token = options.get('renew_token')
...@@ -86,6 +91,9 @@ class Command(BaseCommand): ...@@ -86,6 +91,9 @@ class Command(BaseCommand):
if api_url: if api_url:
service.api_url = api_url service.api_url = api_url
if url:
service.url = url
if auth_token: if auth_token:
service.auth_token = auth_token service.auth_token = auth_token
......
...@@ -121,6 +121,8 @@ def dict_merge(a, b): ...@@ -121,6 +121,8 @@ def dict_merge(a, b):
class Service(models.Model): class Service(models.Model):
name = models.CharField(_('Name'), max_length=255, unique=True, name = models.CharField(_('Name'), max_length=255, unique=True,
db_index=True) db_index=True)
url = models.CharField(_('Service url'), max_length=255, null=True,
help_text=_("URL the service is accessible from"))
api_url = models.CharField(_('Service API url'), max_length=255, null=True) api_url = models.CharField(_('Service API url'), max_length=255, null=True)
auth_token = models.CharField(_('Authentication Token'), max_length=32, auth_token = models.CharField(_('Authentication Token'), max_length=32,
null=True, blank=True) null=True, blank=True)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment