Skip to content

Commit 1a65bd5

Browse files
author
Gunther Klessinger
committed
feat: show env
1 parent a0a9c34 commit 1a65bd5

File tree

7 files changed

+55
-22
lines changed

7 files changed

+55
-22
lines changed

environ

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ NAME="company"
88
#
99
# For others use py:...
1010
DNS_API_TOKEN="py:keyval"
11-
GITOPS_TOKEN="py:keyval"
1211
HCLOUD_TOKEN="py:keyval"
1312
HCLOUD_TOKEN_WRITE="py:keyval"
1413

@@ -27,4 +26,4 @@ GITOPS_HOST="py:keyval"
2726
GITOPS_OWNER="company"
2827
GITOPS_PATH="clusters/staging"
2928
GITOPS_REPO="k8s"
30-
GITOPS_TOKEN=""
29+
GITOPS_TOKEN="py:keyval"

justfile

+14-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ set export
66
set unstable
77
set script-interpreter := ['uv', 'run']
88
alias c := create-cluster
9-
alias cfg := render-config
9+
alias cfg := pyhk3-config
1010
alias t := test
1111
alias p := pyhk3
1212
alias pf := port-forward
@@ -24,11 +24,10 @@ do *ARGS:
2424
ssh *ARGS:
2525
just p do ssh {{ARGS}}
2626

27-
render-config:
27+
pyhk3-config *ARGS:
2828
just p hk3s render_config
29-
30-
port-forward:
31-
just p do port_forward
29+
just p do show_env {{ARGS}}
30+
3231

3332
[confirm('Sure to destroy all servers of the cluster?')]
3433
rm:
@@ -49,8 +48,17 @@ create-cluster:
4948
download-kubectl:
5049
just p do download_kubectl
5150

51+
# enables a port-forward to proxy, so that kubectl, when downloaded, can be used
52+
port-forward:
53+
just p do port_forward
54+
55+
56+
install-gitops:
57+
just p gitops install
58+
59+
5260
test:
53-
just render-config
61+
just pyhk3-config
5462
uv run pytest ./tests/test_setup.py
5563

5664
publish:

keyval.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@
1111
sec = {}
1212

1313

14+
DNS_API_TOKEN = sec.get('DNS_API_TOKEN', '...')
1415
DOMAIN = sec.get('DOMAIN', 'cluster.company.net')
1516
EMAIL = sec.get('EMAIL', '[email protected]')
1617
FN_SSH_KEY = sec.get('FN_SSH_KEY', '~/.ssh/hetzner-cluster')
1718
GITOPS_HOST = sec.get('GITOPS_HOST', 'gitlab.company.com')
18-
19-
DNS_API_TOKEN = sec.get('DNS_API_TOKEN', '...')
2019
GITOPS_TOKEN = sec.get('GITOPS_TOKEN', '...')
2120
HCLOUD_TOKEN = sec.get('HCLOUD_TOKEN', '...')
2221
HCLOUD_TOKEN_WRITE = sec.get('HCLOUD_TOKEN_WRITE', '...')

src/pyhk3/cli.py

+17-10
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,22 @@
44
from inspect import signature as sig
55
from functools import partial
66
from .create import create, hk3s
7+
from .gitops import gitops
78
from .do import do, recover
89
from rich.console import Console
910
from rich.tree import Tree
1011

12+
13+
class pyhk3:
14+
"""main class"""
15+
16+
create = create
17+
do = do
18+
recover = recover
19+
hk3s = hk3s
20+
gitops = gitops
21+
22+
1123
console = Console()
1224

1325

@@ -20,8 +32,10 @@ def tc(cls):
2032
return f'{B(cls.__name__)} {D(cls)}'
2133

2234

23-
def tv(fnc):
24-
return f'{fnc.__name__} {D(fnc)}'
35+
def tv(fnc, name='xxx'):
36+
n = fnc.__name__
37+
n = '' if n == name else n
38+
return f'{n} {D(fnc)}'
2539

2640

2741
def cls_help(cls, inittree=None):
@@ -33,7 +47,7 @@ def cls_help(cls, inittree=None):
3347
cls_help(v, tr)
3448
continue
3549
if not isinstance(v, list):
36-
tree.add(f'{B(k)} {tv(v)}')
50+
tree.add(f'{B(k)} {tv(v, name=k)}')
3751
continue
3852
tr = tree.add(B(k))
3953
for m in v:
@@ -43,13 +57,6 @@ def cls_help(cls, inittree=None):
4357
sys.exit(0)
4458

4559

46-
class pyhk3:
47-
create = create
48-
do = do
49-
recover = recover
50-
hk3s = hk3s
51-
52-
5360
def create_partial(funcs, args, argv, x):
5461
"""the last func in a argv list may have arguments which we map here to a partial of that func"""
5562
args.pop(0)

src/pyhk3/do.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import yaml
2-
2+
from .defaults import envdefaults
3+
from .tools import env
34
from .create import hk3s, tools, local
45
from .hapi import by_name, hapi, ips, need_env
56
from .tools import die, log, shw, ssh
@@ -57,8 +58,19 @@ def hk3sconfig():
5758
shw(hk3s.recover_config)
5859

5960

61+
def show_env(match=''):
62+
for k in sorted(envdefaults.__dict__):
63+
if k[0] != '_' and match in k.lower():
64+
kl = k.lower()
65+
v = env(k)
66+
if 'token' in kl or 'secret' in kl or 'pass' in kl:
67+
v = v[:4] + '*' * min(50, (len(v) - 4))
68+
print(f'{k}={v}')
69+
70+
6071
class do:
6172
ssh = run_remote
6273
delete = delete
6374
download_kubectl = local.download_kubectl
6475
port_forward = port_forward
76+
show_env = show_env

src/pyhk3/gitops.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
def install():
2+
breakpoint() # FIXME BREAKPOINT
3+
print('gitops install')
4+
5+
6+
class gitops:
7+
install = install

src/pyhk3/tools.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ def env(key, dflt=None):
8383
v = getattr(envdefaults, key, dflt)
8484
if str(v).startswith('py:'):
8585
v = pyval(key, v[3:], dflt)
86-
elif str(v).startswith('pass:'):
86+
# not elif, pyval may return pass:...
87+
if str(v).startswith('pass:'):
8788
x = _secrets.get(v, nil)
8889
if x == nil:
8990
x = run(['pass', 'show', v[5:]], capture_output=True, text=True) or dflt

0 commit comments

Comments
 (0)