summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2019-10-18 10:49:20 +0300
committerLars Wirzenius <liw@liw.fi>2019-10-18 10:49:20 +0300
commitcd41fb97dcf8b2c271090c44a6d299f8f87c6217 (patch)
tree92024d274bb26090af42ddb97d423c2d4786f3b5
parent57a27b0432a0d9b8877ea50a554294326302e7da (diff)
downloadick2-cd41fb97dcf8b2c271090c44a6d299f8f87c6217.tar.gz
Revert "Add: TokenGetter"
This reverts commit 7a6bc2f7749c10c1d3344ea0196e81ae95b7f0d7.
-rw-r--r--ick2/__init__.py1
-rw-r--r--ick2/apibase.py4
-rw-r--r--ick2/controllerapi.py10
-rw-r--r--ick2/projectapi.py2
-rw-r--r--ick2/projectapi_tests.py11
-rw-r--r--ick2/tokengetter.py70
-rw-r--r--ick2/workapi.py3
-rw-r--r--ick2/workapi_tests.py16
-rw-r--r--ick2/workerapi.py3
-rw-r--r--ick_controller.py6
-rw-r--r--without-tests1
11 files changed, 8 insertions, 119 deletions
diff --git a/ick2/__init__.py b/ick2/__init__.py
index 586ddb5..235ee96 100644
--- a/ick2/__init__.py
+++ b/ick2/__init__.py
@@ -89,7 +89,6 @@ from .client import (
AuthClient,
Reporter,
)
-from .tokengetter import TokenGetter
from .actionenvs import (
Runner,
ActionEnvironment,
diff --git a/ick2/apibase.py b/ick2/apibase.py
index 0537b6b..46c17cf 100644
--- a/ick2/apibase.py
+++ b/ick2/apibase.py
@@ -26,10 +26,6 @@ class APIbase:
isinstance(state, ick2.MemoryStore) or
isinstance(state, ick2.MuckStore))
self._trans = ick2.TransactionalState(state)
- self._token_getter = None
-
- def set_token_getter(self, getter): # pragma: no cover
- self._token_getter = getter
def get_routes(self, path):
resource_path = '{}/<name:re:[^/+][^/]*?(/[^/+][^/]*?)*>'.format(path)
diff --git a/ick2/controllerapi.py b/ick2/controllerapi.py
index a673e0d..b28e1f7 100644
--- a/ick2/controllerapi.py
+++ b/ick2/controllerapi.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2017-2019 Lars Wirzenius
+# Copyright (C) 2017-2018 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
@@ -18,9 +18,8 @@ import ick2
class ControllerAPI:
- def __init__(self, state, token_getter):
+ def __init__(self, state):
self._state = state
- self._token_getter = token_getter
self._apis = {}
def set_apt_server(self, domain): # pragma: no cover
@@ -31,7 +30,6 @@ class ControllerAPI:
def set_auth_url(self, url): # pragma: no cover
self._set_url('set_auth_url', url)
- self._token_getter.set_auth_url(url)
def set_notify_url(self, url): # pragma: no cover
self._set_url('set_notify_url', url)
@@ -62,9 +60,7 @@ class ControllerAPI:
for path in apis:
if path not in self._apis:
- api = apis[path](self._state)
- api.set_token_getter(self._token_getter)
- self._apis[path] = api
+ self._apis[path] = apis[path](self._state)
routes = []
for path, api in self._apis.items():
diff --git a/ick2/projectapi.py b/ick2/projectapi.py
index 00fce8a..a854716 100644
--- a/ick2/projectapi.py
+++ b/ick2/projectapi.py
@@ -50,7 +50,7 @@ class ProjectAPI(ick2.ResourceApiBase):
]
def trigger_project(self, project, **kwargs): # pragma: no cover
- token = self._token_getter.get_token()
+ token = 'FIXME'
with self._trans.modify(token, 'projects', project) as p:
self._start_build(token, p)
return {'status': ick2.BUILD_TRIGGERED}
diff --git a/ick2/projectapi_tests.py b/ick2/projectapi_tests.py
index bdb58d1..f8b3c2a 100644
--- a/ick2/projectapi_tests.py
+++ b/ick2/projectapi_tests.py
@@ -20,12 +20,6 @@ import unittest
import ick2
-class DummyTokenGetter:
-
- def get_token(self):
- return 'DUMMY.TOKEN'
-
-
class ProjectAPITests(unittest.TestCase):
def setUp(self):
@@ -35,10 +29,7 @@ class ProjectAPITests(unittest.TestCase):
return ick2.ProjectAPI(self.state)
def create_pipeline_api(self):
- getter = DummyTokenGetter()
- api = ick2.PipelineAPI(self.state)
- api.set_token_getter(getter)
- return api
+ return ick2.PipelineAPI(self.state)
def test_has_not_projects_initially(self):
api = self.create_api()
diff --git a/ick2/tokengetter.py b/ick2/tokengetter.py
deleted file mode 100644
index c152148..0000000
--- a/ick2/tokengetter.py
+++ /dev/null
@@ -1,70 +0,0 @@
-# Copyright (C) 2019 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 time
-
-
-import jwt
-
-
-import ick2
-
-
-class TokenGetter:
-
- scopes = [
- 'super',
- 'create',
- 'update',
- 'show',
- 'delete',
- 'uapi_workers_post',
- 'uapi_workers_id_get',
- 'uapi_workers_id_put',
- 'uapi_workers_id_delete',
- 'uapi_builds_post',
- 'uapi_builds_id_get',
- 'uapi_builds_id_put',
- 'uapi_builds_id_delete',
- 'uapi_logs_post',
- 'uapi_logs_id_get',
- 'uapi_logs_id_put',
- 'uapi_logs_id_delete',
- ]
-
- def __init__(self, client_id, client_secret):
- self._ac = ick2.AuthClient()
- self._ac.set_client_creds(client_id, client_secret)
- self._token = None
- self._token_exp = None
-
- def set_auth_url(self, auth_url):
- self._ac.set_auth_url(auth_url)
-
- def get_token(self):
- if not self._got_valid_token():
- self._get_new_token()
- return self._token
-
- def _got_valid_token(self):
- fuzz = 10
- return (self._token is not None and
- self._token_exp is not None and
- time.time() + fuzz < self._token_exp)
-
- def _get_new_token(self):
- self._token = self._ac.get_token(' '.join(self.scopes))
- parsed = jwt.decode(self._token, verify=False)
- self._token_exp = parsed['exp']
diff --git a/ick2/workapi.py b/ick2/workapi.py
index 7ff6f93..3eeb0fa 100644
--- a/ick2/workapi.py
+++ b/ick2/workapi.py
@@ -41,7 +41,6 @@ class WorkAPI(ick2.APIbase):
]
def get_work(self, token=None, **kwargs):
- token = self._token_getter.get_token()
worker_id = self._get_client_id(**kwargs)
ick2.log.log(
'trace', msg_text='Worker wants work', worker_id=worker_id)
@@ -141,8 +140,6 @@ class WorkAPI(ick2.APIbase):
return None
def update_work(self, update, token=None, **kwargs):
- token = self._token_getter.get_token()
-
try:
worker_id = update['worker']
build_id = update['build_id']
diff --git a/ick2/workapi_tests.py b/ick2/workapi_tests.py
index 0ac3a86..72bcaf1 100644
--- a/ick2/workapi_tests.py
+++ b/ick2/workapi_tests.py
@@ -36,9 +36,7 @@ class WorkAPITests(unittest.TestCase):
],
}
- getter = DummyTokenGetter()
pipeapi = ick2.PipelineAPI(self.state)
- pipeapi.set_token_getter(getter)
pipeapi.create(pipeline)
project = {
@@ -49,7 +47,6 @@ class WorkAPITests(unittest.TestCase):
'pipelines': ['build'],
}
api = ick2.ProjectAPI(self.state)
- api.set_token_getter(getter)
api.create(project)
return api
@@ -60,17 +57,12 @@ class WorkAPITests(unittest.TestCase):
self.claims = {
'aud': 'asterix',
}
- getter = DummyTokenGetter()
api = ick2.WorkerAPI(self.state)
- api.set_token_getter(getter)
api.create(worker, claims=self.claims)
return api
def create_work_api(self):
- getter = DummyTokenGetter()
- api = ick2.WorkAPI(self.state)
- api.set_token_getter(getter)
- return api
+ return ick2.WorkAPI(self.state)
def test_worker_gets_no_work_when_no_builds_have_been_triggered(self):
self.create_project_api()
@@ -295,9 +287,3 @@ class WorkAPITests(unittest.TestCase):
# Ask for work again.
self.assertEqual(work.get_work(claims=self.claims), {})
-
-
-class DummyTokenGetter:
-
- def get_token(self):
- return 'DUMMY.TOKEN'
diff --git a/ick2/workerapi.py b/ick2/workerapi.py
index 9a2c5f2..d4b508c 100644
--- a/ick2/workerapi.py
+++ b/ick2/workerapi.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2017-2019 Lars Wirzenius
+# Copyright (C) 2017-2018 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
@@ -34,5 +34,4 @@ class WorkerAPI(ick2.ResourceApiBase): # pragma: no cover
def create(self, body, **kwargs):
client_id = self._get_client_id(**kwargs)
body['worker'] = client_id
- kwargs['token'] = self._token_getter.get_token()
return super().create(body, **kwargs)
diff --git a/ick_controller.py b/ick_controller.py
index 7299e60..62ccaef 100644
--- a/ick_controller.py
+++ b/ick_controller.py
@@ -51,8 +51,6 @@ default_config = {
'auth-url': None,
'notify-url': None,
'apt-server': None,
- 'client-id': None,
- 'client-secret': None,
}
@@ -98,9 +96,7 @@ def main():
state = ick2.MuckStore(config['muck-url'])
- getter = ick2.TokenGetter(config['client-id'], config['client-secret'])
-
- api = ick2.ControllerAPI(state, getter)
+ api = ick2.ControllerAPI(state)
api.set_apt_server(config['apt-server'])
api.set_artifact_store_url(config['artifact-store'])
api.set_auth_url(config['auth-url'])
diff --git a/without-tests b/without-tests
index 673068e..ca8a65a 100644
--- a/without-tests
+++ b/without-tests
@@ -11,7 +11,6 @@ ick2/notificationapi.py
ick2/pipelineapi.py
ick2/resource.py
ick2/responses.py
-ick2/tokengetter.py
ick2/trans.py
ick2/sendmail.py
ick2/version.py