-
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.
- Loading branch information
Showing
11 changed files
with
754 additions
and
8 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
Empty file.
Empty file.
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,14 @@ | ||
| # import json | ||
| # # import requests | ||
|
|
||
|
|
||
| # def lambda_handler(event, context): | ||
|
|
||
| # personId = event['queryStringParameters']['personId'] | ||
|
|
||
| # return { | ||
| # "statusCode": 200, | ||
| # "body": json.dumps({ | ||
| # "personId": personId + " from Lambda" , | ||
| # }), | ||
| # } |
Empty file.
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,32 @@ | ||
| """ | ||
| Boto client | ||
| TODO: change client to assume role | ||
| """ | ||
|
|
||
| import boto3 | ||
| from botocore.exceptions import ClientError | ||
| from loguru import logger | ||
|
|
||
|
|
||
| class BotoClient: | ||
| def __init__(self, profile, region, service): | ||
| """ | ||
| BotoClient constructor | ||
| """ | ||
| self.profile = profile | ||
| self.region = region | ||
| self.service = service | ||
|
|
||
| def create_client(self): | ||
| """ | ||
| creates a boto session and returns a client for a given profile | ||
| """ | ||
| try: | ||
| session = boto3.session.Session(profile_name=self.profile) | ||
| client = session.client(service_name=self.service, region_name=self.region) | ||
|
|
||
| return client | ||
|
|
||
| except ClientError as error: | ||
| logger.critical(f"error creating client {error}") | ||
| return None |
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,23 @@ | ||
| { | ||
| "attrs": { | ||
| "account_name": "lab-dev-ew", | ||
| "aws_region": "us-gov-east-1", | ||
| "cluster_mailing_list": "matthew.c.morgan@census.gov", | ||
| "cluster_name": "csvd-platform-lab-mcm", | ||
| "eks_instance_disk_size": 100, | ||
| "eks_ng_desired_size": 2, | ||
| "eks_ng_max_size": 10, | ||
| "eks_ng_min_size": 2, | ||
| "environment": "development", | ||
| "environment_abbr": "dev", | ||
| "organization": "census:ocio:csvd", | ||
| "finops_project_name": "csvd_platformbaseline", | ||
| "finops_project_number": "fs0000000078", | ||
| "finops_project_role": "csvd_platformbaseline_app", | ||
| "vpc_domain_name": "dev.lab.csp2.census.gov", | ||
| "vpc_name": "vpc3-lab-dev" | ||
| }, | ||
| "tags" : { | ||
| "slim:schedule": "8:00-17:00" | ||
| } | ||
| } |
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,124 @@ | ||
| ################################################################## | ||
| # Script | ||
| # @usage python main.py | ||
| ################################################################## | ||
| # import os | ||
| import sys | ||
| import json | ||
| from loguru import logger | ||
| from jinja2 import Environment, FileSystemLoader | ||
| from github import Github, Auth | ||
|
|
||
| # import boto3 | ||
| from botocore.exceptions import ClientError | ||
| from .client.client import BotoClient | ||
|
|
||
| # import pygit2 | ||
|
|
||
| CENSUS_GITHUB_API = "https://github.e.it.census.gov/api/v3" | ||
| REGION_NAME = "us-gov-east-1" | ||
| PROFILE = "224384469011-lab-gov-dev-nonprod" | ||
| ORG_NAME = "SCT-Engineering" | ||
|
|
||
|
|
||
| def get_github_token(): | ||
|
|
||
| bc = BotoClient(PROFILE, REGION_NAME, "secretsmanager") | ||
|
|
||
| if bc is None: | ||
| logger.critical("error connecting to AWS") | ||
| logger.critical("exiting...bye") | ||
| sys.exit() | ||
|
|
||
| client = bc.create_client() | ||
|
|
||
| secret_name = "dev/eks_automation_github_token" | ||
|
|
||
| try: | ||
| get_secret_value_response = client.get_secret_value(SecretId=secret_name) | ||
| except ClientError as e: | ||
| raise e | ||
|
|
||
| secret = get_secret_value_response["SecretString"] | ||
|
|
||
| return secret | ||
|
|
||
|
|
||
| def operate_github(): | ||
|
|
||
| token = get_github_token() | ||
|
|
||
| auth = Auth.Token(token) | ||
| g = Github(auth=auth, base_url=CENSUS_GITHUB_API) | ||
| user = g.get_user() | ||
| print(user.login) | ||
|
|
||
| # print(g) | ||
| # org = g.get_organization(ORG_NAME) | ||
|
|
||
| # repo = org.get_repo("platform-tg-infra") | ||
| # print(repo) | ||
|
|
||
| # #create the new repository | ||
| # repo = org.create_repo(projectName, description = projectDescription ) | ||
|
|
||
| # #create some new files in the repo | ||
| # repo.create_file("/README.md", "init commit", readmeText) | ||
|
|
||
| # #Clone the newly created repo | ||
| # repoClone = pygit2.clone_repository(repo.git_url, '/path/to/clone/to') | ||
|
|
||
| # #put the files in the repository here | ||
|
|
||
| # #Commit it | ||
| # repoClone.remotes.set_url("origin", repo.clone_url) | ||
| # index = repoClone.index | ||
| # index.add_all() | ||
| # index.write() | ||
| # author = pygit2.Signature("your name", "your email") | ||
| # commiter = pygit2.Signature("your name", "your email") | ||
| # tree = index.write_tree() | ||
| # oid = repoClone.create_commit( | ||
| # 'refs/heads/master', | ||
| # author, | ||
| # commiter, | ||
| # "init commit", | ||
| # tree, | ||
| # [repoClone.head.get_object().hex] | ||
| # ) | ||
| # remote = repoClone.remotes["origin"] | ||
| # credentials = pygit2.UserPass(userName, password) | ||
| # remote.credentials = credentials | ||
|
|
||
| # callbacks=pygit2.RemoteCallbacks(credentials=credentials) | ||
|
|
||
| # remote.push(['refs/heads/master'],callbacks=callbacks) | ||
|
|
||
|
|
||
| def main(): | ||
| """ | ||
| main entry routine | ||
| """ | ||
| # Open and read the JSON file | ||
| data = "" | ||
| with open("data.json", "r") as file: | ||
| data = json.load(file) | ||
|
|
||
| jinja_env = Environment(loader=FileSystemLoader("templates/"), trim_blocks=True) | ||
| template = jinja_env.get_template("eks.hcl.j2") | ||
| rendered = template.render(data=data) | ||
|
|
||
| print(rendered) | ||
|
|
||
| # with open(template_location, "w") as file_obj: | ||
| # file_obj.write(rendered) | ||
|
|
||
| logger.info("EKS CI/CD pipeline payload has been created!") | ||
|
|
||
| operate_github() | ||
|
|
||
| return True | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
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 |
|---|---|---|
|
|
@@ -5,3 +5,5 @@ pre-commit | |
| loguru | ||
| Jinja2 | ||
| requests | ||
| pygithub | ||
| boto3 | ||
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,10 @@ | ||
| locals { | ||
| {% for key, value in data['attrs'] | items -%} | ||
| {{ key }} = "{{ value }}" | ||
| {% endfor -%} | ||
| tags = { | ||
| {% for key, value in data['tags'] | items -%} | ||
| {{ key }} = "{{ value }}" | ||
| {% endfor -%} | ||
| } | ||
| } |