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
class Command(BaseCommand):
args = "<name> <endpoint URL>"
args = "<name> <service URL> <API URL> "
help = "Register a service"
def handle(self, *args, **options):
......@@ -47,6 +47,7 @@ class Command(BaseCommand):
name = args[0]
api_url = args[1]
url = args[2]
try:
s = Service.objects.get(name=name)
......@@ -61,7 +62,7 @@ class Command(BaseCommand):
raise CommandError(m)
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:
raise CommandError("Failed to create service.")
else:
......
......@@ -43,10 +43,11 @@ class Command(ListCommand):
FIELDS = {
"id": ("id", "ID"),
"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"),
"created": ("auth_token_created", "Token creation 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):
dest='name',
default=None,
help="Set service name"),
make_option('--url',
dest='url',
default=None,
help="Set service url"),
make_option('--api-url',
dest='api_url',
default=None,
......@@ -77,6 +81,7 @@ class Command(BaseCommand):
name = options.get('name')
api_url = options.get('api_url')
url = options.get('url')
auth_token = options.get('auth_token')
renew_token = options.get('renew_token')
......@@ -86,6 +91,9 @@ class Command(BaseCommand):
if api_url:
service.api_url = api_url
if url:
service.url = url
if auth_token:
service.auth_token = auth_token
......
......@@ -121,6 +121,8 @@ def dict_merge(a, b):
class Service(models.Model):
name = models.CharField(_('Name'), max_length=255, unique=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)
auth_token = models.CharField(_('Authentication Token'), max_length=32,
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