-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for downloading the correct version of kubeseal bin…
…ary (#12)
- Loading branch information
Showing
7 changed files
with
106 additions
and
18 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "kubeseal-auto" | ||
version = "0.3.1" | ||
version = "0.4.0" | ||
description = "An interactive wrapper for kubeseal binary" | ||
authors = ["Vadim Gedz <[email protected]>"] | ||
license = "MIT" | ||
|
@@ -17,6 +17,7 @@ questionary = "^1.10.0" | |
icecream = "^2.1.2" | ||
PyYAML = "^6.0" | ||
colorama = "^0.4.4" | ||
requests = "^2.28.1" | ||
|
||
[tool.poetry.dev-dependencies] | ||
|
||
|
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,65 @@ | ||
import os | ||
import platform | ||
|
||
import click | ||
import requests | ||
from icecream import ic | ||
|
||
|
||
class Host: | ||
def __init__(self): | ||
self.base_url = ( | ||
"https://github.com/bitnami-labs/sealed-secrets/releases/download" | ||
) | ||
self.bin_location = f"{os.path.expanduser('~')}/bin" | ||
self.cpu_type = self._get_cpu_type() | ||
self.system = self._get_system_type() | ||
|
||
@staticmethod | ||
def _get_cpu_type(): | ||
return platform.machine() | ||
|
||
@staticmethod | ||
def _get_system_type(): | ||
if platform.system() == "Darwin": | ||
return "darwin" | ||
elif platform.system() == "Linux": | ||
return "linux" | ||
else: | ||
return "unsupported" | ||
|
||
def _download_kubeseal_binary(self, version: str): | ||
click.echo("Downloading kubeseal binary") | ||
|
||
url = f"{self.base_url}/v{version}/kubeseal-{version}-{self.system}-{self.cpu_type}.tar.gz" | ||
ic(url) | ||
|
||
if not os.path.exists(self.bin_location): | ||
os.makedirs(self.bin_location) | ||
|
||
click.echo(f"Downloading {url}") | ||
with requests.get( | ||
f"{self.base_url}/v{version}/kubeseal-{version}-{self.system}-{self.cpu_type}.tar.gz" | ||
) as r: | ||
with open( | ||
f"/tmp/kubeseal-{version}-{self.system}-{self.cpu_type}.tar.gz", "wb" | ||
) as f: | ||
f.write(r.content) | ||
|
||
os.system( | ||
f"tar -xvf " | ||
f"/tmp/kubeseal-{version}-{self.system}-{self.cpu_type}.tar.gz " | ||
f"-C {self.bin_location} kubeseal" | ||
) | ||
os.rename( | ||
f"{self.bin_location}/kubeseal", f"{self.bin_location}/kubeseal-{version}" | ||
) | ||
os.remove(f"/tmp/kubeseal-{version}-{self.system}-{self.cpu_type}.tar.gz") | ||
|
||
def ensure_kubeseal_binary(self, version: str): | ||
version = version.split("v")[-1] | ||
if not os.path.exists(f"{self.bin_location}/kubeseal-{version}"): | ||
click.echo( | ||
f"kubeseal binary not found at {self.bin_location}/kubeseal-{version}" | ||
) | ||
self._download_kubeseal_binary(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