sshkube 0.2.2__tar.gz → 0.2.4__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: sshkube
3
- Version: 0.2.2
3
+ Version: 0.2.4
4
4
  Summary: Access kubernetes clusters over ssh
5
5
  Author: Daniel J. B. Clarke
6
6
  Author-email: u8sand@gmail.com
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "sshkube"
3
- version = "0.2.2"
3
+ version = "0.2.4"
4
4
  description = "Access kubernetes clusters over ssh"
5
5
  authors = [
6
6
  {name = "Daniel J. B. Clarke",email = "u8sand@gmail.com"}
@@ -62,15 +62,20 @@ def wait_for_port(port, timeout=1, backoff=1, retries=3):
62
62
 
63
63
  class PidFile:
64
64
  pidfile = workdir/'pid'
65
- def __init__(self, *, pid, port):
65
+ def __init__(self, *, netloc, pid, port):
66
+ self.netloc = netloc
66
67
  self.pid = pid
67
68
  self.port = port
68
69
 
69
70
  @staticmethod
70
71
  def read():
71
72
  if PidFile.pidfile.exists():
72
- pid, _, port = PidFile.pidfile.read_text().partition(':')
73
- pidfile = PidFile(pid=int(pid), port=int(port))
73
+ pid, _, netloc_port = PidFile.pidfile.read_text().partition(':')
74
+ netloc, _, port = netloc_port.partition(':')
75
+ if not _:
76
+ port = netloc
77
+ netloc = ''
78
+ pidfile = PidFile(netloc=netloc, pid=int(pid), port=int(port))
74
79
  if pidfile.running:
75
80
  return pidfile
76
81
  else:
@@ -79,7 +84,7 @@ class PidFile:
79
84
  def write(self):
80
85
  if PidFile.pidfile.exists(): raise RuntimeError('PID file already exists')
81
86
  PidFile.pidfile.parent.mkdir(parents=True, exist_ok=True)
82
- PidFile.pidfile.write_text(f"{self.pid}:{self.port}")
87
+ PidFile.pidfile.write_text(f"{self.pid}:{self.netloc}:{self.port}")
83
88
 
84
89
  @property
85
90
  def running(self):
@@ -124,10 +129,10 @@ def _install(*, server, user, use_env, identity_file, verify, verbose):
124
129
  (workdir/'config').write_text('\n'.join(filter(None, [
125
130
  f"Host {server}",
126
131
  user and f" User {user}",
132
+ f" IdentitiesOnly yes",
127
133
  identity_file and f" IdentityFile {identity_file}",
128
- identity_file and f" IdentitiesOnly yes",
129
- use_env and f" ProxyCommand env PYTHONPATH={':'.join(sys.path)} {sys.executable} -m {__package__} openssl -s {server} --verify={verify}",
130
- (not use_env) and f" ProxyCommand {sys.executable} -m {__package__} openssl -s {server} --verify={verify}",
134
+ use_env and f" ProxyCommand env \"PYTHONPATH={':'.join(sys.path)}\" \"{sys.executable}\" -m {__package__} openssl -s {server} --verify={verify}",
135
+ (not use_env) and f" ProxyCommand \"{sys.executable}\" -m {__package__} openssl -s {server} --verify={verify}",
131
136
  ]))+'\n')
132
137
 
133
138
  # verify connection
@@ -163,7 +168,7 @@ def start_server(*, server, force):
163
168
  def _start_server(*, server, force):
164
169
  pid = PidFile.read()
165
170
  if pid:
166
- if force:
171
+ if pid.netloc != server or force:
167
172
  _kill_server()
168
173
  else:
169
174
  return
@@ -182,7 +187,7 @@ def _start_server(*, server, force):
182
187
  proc = Popen(make_ssh_cmd(server=server, flags=[f"-NL{port}:{k8s_server_parsed.netloc}"]), start_new_session=True)
183
188
  try:
184
189
  wait_for_port(port)
185
- PidFile(pid=proc.pid, port=port).write()
190
+ PidFile(netloc=server, pid=proc.pid, port=port).write()
186
191
  except RuntimeError as e:
187
192
  proc.kill()
188
193
  raise click.UsageError('Proxy server failed to start..') from e
@@ -212,11 +217,9 @@ def _init(*, server):
212
217
  '''
213
218
  Usage: eval "$(sshkube init)"
214
219
  '''
220
+ _start_server(server=server, force=False)
215
221
  pid = PidFile.read()
216
- if pid is None:
217
- _start_server(server=server, force=False)
218
- pid = PidFile.read()
219
- assert pid is not None
222
+ assert pid is not None
220
223
  #
221
224
  if sys.platform == 'win32':
222
225
  print(
@@ -243,10 +246,9 @@ def _run(*, server, args):
243
246
  Usage: sshkube run kubectl help
244
247
  '''
245
248
  pid = PidFile.read()
246
- if pid is None:
247
- _start_server(server=server, force=False)
248
- pid = PidFile.read()
249
- assert pid is not None
249
+ _start_server(server=server, force=False)
250
+ pid = PidFile.read()
251
+ assert pid is not None
250
252
  #
251
253
  subprocess.run(args, env=dict(
252
254
  os.environ,
File without changes
File without changes
File without changes
File without changes