refactor of api structure

To make versioning of the api clearer, I've broken up the
api into subfolders and kept the models at the top api layer.

Should make things easier to understand and update.

Change-Id: I357582d6fcc2eaf59ebe721cc4fef3a3e98da492
This commit is contained in:
adriant 2015-07-28 18:00:08 +12:00
parent 93c9806990
commit 36683546e6
24 changed files with 73 additions and 21 deletions

View File

@ -1,3 +1,3 @@
include README.md
include stacktask/*/templates/*
graft stacktask/api/v*/templates

View File

@ -2,6 +2,7 @@
SECRET_KEY: '+er!!4olta#17a=n%uotcazg2ncpl==yjog%1*o-(cr%zys-)!'
ADDITIONAL_APPS:
- stacktask.api.v1
- stacktask.tenant_setup
DATABASES:

View File

@ -4,7 +4,7 @@ from setuptools import setup, find_packages
setup(
name='stacktask',
version='0.1.0a4',
version='0.1.0a5',
description='A user registration service for openstack.',
long_description=(
'A registration service to sit alongside keystone and ' +
@ -23,6 +23,7 @@ setup(
keywords='openstack registration keystone users tasks workflow',
packages=find_packages(),
package_data={'stacktask': ['api/v*/templates/*.txt']},
install_requires=[
'Django>=1.7.3',

View File

@ -13,7 +13,7 @@
# under the License.
from django.contrib import admin
from stacktask.api_v1.models import Token, Registration
from stacktask.api.models import Token, Registration
admin.site.register(Token)
admin.site.register(Registration)

View File

@ -4,7 +4,7 @@ from __future__ import unicode_literals
from django.db import models, migrations
import jsonfield.fields
import django.utils.timezone
import stacktask.api_v1.models
import stacktask.api.models
class Migration(migrations.Migration):
@ -25,7 +25,7 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='Registration',
fields=[
('uuid', models.CharField(default=stacktask.api_v1.models.hex_uuid, max_length=200, serialize=False, primary_key=True)),
('uuid', models.CharField(default=stacktask.api.models.hex_uuid, max_length=200, serialize=False, primary_key=True)),
('reg_ip', models.GenericIPAddressField()),
('keystone_user', jsonfield.fields.JSONField(default={})),
('action_view', models.CharField(max_length=200)),
@ -43,12 +43,12 @@ class Migration(migrations.Migration):
('token', models.CharField(max_length=200, serialize=False, primary_key=True)),
('created', models.DateTimeField(default=django.utils.timezone.now)),
('expires', models.DateTimeField()),
('registration', models.ForeignKey(to='api_v1.Registration')),
('registration', models.ForeignKey(to='api.Registration')),
],
),
migrations.AddField(
model_name='notification',
name='registration',
field=models.ForeignKey(to='api_v1.Registration'),
field=models.ForeignKey(to='api.Registration'),
),
]

15
stacktask/api/tests.py Normal file
View File

@ -0,0 +1,15 @@
# Copyright (C) 2015 Catalyst IT Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from stacktask.api.v1 import tests

20
stacktask/api/urls.py Normal file
View File

@ -0,0 +1,20 @@
# Copyright (C) 2015 Catalyst IT Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from django.conf.urls import patterns, url, include
urlpatterns = patterns(
'',
url(r'^v1/', include('stacktask.api.v1.urls')),
)

View File

View File

@ -0,0 +1,15 @@
# Copyright (C) 2015 Catalyst IT Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from django.db import models

View File

@ -14,7 +14,7 @@
from rest_framework import status
from rest_framework.test import APITestCase
from stacktask.api_v1.models import Registration, Token
from stacktask.api.models import Registration, Token
import mock
from django.utils import timezone
from datetime import timedelta

View File

@ -13,7 +13,7 @@
# under the License.
from django.conf.urls import patterns, url
from stacktask.api_v1 import views
from stacktask.api.v1 import views
urlpatterns = patterns(
'',

View File

@ -15,7 +15,7 @@
from decorator import decorator
from rest_framework.views import APIView
from rest_framework.response import Response
from .models import Registration, Token, Notification
from stacktask.api.models import Registration, Token, Notification
from django.utils import timezone
from datetime import timedelta
from uuid import uuid4

View File

@ -9,7 +9,7 @@ import jsonfield.fields
class Migration(migrations.Migration):
dependencies = [
('api_v1', '0001_initial'),
('api', '0001_initial'),
]
operations = [
@ -25,7 +25,7 @@ class Migration(migrations.Migration):
('need_token', models.BooleanField()),
('order', models.IntegerField()),
('created', models.DateTimeField(default=django.utils.timezone.now)),
('registration', models.ForeignKey(to='api_v1.Registration')),
('registration', models.ForeignKey(to='api.Registration')),
],
),
]

View File

@ -33,7 +33,7 @@ class Action(models.Model):
state = models.CharField(max_length=200, default="default")
valid = models.BooleanField(default=False)
need_token = models.BooleanField()
registration = models.ForeignKey('api_v1.Registration')
registration = models.ForeignKey('api.Registration')
order = models.IntegerField()

View File

@ -13,9 +13,9 @@
# under the License.
from django.test import TestCase
from stacktask.api_v1.models import Registration
from stacktask.api_v1.tests import FakeManager, setup_temp_cache
from stacktask.api_v1 import tests
from stacktask.api.models import Registration
from stacktask.api.v1.tests import FakeManager, setup_temp_cache
from stacktask.api.v1 import tests
from stacktask.base.models import NewUser, NewProject, ResetUser
import mock

View File

@ -51,7 +51,7 @@ INSTALLED_APPS = (
'django.contrib.staticfiles',
'rest_framework',
'stacktask.base',
'stacktask.api_v1',
'stacktask.api',
)
MIDDLEWARE_CLASSES = (

View File

@ -13,9 +13,9 @@
# under the License.
from django.test import TestCase
from stacktask.api_v1.models import Registration
from stacktask.api_v1.tests import FakeManager, setup_temp_cache
from stacktask.api_v1 import tests
from stacktask.api.models import Registration
from stacktask.api.v1.tests import FakeManager, setup_temp_cache
from stacktask.api.v1 import tests
from stacktask.tenant_setup.models import DefaultProjectResources, AddAdminToProject
import mock

View File

@ -18,5 +18,5 @@ from django.contrib import admin
urlpatterns = patterns(
'',
url(r'^admin/', include(admin.site.urls)),
url(r'^v1/', include('stacktask.api_v1.urls')),
url(r'^', include('stacktask.api.urls')),
)