summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ick2/__init__.py2
-rw-r--r--ick2/controllerapi.py72
-rw-r--r--ick2/projectapi.py86
-rw-r--r--without-tests1
4 files changed, 89 insertions, 72 deletions
diff --git a/ick2/__init__.py b/ick2/__init__.py
index 2b4bae8..abbde96 100644
--- a/ick2/__init__.py
+++ b/ick2/__init__.py
@@ -32,9 +32,9 @@ from .apibase import APIbase, ResourceApiBase
from .buildsapi import BuildsAPI
from .logapi import LogAPI
from .versionapi import VersionAPI
+from .projectapi import ProjectAPI
from .workapi import WorkAPI
from .workerapi import WorkerAPI
from .controllerapi import (
ControllerAPI,
- ProjectAPI,
)
diff --git a/ick2/controllerapi.py b/ick2/controllerapi.py
index 4283e82..4b67d10 100644
--- a/ick2/controllerapi.py
+++ b/ick2/controllerapi.py
@@ -32,7 +32,7 @@ class ControllerAPI:
'/version': ick2.VersionAPI,
'/builds': ick2.BuildsAPI,
'/logs': ick2.LogAPI,
- '/projects': ProjectAPI,
+ '/projects': ick2.ProjectAPI,
'/work': ick2.WorkAPI,
'/workers': ick2.WorkerAPI,
}
@@ -44,73 +44,3 @@ class ControllerAPI:
routes.extend(api.get_routes(path))
ick2.log.log('info', msg_texg='Found routes', routes=routes)
return routes
-
-
-class ProjectAPI(ick2.ResourceApiBase):
-
- def __init__(self, state):
- super().__init__('projects', state)
-
- def get_resource_name(self, resource):
- return resource['project']
-
- def get_routes(self, path): # pragma: no cover
- return super().get_routes(path) + self.get_pipeline_routes(path)
-
- def get_pipeline_routes(self, path): # pragma: no cover
- pipeline_path = '{}/<project>/pipelines/<pipeline>'.format(path)
- builds_path = '{}/<project>/builds'.format(path)
- return [
- {
- 'method': 'GET',
- 'path': pipeline_path,
- 'callback': self.GET(self.get_pipeline),
- },
- {
- 'method': 'PUT',
- 'path': pipeline_path,
- 'callback': self.PUT(self.set_pipeline_callback),
- },
- {
- 'method': 'GET',
- 'path': builds_path,
- 'callback': self.GET(self.get_builds),
- },
- ]
-
- def get_pipeline(self, project, pipeline):
- p = self._state.get_resource(self._type_name, project)
- for pl in p['pipelines']:
- if pl['name'] == pipeline:
- return {
- 'status': pl.get('status', 'idle'),
- }
- raise ick2.NotFound()
-
- def set_pipeline_callback(
- self, body, project, pipeline): # pragma: no cover
- return self.set_pipeline(body['status'], project, pipeline)
-
- def set_pipeline(self, state, project, pipeline):
- allowed_changes = {
- 'idle': 'triggered',
- 'triggered': 'building',
- 'building': 'idle',
- }
- p = self._state.get_resource(self._type_name, project)
- for pl in p['pipelines']:
- if pl['name'] == pipeline:
- old_state = pl.get('status', 'idle')
- if allowed_changes[old_state] != state:
- raise ick2.WrongPipelineStatus(state)
- pl['status'] = state
- self._state.update_resource(self._type_name, project, p)
- return {'status': state}
- raise ick2.NotFound()
-
- def get_builds(self, project):
- p = self._state.get_resource(self._type_name, project)
- return {
- 'project': project,
- 'builds': p.get('builds', []),
- }
diff --git a/ick2/projectapi.py b/ick2/projectapi.py
new file mode 100644
index 0000000..fec4585
--- /dev/null
+++ b/ick2/projectapi.py
@@ -0,0 +1,86 @@
+# Copyright (C) 2017 Lars Wirzenius
+# 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/>.
+
+
+import ick2
+
+
+class ProjectAPI(ick2.ResourceApiBase):
+
+ def __init__(self, state):
+ super().__init__('projects', state)
+
+ def get_resource_name(self, resource):
+ return resource['project']
+
+ def get_routes(self, path): # pragma: no cover
+ return super().get_routes(path) + self.get_pipeline_routes(path)
+
+ def get_pipeline_routes(self, path): # pragma: no cover
+ pipeline_path = '{}/<project>/pipelines/<pipeline>'.format(path)
+ builds_path = '{}/<project>/builds'.format(path)
+ return [
+ {
+ 'method': 'GET',
+ 'path': pipeline_path,
+ 'callback': self.GET(self.get_pipeline),
+ },
+ {
+ 'method': 'PUT',
+ 'path': pipeline_path,
+ 'callback': self.PUT(self.set_pipeline_callback),
+ },
+ {
+ 'method': 'GET',
+ 'path': builds_path,
+ 'callback': self.GET(self.get_builds),
+ },
+ ]
+
+ def get_pipeline(self, project, pipeline):
+ p = self._state.get_resource(self._type_name, project)
+ for pl in p['pipelines']:
+ if pl['name'] == pipeline:
+ return {
+ 'status': pl.get('status', 'idle'),
+ }
+ raise ick2.NotFound()
+
+ def set_pipeline_callback(
+ self, body, project, pipeline): # pragma: no cover
+ return self.set_pipeline(body['status'], project, pipeline)
+
+ def set_pipeline(self, state, project, pipeline):
+ allowed_changes = {
+ 'idle': 'triggered',
+ 'triggered': 'building',
+ 'building': 'idle',
+ }
+ p = self._state.get_resource(self._type_name, project)
+ for pl in p['pipelines']:
+ if pl['name'] == pipeline:
+ old_state = pl.get('status', 'idle')
+ if allowed_changes[old_state] != state:
+ raise ick2.WrongPipelineStatus(state)
+ pl['status'] = state
+ self._state.update_resource(self._type_name, project, p)
+ return {'status': state}
+ raise ick2.NotFound()
+
+ def get_builds(self, project):
+ p = self._state.get_resource(self._type_name, project)
+ return {
+ 'project': project,
+ 'builds': p.get('builds', []),
+ }
diff --git a/without-tests b/without-tests
index 760d380..35e54f5 100644
--- a/without-tests
+++ b/without-tests
@@ -4,6 +4,7 @@ ick2/buildsapi.py
ick2/exceptions.py
ick2/logapi.py
ick2/logging.py
+ick2/projectapi.py
ick2/responses.py
ick2/version.py
ick2/versionapi.py