Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/1 serviceaccount operations #3

Merged
merged 4 commits into from
Jun 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
include VERSION
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ DOCKERFILE := etc/docker/Dockerfile
IMAGE_OWNER := rehive
IMAGE_NAME := tesserarius
IMAGE_BASE := alpine
IMAGE_VERSION := $(shell cat VERSION)
IMAGE_VERSION := $(shell python -c "import tesserarius; print(tesserarius.__version__);")
IMAGE_TAG := $(IMAGE_OWNER)/$(IMAGE_NAME):$(IMAGE_VERSION)
CONTAINER_NAME := tessie

Expand Down
1 change: 0 additions & 1 deletion VERSION

This file was deleted.

10 changes: 9 additions & 1 deletion etc/tesserarius/tesserarius.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,13 @@ staging:
kubernetes:
cluster: staging
namespace: tesserarius-staging
extensions:
serviceAccount:
name: extensions-developer
name: extensions-team-developer
displayName: "Extensions Team Developer"
description: "Service account for the Extensions Team Developer"
platform:
serviceAccount:
name: platform-developer
displayName: "Platform Developer"
description: "Service Account for the Platform Developer"
4 changes: 4 additions & 0 deletions requirements.txt
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
34 changes: 20 additions & 14 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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=[
Expand Down Expand Up @@ -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?
Expand Down Expand Up @@ -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:
Expand Down
10 changes: 6 additions & 4 deletions tesserarius/__init__.py
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'
5 changes: 5 additions & 0 deletions tesserarius/extensions/__init__.py
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")
81 changes: 81 additions & 0 deletions tesserarius/extensions/serviceaccount.py
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")
8 changes: 3 additions & 5 deletions tesserarius/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import pkg_resources
from invoke import Argument, Collection, Program

import tesserarius
from tesserarius.tasks import namespace
from tesserarius.extensions import collection as extensions_collection
from tesserarius.platform import collection as platform_collection


class MainProgram(Program):
Expand All @@ -12,9 +14,5 @@ def core_args(self):
]
return core_args + extra_args

namespace = Collection()
namespace.add_collection(tesserarius.tasks.cluster)
namespace.add_collection(tesserarius.service_accounts.collection)

version = pkg_resources.get_distribution("tesserarius").version
program = MainProgram(namespace=namespace, version=version)
5 changes: 5 additions & 0 deletions tesserarius/platform/__init__.py
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")
81 changes: 81 additions & 0 deletions tesserarius/platform/serviceaccount.py
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")
49 changes: 0 additions & 49 deletions tesserarius/service_accounts.py

This file was deleted.

Loading