portainer-ctl 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.
Files changed (26) hide show
  1. portainer_ctl-0.2.4/.github/dependabot.yml +19 -0
  2. {portainer_ctl-0.2.2 → portainer_ctl-0.2.4}/.github/workflows/ci.yml +13 -13
  3. {portainer_ctl-0.2.2 → portainer_ctl-0.2.4}/Dockerfile +2 -2
  4. {portainer_ctl-0.2.2 → portainer_ctl-0.2.4}/PKG-INFO +3 -3
  5. {portainer_ctl-0.2.2 → portainer_ctl-0.2.4}/pyproject.toml +2 -2
  6. {portainer_ctl-0.2.2 → portainer_ctl-0.2.4}/shell.nix +1 -1
  7. {portainer_ctl-0.2.2 → portainer_ctl-0.2.4}/src/portainer_ctl/api.py +1 -1
  8. {portainer_ctl-0.2.2 → portainer_ctl-0.2.4}/src/portainer_ctl/cli.py +16 -16
  9. {portainer_ctl-0.2.2 → portainer_ctl-0.2.4}/src/portainer_ctl/client.py +1 -7
  10. {portainer_ctl-0.2.2 → portainer_ctl-0.2.4}/src/portainer_ctl/errors.py +0 -3
  11. {portainer_ctl-0.2.2 → portainer_ctl-0.2.4}/src/portainer_ctl/helpers.py +0 -2
  12. {portainer_ctl-0.2.2 → portainer_ctl-0.2.4}/src/portainer_ctl/models.py +7 -6
  13. {portainer_ctl-0.2.2 → portainer_ctl-0.2.4}/src/portainer_ctl/printer.py +8 -7
  14. {portainer_ctl-0.2.2 → portainer_ctl-0.2.4}/tests/test_api.py +20 -14
  15. {portainer_ctl-0.2.2 → portainer_ctl-0.2.4}/tests/test_cli.py +9 -3
  16. {portainer_ctl-0.2.2 → portainer_ctl-0.2.4}/tests/test_helpers.py +0 -1
  17. portainer_ctl-0.2.4/uv.lock +406 -0
  18. portainer_ctl-0.2.2/CHANGELOG.md +0 -85
  19. portainer_ctl-0.2.2/uv.lock +0 -481
  20. {portainer_ctl-0.2.2 → portainer_ctl-0.2.4}/.envrc +0 -0
  21. {portainer_ctl-0.2.2 → portainer_ctl-0.2.4}/.gitignore +0 -0
  22. {portainer_ctl-0.2.2 → portainer_ctl-0.2.4}/LICENSE +0 -0
  23. {portainer_ctl-0.2.2 → portainer_ctl-0.2.4}/README.md +0 -0
  24. {portainer_ctl-0.2.2 → portainer_ctl-0.2.4}/docker-compose.yml +0 -0
  25. {portainer_ctl-0.2.2 → portainer_ctl-0.2.4}/src/portainer_ctl/__init__.py +0 -0
  26. {portainer_ctl-0.2.2 → portainer_ctl-0.2.4}/test/docker-compose.yml +0 -0
@@ -0,0 +1,19 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: "uv"
4
+ schedule:
5
+ interval: "daily"
6
+ cooldown:
7
+ default-days: 7
8
+
9
+ - package-ecosystem: "github-actions"
10
+ schedule:
11
+ interval: "weekly"
12
+ cooldown:
13
+ default-days: 7
14
+
15
+ - package-ecosystem: "docker"
16
+ schedule:
17
+ interval: "weekly"
18
+ cooldown:
19
+ default-days: 7
@@ -11,14 +11,14 @@ jobs:
11
11
  strategy:
12
12
  matrix:
13
13
  python-version:
14
- - "3.8"
15
- - "3.10"
16
14
  - "3.12"
15
+ - "3.13"
17
16
  - "3.14"
17
+ - "3.15"
18
18
  steps:
19
- - uses: actions/checkout@v4
19
+ - uses: actions/checkout@v7
20
20
  - name: Install uv
21
- uses: astral-sh/setup-uv@v5
21
+ uses: astral-sh/setup-uv@36300bab3f61b84e19f32b6bd26b7897f3c7e951 # v10.4.2
22
22
  with:
23
23
  enable-cache: true
24
24
  cache-dependency-glob: "uv.lock"
@@ -41,16 +41,16 @@ jobs:
41
41
  if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
42
42
  runs-on: ubuntu-latest
43
43
  steps:
44
- - uses: actions/checkout@v4
44
+ - uses: actions/checkout@v7
45
45
  with:
46
46
  fetch-depth: 0
47
47
  - name: Login to Docker Hub
48
- uses: docker/login-action@v3
48
+ uses: docker/login-action@v4
49
49
  with:
50
50
  username: ${{ secrets.DOCKERHUB_USERNAME }}
51
51
  password: ${{ secrets.DOCKERHUB_TOKEN }}
52
52
  - name: Login to GitHub Container Registry
53
- uses: docker/login-action@v3
53
+ uses: docker/login-action@v4
54
54
  with:
55
55
  registry: ghcr.io
56
56
  username: ${{ github.repository_owner }}
@@ -64,7 +64,7 @@ jobs:
64
64
 
65
65
  - name: Docker meta
66
66
  id: meta
67
- uses: docker/metadata-action@v5
67
+ uses: docker/metadata-action@v6
68
68
  with:
69
69
  images: |
70
70
  hnaderi/pctl
@@ -73,9 +73,9 @@ jobs:
73
73
  ${{ steps.get_version.outputs.VERSION }}
74
74
  latest
75
75
  - name: Set up Docker Buildx
76
- uses: docker/setup-buildx-action@v3
76
+ uses: docker/setup-buildx-action@v4
77
77
  - name: Build and push
78
- uses: docker/build-push-action@v6
78
+ uses: docker/build-push-action@v7
79
79
  with:
80
80
  context: .
81
81
  push: ${{ github.event_name != 'pull_request' }}
@@ -90,11 +90,11 @@ jobs:
90
90
  id-token: write
91
91
  contents: write
92
92
  steps:
93
- - uses: actions/checkout@v4
93
+ - uses: actions/checkout@v7
94
94
  with:
95
95
  fetch-depth: 0
96
96
  - name: Install uv
97
- uses: astral-sh/setup-uv@v5
97
+ uses: astral-sh/setup-uv@36300bab3f61b84e19f32b6bd26b7897f3c7e951 # v10.4.2
98
98
  with:
99
99
  enable-cache: true
100
100
  cache-dependency-glob: "uv.lock"
@@ -105,6 +105,6 @@ jobs:
105
105
  - name: Publish package distributions to PyPI
106
106
  uses: pypa/gh-action-pypi-publish@release/v1
107
107
  - name: Release
108
- uses: softprops/action-gh-release@v1
108
+ uses: softprops/action-gh-release@v3
109
109
  with:
110
110
  files: "dist/*"
@@ -1,5 +1,5 @@
1
- ARG BUILDER_IMAGE=ghcr.io/astral-sh/uv:python3.10-alpine
2
- ARG RUNTIME_IMAGE=python:3.10-alpine
1
+ ARG BUILDER_IMAGE=ghcr.io/astral-sh/uv:python3.14-alpine
2
+ ARG RUNTIME_IMAGE=python:3.14-alpine
3
3
 
4
4
  FROM $BUILDER_IMAGE AS builder
5
5
 
@@ -1,12 +1,12 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: portainer-ctl
3
- Version: 0.2.2
3
+ Version: 0.2.4
4
4
  Summary: A poor man's kubectl for docker swarm
5
5
  Author: Hossein Naderi
6
6
  License-Expression: Apache-2.0
7
7
  License-File: LICENSE
8
8
  Keywords: docker,docker swarm,kubectl,portainer,swarm
9
- Requires-Python: >=3.8
9
+ Requires-Python: >=3.12
10
10
  Requires-Dist: requests<3,>=2.31.0
11
11
  Requires-Dist: rich-argparse>=1.7.0
12
12
  Requires-Dist: rich>=14.0.0
@@ -1,9 +1,9 @@
1
1
  [project]
2
2
  name = "portainer-ctl"
3
- version = "0.2.2"
3
+ version = "0.2.4"
4
4
  description = "A poor man's kubectl for docker swarm"
5
5
  authors = [{ name = "Hossein Naderi" }]
6
- requires-python = ">=3.8"
6
+ requires-python = ">=3.12"
7
7
  readme = "README.md"
8
8
  license = "Apache-2.0"
9
9
  keywords = [
@@ -4,7 +4,7 @@ in
4
4
  pkgs.mkShell {
5
5
  name = "Portainer controller";
6
6
  buildInputs = with pkgs; [
7
- python
7
+ python3
8
8
  uv
9
9
  ruff
10
10
  ];
@@ -63,7 +63,7 @@ class StacksAPI:
63
63
  }
64
64
 
65
65
  return self.__client.put(
66
- f"/stacks/{str(stack_id)}",
66
+ f"/stacks/{stack_id!s}",
67
67
  params={"endpointId": self.__endpoint_id},
68
68
  data=data,
69
69
  )
@@ -35,7 +35,7 @@ def parse_mount(conf: str):
35
35
  try:
36
36
  path, name = conf.split(":", 1)
37
37
  return (path, name)
38
- except Exception:
38
+ except ValueError:
39
39
  raise errors.InvalidCommand("invalid mount argument: " + conf)
40
40
 
41
41
 
@@ -128,7 +128,7 @@ def deploy(args):
128
128
  with open(args.env_file, "r") as f:
129
129
  env_lines = env_lines + f.readlines()
130
130
 
131
- request.variables = dict()
131
+ request.variables = {}
132
132
  for line in env_lines:
133
133
  stripped = line.strip()
134
134
  if not stripped or stripped.startswith("#"):
@@ -138,19 +138,15 @@ def deploy(args):
138
138
  continue
139
139
  request.variables[stripped[:idx]] = stripped[idx + 1 :]
140
140
 
141
- request.configs = dict(
142
- [
143
- (name, read_string(path))
144
- for (path, name) in [parse_mount(conf) for conf in args.config]
145
- ]
146
- )
141
+ request.configs = {
142
+ name: read_string(path)
143
+ for (path, name) in [parse_mount(conf) for conf in args.config]
144
+ }
147
145
 
148
- request.secrets = dict(
149
- [
150
- (name, read_string(path))
151
- for (path, name) in [parse_mount(conf) for conf in args.secret]
152
- ]
153
- )
146
+ request.secrets = {
147
+ name: read_string(path)
148
+ for (path, name) in [parse_mount(conf) for conf in args.secret]
149
+ }
154
150
 
155
151
  return api.endpoint(args.endpoint).deploy(request, args.no_error)
156
152
 
@@ -499,8 +495,12 @@ def _build_system_cmd(subparsers):
499
495
 
500
496
  def build_init_cmd():
501
497
  def init(args):
502
- PASSWORD = args.password or getenv("PORTAINER_PASSWORD") or _DEFAULT_PASSWORD
503
- USERNAME = args.username or getenv("PORTAINER_USERNAME") or _DEFAULT_USERNAME
498
+ PASSWORD = (
499
+ args.password or getenv("PORTAINER_PASSWORD") or _DEFAULT_PASSWORD
500
+ )
501
+ USERNAME = (
502
+ args.username or getenv("PORTAINER_USERNAME") or _DEFAULT_USERNAME
503
+ )
504
504
  if not (USERNAME and PASSWORD):
505
505
  raise errors.InvalidCommand(
506
506
  "Both username and password are required for admin initiation."
@@ -1,5 +1,3 @@
1
- #!/usr/bin/env python
2
-
3
1
  import logging
4
2
 
5
3
  import requests
@@ -32,9 +30,7 @@ class Client:
32
30
  return self.__extract(resp)
33
31
 
34
32
  def put(self, url: str, data, **kwargs):
35
- resp = requests.put(
36
- self.host + url, headers=self.token, json=data, **kwargs
37
- )
33
+ resp = requests.put(self.host + url, headers=self.token, json=data, **kwargs)
38
34
  return self.__extract(resp)
39
35
 
40
36
  def delete(self, url: str, **kwargs):
@@ -48,7 +44,6 @@ class Client:
48
44
  logger.info("Authorized for " + self.host + " using api token")
49
45
  self.token["Accept"] = "application/json"
50
46
  self.token["x-api-key"] = api_token
51
- return
52
47
 
53
48
  def login(self, username: str, password: str):
54
49
  logger.info("Trying to login to " + self.host + "...")
@@ -57,7 +52,6 @@ class Client:
57
52
  token = resp["jwt"]
58
53
  self.token["Accept"] = "application/json"
59
54
  self.token["Authorization"] = "Bearer " + token
60
- return
61
55
 
62
56
  def logout(self):
63
57
  self.token.clear()
@@ -1,6 +1,3 @@
1
- #!/usr/bin/env python3
2
-
3
-
4
1
  class InvalidCommand(Exception):
5
2
  def __init__(self, msg):
6
3
  self.msg = msg
@@ -1,5 +1,3 @@
1
- #!/usr/bin/env python
2
-
3
1
  from base64 import b64encode
4
2
 
5
3
 
@@ -1,6 +1,7 @@
1
+ from __future__ import annotations
2
+
1
3
  from dataclasses import dataclass, field
2
4
  from enum import Enum
3
- from typing import Dict, List, Optional
4
5
 
5
6
 
6
7
  class EndpointCreationType(Enum):
@@ -22,8 +23,8 @@ class EndpointCreationType(Enum):
22
23
  class EndpointCreationRequest:
23
24
  name: str = ""
24
25
  type: EndpointCreationType = EndpointCreationType.LocalDocker
25
- url: Optional[str] = None
26
- tagIds: List[int] = field(default_factory=list)
26
+ url: str | None = None
27
+ tagIds: list[int] = field(default_factory=list)
27
28
  groupId: int = 0
28
29
 
29
30
 
@@ -31,6 +32,6 @@ class EndpointCreationRequest:
31
32
  class DeploymentRequest:
32
33
  name: str = ""
33
34
  compose: str = ""
34
- configs: Dict[str, str] = field(default_factory=dict)
35
- secrets: Dict[str, str] = field(default_factory=dict)
36
- variables: Dict[str, str] = field(default_factory=dict)
35
+ configs: dict[str, str] = field(default_factory=dict)
36
+ secrets: dict[str, str] = field(default_factory=dict)
37
+ variables: dict[str, str] = field(default_factory=dict)
@@ -1,5 +1,6 @@
1
+ from __future__ import annotations
2
+
1
3
  import json
2
- from typing import Dict, List, Optional, Union
3
4
 
4
5
  from rich import box
5
6
  from rich.console import Console
@@ -9,9 +10,9 @@ console = Console()
9
10
 
10
11
 
11
12
  def __table(
12
- data: Union[Dict, List],
13
- columns: List[str] = None,
14
- title: Optional[str] = None,
13
+ data: dict | list,
14
+ columns: list[str] | None = None,
15
+ title: str | None = None,
15
16
  ):
16
17
  """
17
18
  Print a table from a JSON response using rich.
@@ -58,9 +59,9 @@ def raw(data):
58
59
 
59
60
  def print(
60
61
  args,
61
- data: Union[Dict, List],
62
- columns: List[str] = None,
63
- title: Optional[str] = None,
62
+ data: dict | list,
63
+ columns: list[str] | None = None,
64
+ title: str | None = None,
64
65
  ):
65
66
  if args.json:
66
67
  __json(data)
@@ -18,6 +18,7 @@ def _mock_client(get_return=None, put_return=None, post_return=None):
18
18
  # GlobalStacksAPI.get_stack_id_by_name
19
19
  # ---------------------------------------------------------------------------
20
20
 
21
+
21
22
  def test_get_stack_id_by_name_returns_id():
22
23
  client = _mock_client(get_return=[{"Id": 42, "Name": "mystack"}])
23
24
  api = GlobalStacksAPI(client)
@@ -33,10 +34,12 @@ def test_get_stack_id_by_name_not_found_raises():
33
34
 
34
35
  def test_get_stack_id_by_name_filters_by_name():
35
36
  # API may return stacks that don't exactly match the name filter
36
- client = _mock_client(get_return=[
37
- {"Id": 1, "Name": "mystack"},
38
- {"Id": 2, "Name": "mystack-old"},
39
- ])
37
+ client = _mock_client(
38
+ get_return=[
39
+ {"Id": 1, "Name": "mystack"},
40
+ {"Id": 2, "Name": "mystack-old"},
41
+ ]
42
+ )
40
43
  api = GlobalStacksAPI(client)
41
44
  assert api.get_stack_id_by_name("mystack") == 1
42
45
 
@@ -45,6 +48,7 @@ def test_get_stack_id_by_name_filters_by_name():
45
48
  # StacksAPI.create — update / create / ambiguous branches
46
49
  # ---------------------------------------------------------------------------
47
50
 
51
+
48
52
  def _stacks_api(client, endpoint_id="1"):
49
53
  return StacksAPI(client, endpoint_id)
50
54
 
@@ -61,10 +65,12 @@ def test_create_updates_when_one_existing_stack():
61
65
 
62
66
 
63
67
  def test_create_raises_on_multiple_stacks_with_same_name():
64
- client = _mock_client(get_return=[
65
- {"Id": 1, "Name": "app"},
66
- {"Id": 2, "Name": "app"},
67
- ])
68
+ client = _mock_client(
69
+ get_return=[
70
+ {"Id": 1, "Name": "app"},
71
+ {"Id": 2, "Name": "app"},
72
+ ]
73
+ )
68
74
  api = _stacks_api(client)
69
75
  with pytest.raises(errors.InvalidCommand, match="Multiple stacks"):
70
76
  api.create("app", "compose-content", [])
@@ -73,14 +79,14 @@ def test_create_raises_on_multiple_stacks_with_same_name():
73
79
  def test_create_new_stack_in_swarm():
74
80
  docker_info = {"Swarm": {"Cluster": {"ID": "swarm-abc"}}}
75
81
  client = _mock_client(
76
- get_return=[], # no existing stacks
82
+ get_return=[], # no existing stacks
77
83
  post_return={"Id": 99},
78
84
  )
79
85
  # get() is called twice: once for stacks list, once for docker info via EndpointAPI
80
86
  client.get.side_effect = [
81
- [], # GlobalStacksAPI.list (get_stacks_by_name)
87
+ [], # GlobalStacksAPI.list (get_stacks_by_name)
82
88
  {"ApiVersion": "1.41"}, # EndpointAPI.__init__ version call
83
- docker_info, # EndpointAPI.get_docker_info
89
+ docker_info, # EndpointAPI.get_docker_info
84
90
  ]
85
91
  api = _stacks_api(client)
86
92
  api.create("newapp", "compose-content", [])
@@ -91,9 +97,9 @@ def test_create_new_stack_in_swarm():
91
97
  def test_create_raises_when_not_in_swarm():
92
98
  client = _mock_client()
93
99
  client.get.side_effect = [
94
- [], # no existing stacks
95
- {"ApiVersion": "1.41"}, # EndpointAPI version
96
- {"Swarm": None}, # docker info — not in swarm
100
+ [], # no existing stacks
101
+ {"ApiVersion": "1.41"}, # EndpointAPI version
102
+ {"Swarm": None}, # docker info — not in swarm
97
103
  ]
98
104
  api = _stacks_api(client)
99
105
  with pytest.raises(errors.InvalidCommand, match="Swarm"):
@@ -12,11 +12,11 @@ from portainer_ctl.cli import (
12
12
  parse_mount,
13
13
  )
14
14
 
15
-
16
15
  # ---------------------------------------------------------------------------
17
16
  # parse_mount
18
17
  # ---------------------------------------------------------------------------
19
18
 
19
+
20
20
  def test_parse_mount_valid():
21
21
  assert parse_mount("/tmp/conf.txt:my-conf") == ("/tmp/conf.txt", "my-conf")
22
22
 
@@ -37,6 +37,7 @@ def test_parse_mount_multiple_colons_uses_first():
37
37
  # _resolve_host priority: CLI flag > env var > built-in default
38
38
  # ---------------------------------------------------------------------------
39
39
 
40
+
40
41
  def _args(host=None):
41
42
  ns = argparse.Namespace()
42
43
  ns.host = host
@@ -45,7 +46,10 @@ def _args(host=None):
45
46
 
46
47
  def test_resolve_host_cli_wins_over_env():
47
48
  with patch.dict("os.environ", {"PORTAINER_HOST": "http://from-env:9000/api"}):
48
- assert _resolve_host(_args(host="http://from-cli:9000/api")) == "http://from-cli:9000/api"
49
+ assert (
50
+ _resolve_host(_args(host="http://from-cli:9000/api"))
51
+ == "http://from-cli:9000/api"
52
+ )
49
53
 
50
54
 
51
55
  def test_resolve_host_env_used_when_no_cli():
@@ -57,6 +61,7 @@ def test_resolve_host_default_when_nothing_set():
57
61
  with patch.dict("os.environ", {}, clear=True):
58
62
  # ensure the variable is absent even if set in the outer environment
59
63
  import os
64
+
60
65
  os.environ.pop("PORTAINER_HOST", None)
61
66
  assert _resolve_host(_args()) == _DEFAULT_HOST
62
67
 
@@ -65,6 +70,7 @@ def test_resolve_host_default_when_nothing_set():
65
70
  # env file / variable parsing (tested via the deploy logic extracted inline)
66
71
  # ---------------------------------------------------------------------------
67
72
 
73
+
68
74
  def _parse_env_lines(lines: list[str]) -> dict:
69
75
  """Mirror the parsing loop from cli.deploy so we can unit-test it."""
70
76
  variables = {}
@@ -75,7 +81,7 @@ def _parse_env_lines(lines: list[str]) -> dict:
75
81
  idx = stripped.find("=")
76
82
  if idx < 0:
77
83
  continue
78
- variables[stripped[:idx]] = stripped[idx + 1:]
84
+ variables[stripped[:idx]] = stripped[idx + 1 :]
79
85
  return variables
80
86
 
81
87
 
@@ -1,4 +1,3 @@
1
-
2
1
  from portainer_ctl.helpers import to_base64
3
2
 
4
3