snapctl 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of snapctl might be problematic. Click here for more details.
- snapctl/__init__.py +0 -0
- snapctl/__main__.py +2 -0
- snapctl/echo.py +11 -0
- snapctl/main.py +138 -0
- snapctl/utils.py +38 -0
- snapctl-0.1.0.dist-info/METADATA +19 -0
- snapctl-0.1.0.dist-info/RECORD +9 -0
- snapctl-0.1.0.dist-info/WHEEL +4 -0
- snapctl-0.1.0.dist-info/entry_points.txt +3 -0
snapctl/__init__.py
ADDED
|
File without changes
|
snapctl/__main__.py
ADDED
snapctl/echo.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
from rich import print
|
|
2
|
+
# Run `python -m rich.emoji` to get a list of all emojis that are supported
|
|
3
|
+
|
|
4
|
+
def error(msg: str) -> None:
|
|
5
|
+
print(f"[bold red]Error[/bold red] {msg}")
|
|
6
|
+
|
|
7
|
+
def info(msg: str) -> None:
|
|
8
|
+
print(f"[bold blue]Info[/bold blue] {msg}")
|
|
9
|
+
|
|
10
|
+
def success(msg: str) -> None:
|
|
11
|
+
print(f"[green]Success[/green] {msg}")
|
snapctl/main.py
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import subprocess
|
|
3
|
+
import typer
|
|
4
|
+
from typing import Optional
|
|
5
|
+
|
|
6
|
+
from snapctl.echo import error, success, info
|
|
7
|
+
from snapctl.utils import get_token_values, check_docker
|
|
8
|
+
from rich.progress import Progress, SpinnerColumn, TextColumn
|
|
9
|
+
|
|
10
|
+
app = typer.Typer()
|
|
11
|
+
|
|
12
|
+
# Constants
|
|
13
|
+
VALID_COMMANDS = {
|
|
14
|
+
'byosnap': ['upload']
|
|
15
|
+
}
|
|
16
|
+
# TOKEN="eyJwYXlsb2FkIjoiZTQ0dEo2dDNnSGhaOVRlYThRcmFyWFhQdVZVMWhxT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aTzFRY2kwNzBPSGpneWhDY0JCdzIwSGZZaW54Uk09IiwidmVyc2lvbiI6IjIiLCJ0eXBlIjoiREFUQV9LRVkiLCJleHBpcmF0aW9uIjoxNjc4NTAzMjc0fQ=="
|
|
17
|
+
# BASE_REPO= '131164543756.dkr.ecr.us-west-2.amazonaws.com'
|
|
18
|
+
# REPO_NAME="sandbox-multi-tools"
|
|
19
|
+
# ECR_PATH=f"{BASE_REPO}/{REPO_NAME}"
|
|
20
|
+
|
|
21
|
+
# Commands
|
|
22
|
+
@app.callback()
|
|
23
|
+
def callback():
|
|
24
|
+
"""
|
|
25
|
+
Snapser CLI Tool
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
# command: Optional[str] = typer.Argument(None)
|
|
29
|
+
@app.command()
|
|
30
|
+
def byosnap(
|
|
31
|
+
command: str = typer.Argument(..., help="Bring your own Commands: " + ", ".join(VALID_COMMANDS['byosnap']) + "."),
|
|
32
|
+
path: str = typer.Argument(..., help="Path to your snap code"),
|
|
33
|
+
tag: str = typer.Argument(..., help="Tag for your snap"),
|
|
34
|
+
token: str = typer.Argument(..., help="Copy the token from the Web App"),
|
|
35
|
+
docker_file: str = typer.Option("Dockerfile", help="Dockerfile name to use")
|
|
36
|
+
):
|
|
37
|
+
"""
|
|
38
|
+
Bring your own code
|
|
39
|
+
"""
|
|
40
|
+
token_list = []
|
|
41
|
+
# Error checking
|
|
42
|
+
with Progress(
|
|
43
|
+
SpinnerColumn(),
|
|
44
|
+
TextColumn("[progress.description]{task.description}"),
|
|
45
|
+
transient=True,
|
|
46
|
+
) as progress:
|
|
47
|
+
progress.add_task(description=f'Checking dependencies...', total=None)
|
|
48
|
+
if not check_docker():
|
|
49
|
+
return error('Docker not present')
|
|
50
|
+
if not command in VALID_COMMANDS['byosnap']:
|
|
51
|
+
error_message: str = 'Invalid command. Valid commands are ' + ', '.join(VALID_COMMANDS['byosnap']) + '.'
|
|
52
|
+
return error(error_message)
|
|
53
|
+
token_list = get_token_values(token)
|
|
54
|
+
if token_list is None:
|
|
55
|
+
error_message: str = 'Invalid token. Please reach out to your support team.'
|
|
56
|
+
return error(error_message)
|
|
57
|
+
|
|
58
|
+
success('Dependencies Verified')
|
|
59
|
+
|
|
60
|
+
# Extract details from the token
|
|
61
|
+
web_app_token = token_list[0]
|
|
62
|
+
service_id = token_list[1]
|
|
63
|
+
ecr_repo_url = token_list[2]
|
|
64
|
+
ecr_repo_username = token_list[3]
|
|
65
|
+
ecr_repo_token = token_list[4]
|
|
66
|
+
|
|
67
|
+
try:
|
|
68
|
+
|
|
69
|
+
# Login to Snapser Registry
|
|
70
|
+
with Progress(
|
|
71
|
+
SpinnerColumn(),
|
|
72
|
+
TextColumn("[progress.description]{task.description}"),
|
|
73
|
+
transient=True,
|
|
74
|
+
) as progress:
|
|
75
|
+
progress.add_task(description=f'Logging into Snapser Image Registry...', total=None)
|
|
76
|
+
response = subprocess.run([
|
|
77
|
+
f'echo "{ecr_repo_token}" | docker login --username {ecr_repo_username} --password-stdin {ecr_repo_url}'
|
|
78
|
+
], shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
|
|
79
|
+
if response.returncode:
|
|
80
|
+
return error('Unable to connect to the Snapser Container Repository. Please get the latest token from the Web app.')
|
|
81
|
+
success('Login Successful')
|
|
82
|
+
|
|
83
|
+
# Build your snap
|
|
84
|
+
with Progress(
|
|
85
|
+
SpinnerColumn(),
|
|
86
|
+
TextColumn("[progress.description]{task.description}"),
|
|
87
|
+
transient=True,
|
|
88
|
+
) as progress:
|
|
89
|
+
progress.add_task(description=f'Building your snap...', total=None)
|
|
90
|
+
response = subprocess.run([
|
|
91
|
+
#f"docker build --no-cache -t {tag} {path}"
|
|
92
|
+
f"docker build -t {service_id}.{tag} {path}"
|
|
93
|
+
], shell=True, )#stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
|
|
94
|
+
if response.returncode:
|
|
95
|
+
return error('Unable to build docker.')
|
|
96
|
+
success('Build Successfull')
|
|
97
|
+
|
|
98
|
+
# Tag the repo
|
|
99
|
+
with Progress(
|
|
100
|
+
SpinnerColumn(),
|
|
101
|
+
TextColumn("[progress.description]{task.description}"),
|
|
102
|
+
transient=True,
|
|
103
|
+
) as progress:
|
|
104
|
+
progress.add_task(description=f'Tagging your snap...', total=None)
|
|
105
|
+
response = subprocess.run([
|
|
106
|
+
f"docker tag {service_id}.{tag} {ecr_repo_url}:{service_id}.{tag}"
|
|
107
|
+
], shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
|
|
108
|
+
if response.returncode:
|
|
109
|
+
return error('Unable to tag your snap.')
|
|
110
|
+
success('Tag Successfull')
|
|
111
|
+
|
|
112
|
+
# Push the image
|
|
113
|
+
with Progress(
|
|
114
|
+
SpinnerColumn(),
|
|
115
|
+
TextColumn("[progress.description]{task.description}"),
|
|
116
|
+
transient=True,
|
|
117
|
+
) as progress:
|
|
118
|
+
progress.add_task(description=f'Pushing your snap...', total=None)
|
|
119
|
+
response = subprocess.run([
|
|
120
|
+
f"docker push {ecr_repo_url}:{service_id}.{tag}"
|
|
121
|
+
], shell=True, )#stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
|
|
122
|
+
if response.returncode:
|
|
123
|
+
return error('Unable to push your snap.')
|
|
124
|
+
success('Snap Upload Successfull')
|
|
125
|
+
|
|
126
|
+
# white_check_mark thumbsup love-you_gesture
|
|
127
|
+
|
|
128
|
+
except Exception as e:
|
|
129
|
+
return error('CLI Error')
|
|
130
|
+
success(f"BYOSnap " + command + ' complete :oncoming_fist:')
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
@app.command()
|
|
134
|
+
def byow():
|
|
135
|
+
"""
|
|
136
|
+
Bring your own workstation
|
|
137
|
+
"""
|
|
138
|
+
typer.echo("Connecting to your cluster")
|
snapctl/utils.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import base64
|
|
2
|
+
import subprocess
|
|
3
|
+
|
|
4
|
+
def check_docker() -> bool:
|
|
5
|
+
try:
|
|
6
|
+
subprocess.run([
|
|
7
|
+
"docker", "--version"
|
|
8
|
+
], stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
|
|
9
|
+
return True
|
|
10
|
+
except:
|
|
11
|
+
return False
|
|
12
|
+
|
|
13
|
+
def get_token_values(token: str) -> None | list:
|
|
14
|
+
try:
|
|
15
|
+
input_token = base64.b64decode(token).decode('ascii')
|
|
16
|
+
token_parts = input_token.split('|')
|
|
17
|
+
# web_app_token|service_id|ecr_repo_url|ecr_repo_username|ecr_repo_token
|
|
18
|
+
if len(token_parts) == 5:
|
|
19
|
+
#token_parts[2] = 'http://131164543756.dkr.ecr.us-west-2.amazonaws.com/adhoc-c1a8eb1f-ee36-4313-bda5-046039ea06b3'
|
|
20
|
+
return token_parts
|
|
21
|
+
if len(token_parts) == 4:
|
|
22
|
+
#token_parts[1] = 'http://131164543756.dkr.ecr.us-west-2.amazonaws.com/adhoc-c1a8eb1f-ee36-4313-bda5-046039ea06b3'
|
|
23
|
+
token_parts.insert(0, '')
|
|
24
|
+
return token_parts
|
|
25
|
+
except Exception:
|
|
26
|
+
pass
|
|
27
|
+
return None
|
|
28
|
+
|
|
29
|
+
# TOKEN_ENV_VAR_NAME = 'SNP_TOKEN'
|
|
30
|
+
# def check_token_env_var() -> bool:
|
|
31
|
+
# if TOKEN_ENV_VAR_NAME in os.environ and os.environ[TOKEN_ENV_VAR_NAME] != '':
|
|
32
|
+
# return True
|
|
33
|
+
# return False
|
|
34
|
+
|
|
35
|
+
# def get_token() -> str:
|
|
36
|
+
# if TOKEN_ENV_VAR_NAME in os.environ and os.environ[TOKEN_ENV_VAR_NAME] != '':
|
|
37
|
+
# return os.environ[TOKEN_ENV_VAR_NAME]
|
|
38
|
+
# return ''
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: snapctl
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Snapser CLI Tool
|
|
5
|
+
Author: Ajinkya Apte
|
|
6
|
+
Author-email: aj@snapser.com
|
|
7
|
+
Requires-Python: >=3.10,<4.0
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
11
|
+
Requires-Dist: typer[all] (>=0.7.0,<0.8.0)
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
|
|
14
|
+
# Snapser CLI Tool
|
|
15
|
+
Snapser CLI Tool
|
|
16
|
+
|
|
17
|
+
## Documentation
|
|
18
|
+
https://typer.tiangolo.com/tutorial/package/
|
|
19
|
+
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
snapctl/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
snapctl/__main__.py,sha256=eBBv0HBPFvCwYs9QrubE2UBd77Yp011-aLK7NPNalEE,47
|
|
3
|
+
snapctl/echo.py,sha256=XZtpDUkBqcbdwF1uuscmQ_X-ENviyeIVE8qzcI7vkdw,321
|
|
4
|
+
snapctl/main.py,sha256=8D5msSsxHFH9CEyKdr1UMiAM8K2rHD82vzlkCa2vtLo,6860
|
|
5
|
+
snapctl/utils.py,sha256=C5fduCoJ8-OASc-xGL2B0MdNSloDtM3K-b1XFu_8VgA,1237
|
|
6
|
+
snapctl-0.1.0.dist-info/METADATA,sha256=H1ciJ5v4jMOqCvJv8SIS9wLETm4IrM8oZUMurLgUB28,490
|
|
7
|
+
snapctl-0.1.0.dist-info/WHEEL,sha256=kLuE8m1WYU0Ig0_YEGrXyTtiJvKPpLpDEiChiNyei5Y,88
|
|
8
|
+
snapctl-0.1.0.dist-info/entry_points.txt,sha256=tkKW9MzmFdRs6Bgkv29G78i9WEBK4WIOWunPfe3t2Wg,44
|
|
9
|
+
snapctl-0.1.0.dist-info/RECORD,,
|