-
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
Davi Mello
authored and
Davi Mello
committed
Jan 27, 2021
1 parent
1ec8aff
commit 549f0c1
Showing
14 changed files
with
207 additions
and
16 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 +1,2 @@ | ||
|
||
export MAGI_YAML_AUTH_BASIC_USER=admin | ||
export MAGI_YAML_AUTH_BASIC_PASS=admin |
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 click | ||
from magi.execution import run | ||
|
||
|
||
|
||
@click.command() | ||
@click.option('-d', '--dir', 'directory', required=True, help='The directory of yaml file to do deploy.') | ||
# @click.option('-f', '--file', 'file', required=False, help='The yaml file name (file.: input.yaml || use .: input ) to do deploy.') | ||
def command(directory: str = ""): | ||
run(folder_path=directory) | ||
|
||
|
||
if __name__ == '__main__': | ||
command() |
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 os | ||
from magi.nodesolver import nodesolver | ||
from magi.readfiles import read_yaml_files | ||
from magi.rest_engine import rest_call | ||
|
||
def run(folder_path:str=None)->None: | ||
|
||
YAMLS_ON_FOLDER : dict = read_yaml_files(folder_path) | ||
|
||
for yaml in YAMLS_ON_FOLDER: | ||
request_list : list = nodesolver(YAMLS_ON_FOLDER[yaml]) | ||
for rest_request in request_list: | ||
rest_call(**rest_request) | ||
|
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,10 @@ | ||
import requests | ||
import logging | ||
|
||
|
||
def rest_call(rest_engine = requests.request, **kwargs) -> int: | ||
call : requests.Response = rest_engine(**kwargs) | ||
logging.info(msg=f"REST_CALL: {kwargs['url']} -> method : {kwargs['method']} -> status_code : {call.status_code}") | ||
logging.debug(msg=f"JSON : {kwargs['url']}") | ||
print(f"REST_CALL: {kwargs['url']} -> method : {kwargs['method']} -> status_code : {call.status_code}") | ||
return call.status_code |
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,17 @@ | ||
import os | ||
|
||
def replace_by_sys_variables(metadata_raw:dict, sys_var_prefix:str="MAGI_YAML") -> None: | ||
""" | ||
This method change the input object in memory. | ||
""" | ||
|
||
metadata: dict = metadata_raw | ||
|
||
for key in metadata: | ||
sys_var: str = f"{sys_var_prefix}_{str(key).upper()}" | ||
if isinstance(metadata[key], dict): | ||
replace_by_sys_variables(metadata_raw=metadata[key], sys_var_prefix=sys_var) | ||
|
||
elif os.getenv(sys_var): | ||
metadata[key] = os.getenv(sys_var) | ||
|
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 |
---|---|---|
|
@@ -3,4 +3,5 @@ pytest==6.2.1 | |
coverage==5.3.1 | ||
setuptools==51.3.3 | ||
wheel==0.36.2 | ||
twine==3.3.0 | ||
twine==3.3.0 | ||
responses==0.12.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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
requests==2.25.1 | ||
pyaml==20.4.0 | ||
pyaml==20.4.0 | ||
click==7.1.2 |
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,10 @@ | ||
metadata: #basic_info | ||
auth: | ||
basic: | ||
user: "admin" | ||
password: "admin" | ||
url: "http://127.0.0.1:8081" | ||
requests: | ||
test_default: #By default the "magi" will do a get | ||
- url: "/service/rest/v1/repositories/docker/hosted" | ||
- url: "/service/rest/v1/repositories" |
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,22 @@ | ||
metadata: #basic_info | ||
auth: | ||
basic: | ||
user: "admin" | ||
password: "admin" | ||
url: "http://127.0.0.1:8081" | ||
requests: | ||
test_default: #By default the "magi" will do a get | ||
- url: "/service/rest/v1/repositories" | ||
- url: "/service/rest/v1/repositories/helm/hosted" | ||
method: 'post' | ||
json: | ||
name: internal_2 | ||
online: true | ||
storage: | ||
blobStoreName: default | ||
strictContentTypeValidation: true | ||
writePolicy: allow_once | ||
cleanup: | ||
policyNames: | ||
- string | ||
|
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,44 @@ | ||
import unittest | ||
import responses | ||
import requests | ||
import os | ||
from magi.rest_engine import rest_call | ||
|
||
# Project Magi dependencies | ||
from magi.nodesolver import nodesolver | ||
from magi.readfiles import read_yaml_files | ||
from magi.rest_engine import rest_call | ||
|
||
|
||
|
||
FOLDER: str = f"{os.path.dirname(__file__)}/mock" | ||
CASE1: str = read_yaml_files(f"{FOLDER}/alpha") | ||
YAML: str = CASE1["mock_test_1"] | ||
request_list : list = nodesolver(YAML) | ||
|
||
|
||
TEST_CASE_1_1 = { | ||
"method": "GET", | ||
"url": "http://mock.site.localhost/dummy", | ||
"status": 200 | ||
} | ||
|
||
TEST_CASE_1_2 = { | ||
"method": "GET", | ||
"url": "http://mock.site.localhost/dummy_2", | ||
"status": 200 | ||
} | ||
|
||
class Test_rest_engine(unittest.TestCase): | ||
|
||
@responses.activate | ||
def test_rest_call(self): | ||
status_code: int = 200 | ||
# Using request Lib | ||
responses.add(**TEST_CASE_1_1) | ||
responses.add(**TEST_CASE_1_2) | ||
|
||
for rest_request in request_list: | ||
print(rest_request["url"]) | ||
self.assertEqual(status_code, rest_call(**rest_request)) | ||
|
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,31 @@ | ||
import os | ||
import unittest | ||
from magi.sys_env import replace_by_sys_variables | ||
|
||
|
||
class Test_sys_env(unittest.TestCase): | ||
|
||
def test_replace_by_sys_variables(self): | ||
CASE : dict = { | ||
"test": { | ||
"user": "hello", | ||
"pass": "pass" | ||
} | ||
} | ||
|
||
CASE_out : dict = { | ||
"test": { | ||
"user": "test", | ||
"pass": "test_Pass0rd" | ||
} | ||
} | ||
|
||
os.environ["MAGI_YAML_TEST_USER"] = CASE_out["test"]["user"] | ||
os.environ["MAGI_YAML_TEST_PASS"] = CASE_out["test"]["pass"] | ||
|
||
|
||
self.assertIsNone(replace_by_sys_variables(CASE.copy())) | ||
|
||
replace_by_sys_variables(CASE.copy()) | ||
self.assertIsInstance(CASE, dict) | ||
self.assertEqual(CASE, CASE_out) |