-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from rehive/feature/1-serviceaccount-operations
Feature/1 serviceaccount operations
- Loading branch information
Showing
17 changed files
with
430 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +0,0 @@ | ||
include VERSION | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
google-api-python-client | ||
invoke==0.18.1 | ||
python-dotenv==0.10.2 | ||
PyYAML==5.1 | ||
semver==2.8.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,8 +8,19 @@ | |
|
||
from setuptools import find_packages, setup | ||
|
||
import tesserarius | ||
|
||
here = path.abspath(path.dirname(__file__)) | ||
|
||
|
||
def parse_requirements(filename): | ||
""" | ||
Load requirements from a pip requirements file | ||
""" | ||
lineiter = (line.strip() for line in open(filename)) | ||
return [line for line in lineiter if line and not line.startswith("#")] | ||
|
||
|
||
# Get the long description from the README file | ||
with open(path.join(here, 'README.rst'), encoding='utf-8') as f: | ||
long_description = f.read() | ||
|
@@ -23,24 +34,25 @@ | |
# Versions should comply with PEP440. For a discussion on single-sourcing | ||
# the version across setup.py and the project code, see | ||
# https://packaging.python.org/en/latest/single_source_version.html | ||
version=open('VERSION').read().strip(), | ||
version=tesserarius.__version__, | ||
# version=version_string, | ||
# version='1.0.6', | ||
|
||
description=( | ||
"CLI that makes it easy to build and deploy an application to k8s."), | ||
"CLI application that make it easier to perform DevOps on " \ | ||
"Kubernetes and GCloud "), | ||
|
||
long_description=long_description, | ||
|
||
# The project's main homepage. | ||
url='https://github.com/kidynamit/tesserarius', | ||
url=tesserarius.__url__, | ||
|
||
# Author details | ||
author='Mwangi', | ||
author_email='[email protected]', | ||
author=tesserarius.__author__, | ||
author_email=tesserarius.__email__, | ||
|
||
# Choose your license | ||
license='MIT License', | ||
license=tesserarius.__license__, | ||
|
||
# See https://pypi.python.org/pypi?:action=list_classifiers | ||
classifiers=[ | ||
|
@@ -68,7 +80,7 @@ | |
# that you indicate whether you support Python 2, Python 3 or both. | ||
'Programming Language :: Python', | ||
'Programming Language :: Python :: 3', | ||
'Programming Language :: Python :: 3.5', | ||
'Programming Language :: Python :: 3.7', | ||
], | ||
|
||
# What does your project relate to? | ||
|
@@ -96,13 +108,7 @@ | |
# your project is installed. For an analysis of "install_requires" vs pip's | ||
# requirements files see: | ||
# https://packaging.python.org/en/latest/requirements.html | ||
install_requires=[ | ||
'invoke<=0.18.1,>=0.15', | ||
'pyyaml', | ||
'python-dotenv>=0.5.1', | ||
'semver', | ||
], | ||
|
||
install_requires= parse_requirements("requirements.txt"), | ||
# List additional groups of dependencies here (e.g. development | ||
# dependencies). You can install these using the following syntax, | ||
# for example: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
from invoke import Collection | ||
|
||
from .tasks import * | ||
from .service_accounts import * | ||
from invoke import Collection, task | ||
__version__ = '0.0.1' | ||
__url__ = 'https://github.com/rehive/tesserarius', | ||
__author__ = 'Mwangi' | ||
__email__ = '[email protected]' | ||
__license__ = 'MIT License' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from tesserarius import Collection | ||
from tesserarius.extensions.serviceaccount import collection as sa_collection | ||
|
||
collection = Collection("extensions") | ||
collection.add_collection(sa_collection, "serviceaccount") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
from tesserarius import task, Collection | ||
from tesserarius.serviceaccount import BaseServiceAccount, BASE_NAME_PATTERN | ||
from tesserarius.utils import get_gcloud_wide_flags, get_settings | ||
|
||
|
||
class ExtensionsServiceAccount(BaseServiceAccount): | ||
project_id = "rehive-services" | ||
|
||
|
||
def __init__(self, | ||
name=None, | ||
display_name=None, | ||
description=None, | ||
base=None): | ||
""" | ||
Checks if self.name has the correct naming convention | ||
platform-<role_name> | ||
short name for the service account describing its purpose. | ||
<role_name> pattern is defined in the tesserarius.serviceaccount | ||
Example: platform-image_store, platform-patroni_wale | ||
""" | ||
name_pattern = r"extensions-[a-z]+-" + BASE_NAME_PATTERN | ||
if name is not None and display_name is not None: | ||
super().__init__(name=name, | ||
display_name=display_name, | ||
description=description, | ||
name_pattern=name_pattern) | ||
# discard base object | ||
base = None | ||
|
||
if base is not None and isinstance(base, BaseServiceAccount): | ||
super().__init__(name=base.name, | ||
display_name=base.display_name, | ||
description=base.description, | ||
name_pattern=name_pattern) | ||
else: | ||
raise ServiceAccountCreateError( | ||
"Invalid arguments provided to create obj.") | ||
|
||
self._check_name() | ||
|
||
|
||
@staticmethod | ||
def create_obj(project="extensions"): | ||
return ExtensionsServiceAccount(base=BaseServiceAccount.create_obj(project)) | ||
|
||
|
||
@task | ||
def create(ctx): | ||
''' | ||
Creates an IAM GCloud Service Account on rehive-services | ||
''' | ||
sa = ExtensionsServiceAccount.create_obj() | ||
sa.create(ctx) | ||
|
||
|
||
@task | ||
def update(ctx): | ||
''' | ||
Updates an IAM GCloud Service Account on rehive-services | ||
''' | ||
sa = ExtensionsServiceAccount.create_obj() | ||
sa.update(ctx) | ||
|
||
|
||
@task | ||
def delete(ctx): | ||
''' | ||
an IAM GCloud Service Account on rehive-services | ||
''' | ||
sa = ExtensionsServiceAccount.create_obj() | ||
sa.delete(ctx) | ||
|
||
collection = Collection("serviceaccount") | ||
collection.add_task(create, "create") | ||
collection.add_task(update, "update") | ||
collection.add_task(delete, "delete") | ||
# collection.add_task(authorize_serviceaccount, "auth") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from tesserarius import Collection | ||
from tesserarius.platform.serviceaccount import collection as sa_collection | ||
|
||
collection = Collection("platform") | ||
collection.add_collection(sa_collection, "serviceaccount") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
from tesserarius import task, Collection | ||
from tesserarius.serviceaccount import BaseServiceAccount, BASE_NAME_PATTERN | ||
from tesserarius.utils import get_gcloud_wide_flags, get_settings | ||
|
||
|
||
class PlatformServiceAccount(BaseServiceAccount): | ||
project_id = "rehive-core" | ||
|
||
|
||
def __init__(self, | ||
name=None, | ||
display_name=None, | ||
description=None, | ||
base=None): | ||
""" | ||
Checks if self.name has the correct naming convention | ||
extensions-<extension_name>-<role_name> | ||
short name for the service account describing its purpose. | ||
<role_name> pattern is defined in the tesserarius.serviceaccount | ||
Example: extensions-product-image_store, extensions-product-patroni_wale | ||
""" | ||
name_pattern = r"platform-" + BASE_NAME_PATTERN | ||
if name is not None and display_name is not None: | ||
super().__init__(name=name, | ||
display_name=display_name, | ||
description=description, | ||
name_pattern=name_pattern) | ||
# discard base object | ||
base = None | ||
|
||
if base is not None and isinstance(base, BaseServiceAccount): | ||
super().__init__(name=base.name, | ||
display_name=base.display_name, | ||
description=base.description, | ||
name_pattern=name_pattern) | ||
else: | ||
raise ServiceAccountCreateError( | ||
"Invalid arguments provided to create obj.") | ||
|
||
self._check_name() | ||
|
||
|
||
@staticmethod | ||
def create_obj(project="platform"): | ||
return PlatformServiceAccount(base=BaseServiceAccount.create_obj(project)) | ||
|
||
|
||
@task | ||
def create(ctx): | ||
''' | ||
Creates an IAM GCloud Service Account on rehive-core | ||
''' | ||
sa = PlatformServiceAccount.create_obj() | ||
sa.create(ctx) | ||
|
||
|
||
@task | ||
def update(ctx): | ||
''' | ||
Updates an IAM GCloud Service Account on rehive-core | ||
''' | ||
sa = PlatformServiceAccount.create_obj() | ||
sa.update(ctx) | ||
|
||
|
||
@task | ||
def delete(ctx): | ||
''' | ||
an IAM GCloud Service Account on rehive-core | ||
''' | ||
sa = PlatformServiceAccount.create_obj() | ||
sa.delete(ctx) | ||
|
||
collection = Collection("serviceaccount") | ||
collection.add_task(create, "create") | ||
collection.add_task(update, "update") | ||
collection.add_task(delete, "delete") | ||
# collection.add_task(authorize_serviceaccount, "auth") |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.