1xops 0.2.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.
- 1xops-0.2.0.dist-info/METADATA +74 -0
- 1xops-0.2.0.dist-info/RECORD +13 -0
- 1xops-0.2.0.dist-info/WHEEL +4 -0
- 1xops-0.2.0.dist-info/entry_points.txt +2 -0
- one_xops/__init__.py +8 -0
- one_xops/cli.py +332 -0
- one_xops/config_file.py +80 -0
- one_xops/profiles/__init__.py +0 -0
- one_xops/profiles/aws.json +49 -0
- one_xops/profiles/azure.json +22 -0
- one_xops/profiles/itsm.json +14 -0
- one_xops/settings.py +119 -0
- one_xops/setup.py +99 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: 1xops
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: 1xops by OceanSoft.io: set up the 1xops plugin, settings and read-only cloud connectors for an organisation, team or person.
|
|
5
|
+
Project-URL: Homepage, https://www.oceansoft.io
|
|
6
|
+
Project-URL: Repository, https://github.com/nnthanh101/1xops
|
|
7
|
+
Project-URL: Issues, https://github.com/nnthanh101/1xops/issues
|
|
8
|
+
Author-email: Nhat-Thanh Nguyen <nnthanh101@gmail.com>
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
Keywords: aws,azure,cloudops,finops,itsm,oceansoft
|
|
11
|
+
Classifier: Environment :: Console
|
|
12
|
+
Classifier: Intended Audience :: System Administrators
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Topic :: System :: Systems Administration
|
|
15
|
+
Requires-Python: >=3.13
|
|
16
|
+
Requires-Dist: pyyaml>=6.0.3
|
|
17
|
+
Requires-Dist: rich>=15.0.0
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
|
|
20
|
+
# 1xops
|
|
21
|
+
|
|
22
|
+
Command line for [1xops by OceanSoft.io](https://github.com/nnthanh101/1xops): checks prerequisites, installs the 1xops plugin, and writes settings and read-only cloud connectors for an organisation, a team (or tenant folder), a project, or one person.
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
uvx 1xops doctor # prerequisites and read-only sign-in (account IDs masked)
|
|
26
|
+
uvx 1xops install --yes # add the marketplaces and install the plugin
|
|
27
|
+
uvx 1xops setup # guided: asks a few questions, writes 1xops.yaml, shows the diff
|
|
28
|
+
uvx 1xops profiles # built-in connector profiles: aws, azure, itsm
|
|
29
|
+
uvx 1xops config --scope team --connectors aws itsm # shows a diff
|
|
30
|
+
uvx 1xops config --scope team --connectors aws itsm --yes # writes it
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
| Scope | Writes | Who it is for |
|
|
34
|
+
|---|---|---|
|
|
35
|
+
| `org` | `managed-settings.json`, `managed-mcp.json` in `--out`, for IT to deploy | Everyone in the organisation |
|
|
36
|
+
| `team` | `.claude/settings.json`, `.mcp.json` in `--dir` (a project or tenant folder) | Everyone on the project, via git |
|
|
37
|
+
| `local` | `.claude/settings.local.json` in `--dir`; connectors via the host CLI | You, in this project |
|
|
38
|
+
| `personal` | `~/.claude/settings.json`; connectors via the host CLI | You, in every project |
|
|
39
|
+
|
|
40
|
+
## 1xops.yaml
|
|
41
|
+
|
|
42
|
+
One file holds everything a person or team sets. It holds non-secret values only; secrets stay in AWS SSO, `az login` or the Atlassian sign-in.
|
|
43
|
+
|
|
44
|
+
```yaml
|
|
45
|
+
scope: team # org | team | local | personal
|
|
46
|
+
dir: . # project or tenant folder (team, local)
|
|
47
|
+
connectors:
|
|
48
|
+
aws:
|
|
49
|
+
AWS_BILLING_PROFILE: "billing-readonly"
|
|
50
|
+
AWS_OPERATIONS_PROFILE: "ops-readonly"
|
|
51
|
+
AWS_REGION: "ap-southeast-2"
|
|
52
|
+
itsm: {}
|
|
53
|
+
./my-profile.json: {} # your own profile
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
1xops config --file 1xops.yaml --yes # apply it
|
|
58
|
+
eval "$(1xops env)" # team/org: load your values into the shell
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
- Keys are the `${VAR}` names each profile uses; `1xops profiles` lists them.
|
|
62
|
+
- At `team` and `org` scope the shared files keep `${VAR}`, so profile names and tenant IDs never reach git. The host reads these from your shell environment, so run `1xops env`.
|
|
63
|
+
- At `local` and `personal` scope the values are written into your private host configuration.
|
|
64
|
+
- Values must be quoted strings, and keys that look like secrets (`TOKEN`, `SECRET`, `PASSWORD`, `API_KEY`) are refused.
|
|
65
|
+
- Keep a personal `1xops.yaml` out of git.
|
|
66
|
+
|
|
67
|
+
## Rules
|
|
68
|
+
|
|
69
|
+
- Nothing changes without `--yes`.
|
|
70
|
+
- Existing values are never overwritten; only missing entries are added.
|
|
71
|
+
- Built-in profiles pin every server version and use `${VAR}` references for profiles, tokens and URLs, so no secret is written to a file.
|
|
72
|
+
- Your own profile is a JSON file with an `mcpServers` object: `--connectors ./my-profile.json`.
|
|
73
|
+
|
|
74
|
+
Licence: Apache-2.0. © 2026 Nhat-Thanh Nguyen (nnthanh101@gmail.com), OceanSoft.io. Licence, trademarks and third-party components: [NOTICE](https://github.com/nnthanh101/1xops/blob/develop/NOTICE).
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
one_xops/__init__.py,sha256=bfWhc8wFxrFQbkmpr2snamWLC_3mZxRK33w-fWhKBBI,228
|
|
2
|
+
one_xops/cli.py,sha256=E5lCeIeTzeUUP9_JBFvcP6Xn1KNwMpT9WXe9lGF9Fik,12320
|
|
3
|
+
one_xops/config_file.py,sha256=Qrdvv_QjSYDW-XiXqyiEeouPgiYfZCnct4uVM0wiXk8,3026
|
|
4
|
+
one_xops/settings.py,sha256=cIc8GS_d9zo1x-cp64AN2F8LLb2R8h37XJ4yEjKasYU,4309
|
|
5
|
+
one_xops/setup.py,sha256=GWKWZZ_i1WqIboRxBdS0L6x2kMTWzCbzkkSv11qcPSY,3798
|
|
6
|
+
one_xops/profiles/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
+
one_xops/profiles/aws.json,sha256=fwqPMHw2-ycvz2yNuwd81xy41r1QgyfCeou7quuA2i4,1304
|
|
8
|
+
one_xops/profiles/azure.json,sha256=AAihKxgnmZV_QezNdTyhzUT99HKkhqK1FSSKthHMGbY,477
|
|
9
|
+
one_xops/profiles/itsm.json,sha256=EfxCw0P91-39qgIbZoZNZNR00Ghx8yIQWu9qlFBqF2g,285
|
|
10
|
+
1xops-0.2.0.dist-info/METADATA,sha256=0awCw92SIetWLv_pea1FGprouZItZgCXLcRBtYxp8eg,3837
|
|
11
|
+
1xops-0.2.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
12
|
+
1xops-0.2.0.dist-info/entry_points.txt,sha256=oAB_19g9jM3M2hppVuep6gr3riv7_vlyUG7xvHqysYk,44
|
|
13
|
+
1xops-0.2.0.dist-info/RECORD,,
|
one_xops/__init__.py
ADDED
one_xops/cli.py
ADDED
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
"""1xops command line: doctor, install, config, profiles.
|
|
2
|
+
|
|
3
|
+
Nothing is changed unless you pass --yes; without it each command shows what it would do.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
import argparse
|
|
9
|
+
import difflib
|
|
10
|
+
import json
|
|
11
|
+
import shlex
|
|
12
|
+
import shutil
|
|
13
|
+
import subprocess
|
|
14
|
+
import sys
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
|
|
17
|
+
import yaml
|
|
18
|
+
from rich.console import Console
|
|
19
|
+
from rich.table import Table
|
|
20
|
+
|
|
21
|
+
from one_xops import __version__
|
|
22
|
+
from one_xops import config_file as cf
|
|
23
|
+
from one_xops import settings as s
|
|
24
|
+
from one_xops import setup as wizard
|
|
25
|
+
|
|
26
|
+
console = Console()
|
|
27
|
+
|
|
28
|
+
INSTALL_STEPS = [
|
|
29
|
+
[s.HOST, "plugin", "marketplace", "add", "anthropics/knowledge-work-plugins"],
|
|
30
|
+
[s.HOST, "plugin", "marketplace", "add", "nnthanh101/1xops"],
|
|
31
|
+
[s.HOST, "plugin", "install", "1xops@1xops"],
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _run(cmd: list[str], timeout: int = 20) -> tuple[int, str]:
|
|
36
|
+
try:
|
|
37
|
+
p = subprocess.run(cmd, check=False, capture_output=True, text=True, timeout=timeout)
|
|
38
|
+
except (OSError, subprocess.TimeoutExpired) as exc:
|
|
39
|
+
return 1, str(exc)
|
|
40
|
+
return p.returncode, (p.stdout or p.stderr).strip()
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _mask(account: str) -> str:
|
|
44
|
+
return f"****{account[-4:]}" if len(account) >= 4 else "****"
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
# ── doctor ──────────────────────────────────────────────────────────────────
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def check_tools() -> list[tuple[str, bool, bool, str]]:
|
|
51
|
+
"""(name, required, ok, detail) for each prerequisite. Read-only."""
|
|
52
|
+
rows = []
|
|
53
|
+
for name, required in [
|
|
54
|
+
("git", True),
|
|
55
|
+
(s.HOST, True),
|
|
56
|
+
("uv", False),
|
|
57
|
+
("npx", False),
|
|
58
|
+
("docker", False),
|
|
59
|
+
("gh", False),
|
|
60
|
+
("aws", False),
|
|
61
|
+
("az", False),
|
|
62
|
+
]:
|
|
63
|
+
path = shutil.which(name)
|
|
64
|
+
if not path:
|
|
65
|
+
rows.append((name, required, False, "not found on PATH"))
|
|
66
|
+
continue
|
|
67
|
+
code, out = _run([name, "--version"])
|
|
68
|
+
rows.append((name, required, code == 0, out.splitlines()[0] if out else path))
|
|
69
|
+
return rows
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def check_sign_in(aws_profile: str | None) -> list[tuple[str, bool, bool, str]]:
|
|
73
|
+
"""Read-only sign-in checks. Account IDs are masked, never printed in full."""
|
|
74
|
+
rows = []
|
|
75
|
+
if shutil.which("aws"):
|
|
76
|
+
cmd = ["aws", "sts", "get-caller-identity", "--output", "json"]
|
|
77
|
+
if aws_profile:
|
|
78
|
+
cmd += ["--profile", aws_profile]
|
|
79
|
+
code, out = _run(cmd)
|
|
80
|
+
if code == 0:
|
|
81
|
+
account = json.loads(out).get("Account", "")
|
|
82
|
+
rows.append(("aws sign-in", False, True, f"signed in, account {_mask(account)}"))
|
|
83
|
+
else:
|
|
84
|
+
rows.append(("aws sign-in", False, False, "not signed in (aws sso login)"))
|
|
85
|
+
if shutil.which("az"):
|
|
86
|
+
code, _ = _run(["az", "account", "show", "--output", "none"])
|
|
87
|
+
rows.append(
|
|
88
|
+
(
|
|
89
|
+
"azure sign-in",
|
|
90
|
+
False,
|
|
91
|
+
code == 0,
|
|
92
|
+
"signed in" if code == 0 else "not signed in (az login)",
|
|
93
|
+
)
|
|
94
|
+
)
|
|
95
|
+
if shutil.which("gh"):
|
|
96
|
+
code, _ = _run(["gh", "auth", "status"])
|
|
97
|
+
rows.append(
|
|
98
|
+
(
|
|
99
|
+
"github sign-in",
|
|
100
|
+
False,
|
|
101
|
+
code == 0,
|
|
102
|
+
"signed in" if code == 0 else "not signed in (gh auth login)",
|
|
103
|
+
)
|
|
104
|
+
)
|
|
105
|
+
return rows
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def cmd_doctor(args: argparse.Namespace) -> int:
|
|
109
|
+
rows = check_tools() + check_sign_in(args.aws_profile)
|
|
110
|
+
table = Table(title=f"1xops {__version__} doctor")
|
|
111
|
+
for col in ("check", "needed", "result", "detail"):
|
|
112
|
+
table.add_column(col)
|
|
113
|
+
for name, required, ok, detail in rows:
|
|
114
|
+
result = (
|
|
115
|
+
"[green]ok[/]" if ok else ("[red]missing[/]" if required else "[yellow]optional[/]")
|
|
116
|
+
)
|
|
117
|
+
table.add_row(name, "required" if required else "optional", result, detail)
|
|
118
|
+
console.print(table)
|
|
119
|
+
failed = [r[0] for r in rows if r[1] and not r[2]]
|
|
120
|
+
if failed:
|
|
121
|
+
console.print(f"[red]Required: {', '.join(failed)}[/]")
|
|
122
|
+
return 1
|
|
123
|
+
return 0
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
# ── install ─────────────────────────────────────────────────────────────────
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def cmd_install(args: argparse.Namespace) -> int:
|
|
130
|
+
if not shutil.which(s.HOST):
|
|
131
|
+
console.print(f"[red]'{s.HOST}' CLI not found; run '1xops doctor'.[/]")
|
|
132
|
+
return 1
|
|
133
|
+
for step in INSTALL_STEPS:
|
|
134
|
+
step = [*step, "--scope", args.scope]
|
|
135
|
+
console.print(f"[bold]$ {' '.join(step)}[/]")
|
|
136
|
+
if not args.yes:
|
|
137
|
+
continue
|
|
138
|
+
code, out = _run(step, timeout=180)
|
|
139
|
+
console.print(out)
|
|
140
|
+
if code != 0:
|
|
141
|
+
return code
|
|
142
|
+
if not args.yes:
|
|
143
|
+
console.print("Dry run. Re-run with --yes to install.")
|
|
144
|
+
return 0
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
# ── config ──────────────────────────────────────────────────────────────────
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def _show_change(path: Path, before: dict, after: dict) -> bool:
|
|
151
|
+
if before == after:
|
|
152
|
+
console.print(f"[dim]{path}: already up to date[/]")
|
|
153
|
+
return False
|
|
154
|
+
diff = difflib.unified_diff(
|
|
155
|
+
s.dumps(before).splitlines(),
|
|
156
|
+
s.dumps(after).splitlines(),
|
|
157
|
+
fromfile=str(path),
|
|
158
|
+
tofile=str(path),
|
|
159
|
+
lineterm="",
|
|
160
|
+
)
|
|
161
|
+
console.print("\n".join(diff), markup=False, highlight=False)
|
|
162
|
+
return True
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def _write(path: Path, data: dict) -> None:
|
|
166
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
167
|
+
tmp = path.with_suffix(path.suffix + ".tmp")
|
|
168
|
+
tmp.write_text(s.dumps(data))
|
|
169
|
+
tmp.replace(path)
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def _resolve(args: argparse.Namespace) -> tuple[str, Path, Path | None, dict[str, dict]]:
|
|
173
|
+
"""Scope, folder, org output and {connector: values}, from 1xops.yaml or the flags."""
|
|
174
|
+
if args.file:
|
|
175
|
+
cfg = cf.load(Path(args.file))
|
|
176
|
+
out = Path(cfg["out"]).resolve() if cfg["out"] else None
|
|
177
|
+
return cfg["scope"], Path(cfg["dir"]).resolve(), out, cfg["connectors"]
|
|
178
|
+
out = Path(args.out).resolve() if args.out else None
|
|
179
|
+
return args.scope, Path(args.dir).resolve(), out, {c: {} for c in args.connectors}
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def cmd_config(args: argparse.Namespace) -> int:
|
|
183
|
+
try:
|
|
184
|
+
scope, project, out, connectors = _resolve(args)
|
|
185
|
+
profiles = [(s.load_profile(name), values) for name, values in connectors.items()]
|
|
186
|
+
except (ValueError, TypeError, OSError, yaml.YAMLError) as exc:
|
|
187
|
+
console.print(f"[red]{exc}[/]")
|
|
188
|
+
return 2
|
|
189
|
+
personal = scope in ("local", "personal")
|
|
190
|
+
servers: dict = {}
|
|
191
|
+
wanted = s.BASELINE
|
|
192
|
+
for profile, values in profiles:
|
|
193
|
+
# Shared files keep ${VAR}; private host config gets the person's values.
|
|
194
|
+
servers.update(
|
|
195
|
+
cf.substitute(profile["mcpServers"], values) if personal else profile["mcpServers"]
|
|
196
|
+
)
|
|
197
|
+
wanted = s.merge(wanted, {"permissions": profile.get("permissions", {})})
|
|
198
|
+
|
|
199
|
+
planned: list[tuple[Path, dict]] = []
|
|
200
|
+
target = s.settings_path(scope, project, out)
|
|
201
|
+
before = s.read_json(target)
|
|
202
|
+
after = s.merge(before, wanted)
|
|
203
|
+
if _show_change(target, before, after):
|
|
204
|
+
planned.append((target, after))
|
|
205
|
+
|
|
206
|
+
host_cmds: list[list[str]] = []
|
|
207
|
+
if servers:
|
|
208
|
+
mcp_file = s.mcp_path(scope, project, out)
|
|
209
|
+
if mcp_file:
|
|
210
|
+
before = s.read_json(mcp_file)
|
|
211
|
+
after = s.merge(before, {"mcpServers": servers})
|
|
212
|
+
if _show_change(mcp_file, before, after):
|
|
213
|
+
planned.append((mcp_file, after))
|
|
214
|
+
else:
|
|
215
|
+
host_scope = "user" if scope == "personal" else "local"
|
|
216
|
+
for name, spec in servers.items():
|
|
217
|
+
host_cmds.append(
|
|
218
|
+
[s.HOST, "mcp", "add-json", "-s", host_scope, name, json.dumps(spec)]
|
|
219
|
+
)
|
|
220
|
+
console.print(f"[bold]$ {s.HOST} mcp add-json -s {host_scope} {name} '…'[/]")
|
|
221
|
+
|
|
222
|
+
if not args.yes:
|
|
223
|
+
console.print("Dry run. Re-run with --yes to write these changes.")
|
|
224
|
+
return 0
|
|
225
|
+
for path, data in planned:
|
|
226
|
+
_write(path, data)
|
|
227
|
+
console.print(f"[green]wrote {path}[/]")
|
|
228
|
+
for cmd in host_cmds:
|
|
229
|
+
code, msg = _run(cmd)
|
|
230
|
+
console.print(msg)
|
|
231
|
+
if code != 0:
|
|
232
|
+
return code
|
|
233
|
+
if scope == "org":
|
|
234
|
+
console.print(f"Give these files to IT to install in: {s.managed_dir()}")
|
|
235
|
+
if not personal and any(values for _, values in profiles):
|
|
236
|
+
console.print('Shared files use ${VAR}. Load your values with: eval "$(1xops env)"')
|
|
237
|
+
return 0
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
def cmd_env(args: argparse.Namespace) -> int:
|
|
241
|
+
"""Print `export VAR=value` lines from 1xops.yaml, for team and org scopes."""
|
|
242
|
+
try:
|
|
243
|
+
cfg = cf.load(Path(args.file))
|
|
244
|
+
except (ValueError, TypeError, OSError, yaml.YAMLError) as exc:
|
|
245
|
+
print(exc, file=sys.stderr)
|
|
246
|
+
return 2
|
|
247
|
+
for values in cfg["connectors"].values():
|
|
248
|
+
for key, value in values.items():
|
|
249
|
+
print(f"export {key}={shlex.quote(value)}")
|
|
250
|
+
return 0
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
def cmd_profiles(_: argparse.Namespace) -> int:
|
|
254
|
+
table = Table(title="Connector profiles")
|
|
255
|
+
for col in ("profile", "servers", "values (1xops.yaml keys)", "description"):
|
|
256
|
+
table.add_column(col)
|
|
257
|
+
for name in s.builtin_profiles():
|
|
258
|
+
p = s.load_profile(name)
|
|
259
|
+
table.add_row(
|
|
260
|
+
name,
|
|
261
|
+
", ".join(p["mcpServers"]),
|
|
262
|
+
", ".join(cf.variables(p)) or "—",
|
|
263
|
+
p.get("description", ""),
|
|
264
|
+
)
|
|
265
|
+
console.print(table)
|
|
266
|
+
console.print("Use your own: a .json file with an 'mcpServers' object, as a connector name.")
|
|
267
|
+
return 0
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
# ── entry point ─────────────────────────────────────────────────────────────
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
274
|
+
parser = argparse.ArgumentParser(prog="1xops", description="1xops by OceanSoft.io")
|
|
275
|
+
parser.add_argument("--version", action="version", version=f"1xops {__version__}")
|
|
276
|
+
sub = parser.add_subparsers(dest="command", required=True)
|
|
277
|
+
|
|
278
|
+
p = sub.add_parser("doctor", help="check prerequisites and read-only sign-in")
|
|
279
|
+
p.add_argument("--aws-profile", help="AWS profile to check (default: current)")
|
|
280
|
+
p.set_defaults(func=cmd_doctor)
|
|
281
|
+
|
|
282
|
+
p = sub.add_parser("install", help="add the marketplaces and install the plugin")
|
|
283
|
+
p.add_argument(
|
|
284
|
+
"--scope",
|
|
285
|
+
choices=("user", "project", "local"),
|
|
286
|
+
default="user",
|
|
287
|
+
help="host install scope: user (default), project (shared), local",
|
|
288
|
+
)
|
|
289
|
+
p.add_argument("--yes", action="store_true", help="run the commands (default: show them)")
|
|
290
|
+
p.set_defaults(func=cmd_install)
|
|
291
|
+
|
|
292
|
+
p = sub.add_parser("config", help="write settings and connectors for a scope")
|
|
293
|
+
p.add_argument(
|
|
294
|
+
"--scope",
|
|
295
|
+
choices=s.SCOPES,
|
|
296
|
+
default="team",
|
|
297
|
+
help="org: managed files for IT · team: shared project settings (use --dir "
|
|
298
|
+
"for a tenant folder) · local: you, this project · personal: you, every project",
|
|
299
|
+
)
|
|
300
|
+
p.add_argument("--dir", default=".", help="project or tenant folder (team/local scopes)")
|
|
301
|
+
p.add_argument("--out", help="output folder for org scope (default: current folder)")
|
|
302
|
+
p.add_argument(
|
|
303
|
+
"--connectors",
|
|
304
|
+
nargs="*",
|
|
305
|
+
default=[],
|
|
306
|
+
metavar="PROFILE",
|
|
307
|
+
help="built-in profile names (see '1xops profiles') or .json files",
|
|
308
|
+
)
|
|
309
|
+
p.add_argument("--file", help="read scope, folder and connector values from 1xops.yaml")
|
|
310
|
+
p.add_argument("--yes", action="store_true", help="write the changes (default: show a diff)")
|
|
311
|
+
p.set_defaults(func=cmd_config)
|
|
312
|
+
|
|
313
|
+
p = sub.add_parser("env", help="print export lines for the values in 1xops.yaml")
|
|
314
|
+
p.add_argument("--file", default="1xops.yaml")
|
|
315
|
+
p.set_defaults(func=cmd_env)
|
|
316
|
+
|
|
317
|
+
p = sub.add_parser("setup", help="guided setup: asks questions, writes 1xops.yaml")
|
|
318
|
+
p.add_argument("--file", default="1xops.yaml")
|
|
319
|
+
p.set_defaults(func=wizard.run)
|
|
320
|
+
|
|
321
|
+
p = sub.add_parser("profiles", help="list built-in connector profiles")
|
|
322
|
+
p.set_defaults(func=cmd_profiles)
|
|
323
|
+
return parser
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
def main(argv: list[str] | None = None) -> int:
|
|
327
|
+
args = build_parser().parse_args(argv)
|
|
328
|
+
return args.func(args)
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
if __name__ == "__main__":
|
|
332
|
+
sys.exit(main())
|
one_xops/config_file.py
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"""1xops.yaml: the end-user configuration file. Non-secret values only.
|
|
2
|
+
|
|
3
|
+
scope: team # org | team | local | personal
|
|
4
|
+
dir: . # project or tenant folder (team, local)
|
|
5
|
+
connectors:
|
|
6
|
+
aws:
|
|
7
|
+
AWS_OPERATIONS_PROFILE: "ops-readonly"
|
|
8
|
+
AWS_REGION: "ap-southeast-2"
|
|
9
|
+
itsm: {}
|
|
10
|
+
./my-profile.json: {} # your own profile file
|
|
11
|
+
|
|
12
|
+
Keys under each connector are the ${VAR} names its servers use (see `1xops profiles`).
|
|
13
|
+
Secrets stay in SSO, `az login` or OAuth and never go in this file.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
import re
|
|
19
|
+
from pathlib import Path
|
|
20
|
+
|
|
21
|
+
import yaml
|
|
22
|
+
|
|
23
|
+
from one_xops import settings as s
|
|
24
|
+
|
|
25
|
+
VAR = re.compile(r"\$\{([A-Z0-9_]+)(?::-[^}]*)?\}")
|
|
26
|
+
SECRET_HINTS = ("TOKEN", "SECRET", "PASSWORD", "API_KEY")
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def variables(profile: dict) -> list[str]:
|
|
30
|
+
"""Every ${VAR} a profile's servers read, in order of first use."""
|
|
31
|
+
found = VAR.findall(s.dumps(profile["mcpServers"]))
|
|
32
|
+
return list(dict.fromkeys(found))
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def substitute(value, values: dict[str, str]):
|
|
36
|
+
"""Replace ${VAR} / ${VAR:-default} with known values; leave unknown ones as they are."""
|
|
37
|
+
if isinstance(value, str):
|
|
38
|
+
return VAR.sub(lambda m: values.get(m.group(1), m.group(0)), value)
|
|
39
|
+
if isinstance(value, list):
|
|
40
|
+
return [substitute(v, values) for v in value]
|
|
41
|
+
if isinstance(value, dict):
|
|
42
|
+
return {k: substitute(v, values) for k, v in value.items()}
|
|
43
|
+
return value
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def load(path: Path) -> dict:
|
|
47
|
+
"""Read and check 1xops.yaml. Returns {scope, dir, out, connectors: {name: {VAR: value}}}."""
|
|
48
|
+
data = yaml.safe_load(path.read_text()) or {}
|
|
49
|
+
if not isinstance(data, dict):
|
|
50
|
+
raise TypeError(f"{path}: expected a mapping at the top level")
|
|
51
|
+
scope = data.get("scope", "team")
|
|
52
|
+
if scope not in s.SCOPES:
|
|
53
|
+
raise ValueError(f"{path}: scope must be one of {', '.join(s.SCOPES)}")
|
|
54
|
+
connectors = data.get("connectors") or {}
|
|
55
|
+
if not isinstance(connectors, dict):
|
|
56
|
+
raise TypeError(f"{path}: 'connectors' must be a mapping of profile → values")
|
|
57
|
+
for name, values in connectors.items():
|
|
58
|
+
values = values or {}
|
|
59
|
+
connectors[name] = values
|
|
60
|
+
for key, value in values.items():
|
|
61
|
+
if not isinstance(value, str):
|
|
62
|
+
raise TypeError(
|
|
63
|
+
f"{path}: {name}.{key} must be a quoted string (YAML read {value!r})"
|
|
64
|
+
)
|
|
65
|
+
if any(h in key for h in SECRET_HINTS):
|
|
66
|
+
raise ValueError(
|
|
67
|
+
f"{path}: {name}.{key} looks like a secret; keep it in your keychain or "
|
|
68
|
+
"sign-in, not in 1xops.yaml"
|
|
69
|
+
)
|
|
70
|
+
return {
|
|
71
|
+
"scope": scope,
|
|
72
|
+
"dir": str(data.get("dir", ".")),
|
|
73
|
+
"out": data.get("out"),
|
|
74
|
+
"connectors": connectors,
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def dump(config: dict) -> str:
|
|
79
|
+
header = "# 1xops.yaml — non-secret values only. Do not commit if it holds personal values.\n"
|
|
80
|
+
return header + yaml.safe_dump(config, sort_keys=False, default_flow_style=False)
|
|
File without changes
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"description": "AWS Labs servers: cost, audit, monitoring, security review (use read-only roles)",
|
|
3
|
+
"mcpServers": {
|
|
4
|
+
"awslabs-billing-cost-management": {
|
|
5
|
+
"args": [
|
|
6
|
+
"awslabs.billing-cost-management-mcp-server==0.0.45"
|
|
7
|
+
],
|
|
8
|
+
"command": "uvx",
|
|
9
|
+
"env": {
|
|
10
|
+
"AWS_PROFILE": "${AWS_BILLING_PROFILE}",
|
|
11
|
+
"AWS_REGION": "us-east-1",
|
|
12
|
+
"FASTMCP_LOG_LEVEL": "ERROR"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"awslabs-cloudtrail": {
|
|
16
|
+
"args": [
|
|
17
|
+
"awslabs.cloudtrail-mcp-server==0.1.1"
|
|
18
|
+
],
|
|
19
|
+
"command": "uvx",
|
|
20
|
+
"env": {
|
|
21
|
+
"AWS_PROFILE": "${AWS_OPERATIONS_PROFILE}",
|
|
22
|
+
"AWS_REGION": "${AWS_REGION}",
|
|
23
|
+
"FASTMCP_LOG_LEVEL": "ERROR"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"awslabs-cloudwatch": {
|
|
27
|
+
"args": [
|
|
28
|
+
"awslabs.cloudwatch-mcp-server==0.3.1"
|
|
29
|
+
],
|
|
30
|
+
"command": "uvx",
|
|
31
|
+
"env": {
|
|
32
|
+
"AWS_PROFILE": "${AWS_OPERATIONS_PROFILE}",
|
|
33
|
+
"AWS_REGION": "${AWS_REGION}",
|
|
34
|
+
"FASTMCP_LOG_LEVEL": "ERROR"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"awslabs-well-architected-security": {
|
|
38
|
+
"args": [
|
|
39
|
+
"awslabs.well-architected-security-mcp-server==0.2.1"
|
|
40
|
+
],
|
|
41
|
+
"command": "uvx",
|
|
42
|
+
"env": {
|
|
43
|
+
"AWS_PROFILE": "${AWS_OPERATIONS_PROFILE}",
|
|
44
|
+
"AWS_REGION": "${AWS_REGION}",
|
|
45
|
+
"FASTMCP_LOG_LEVEL": "ERROR"
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"description": "Microsoft Azure MCP server, read-only mode",
|
|
3
|
+
"mcpServers": {
|
|
4
|
+
"azure": {
|
|
5
|
+
"args": [
|
|
6
|
+
"-y",
|
|
7
|
+
"@azure/mcp@3.0.0",
|
|
8
|
+
"server",
|
|
9
|
+
"start",
|
|
10
|
+
"--mode",
|
|
11
|
+
"namespace",
|
|
12
|
+
"--read-only"
|
|
13
|
+
],
|
|
14
|
+
"command": "npx",
|
|
15
|
+
"env": {
|
|
16
|
+
"AZURE_MCP_COLLECT_TELEMETRY": "false",
|
|
17
|
+
"AZURE_SUBSCRIPTION_ID": "${AZURE_SUBSCRIPTION_ID}",
|
|
18
|
+
"AZURE_TENANT_ID": "${AZURE_TENANT_ID}"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"description": "Atlassian Rovo MCP server (Cloud: Jira, Confluence); every call asks first",
|
|
3
|
+
"mcpServers": {
|
|
4
|
+
"atlassian": {
|
|
5
|
+
"type": "http",
|
|
6
|
+
"url": "https://mcp.atlassian.com/v2/mcp"
|
|
7
|
+
}
|
|
8
|
+
},
|
|
9
|
+
"permissions": {
|
|
10
|
+
"ask": [
|
|
11
|
+
"mcp__atlassian__*"
|
|
12
|
+
]
|
|
13
|
+
}
|
|
14
|
+
}
|
one_xops/settings.py
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"""Settings and connector files for each scope. Pure functions; the CLI does the writing."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import platform
|
|
7
|
+
from importlib import resources
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
HOST = "claude" # host CLI binary and config folder name (technical identifier)
|
|
11
|
+
|
|
12
|
+
SCOPES = ("org", "team", "local", "personal")
|
|
13
|
+
|
|
14
|
+
MARKETPLACES = {
|
|
15
|
+
"1xops": {"source": {"source": "github", "repo": "nnthanh101/1xops"}},
|
|
16
|
+
"knowledge-work-plugins": {
|
|
17
|
+
"source": {"source": "github", "repo": "anthropics/knowledge-work-plugins"}
|
|
18
|
+
},
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
# Baseline every scope receives: the plugin, its base dependency, no secret reads,
|
|
22
|
+
# and a person's yes before anything leaves the machine or rewrites history.
|
|
23
|
+
BASELINE = {
|
|
24
|
+
"extraKnownMarketplaces": MARKETPLACES,
|
|
25
|
+
"enabledPlugins": {"1xops@1xops": True, "operations@knowledge-work-plugins": True},
|
|
26
|
+
"permissions": {
|
|
27
|
+
"deny": ["Read(./.env)", "Read(./.env.*)", "Read(./**/.env)", "Read(./**/.env.*)"],
|
|
28
|
+
"ask": [
|
|
29
|
+
"Bash(git push *)",
|
|
30
|
+
"Bash(git reset --hard *)",
|
|
31
|
+
"Bash(git tag *)",
|
|
32
|
+
"Bash(gh pr merge *)",
|
|
33
|
+
"Bash(gh release *)",
|
|
34
|
+
"Bash(terraform apply *)",
|
|
35
|
+
"Bash(terraform destroy *)",
|
|
36
|
+
],
|
|
37
|
+
},
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def managed_dir() -> Path:
|
|
42
|
+
"""Where IT installs organisation-wide (managed) files on this OS."""
|
|
43
|
+
if platform.system() == "Darwin":
|
|
44
|
+
return Path("/Library/Application Support/ClaudeCode")
|
|
45
|
+
if platform.system() == "Windows":
|
|
46
|
+
return Path("C:/Program Files/ClaudeCode")
|
|
47
|
+
return Path("/etc/claude-code")
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def settings_path(scope: str, project: Path, out: Path | None = None) -> Path:
|
|
51
|
+
"""The settings file for a scope. `org` writes to `out` for IT to deploy."""
|
|
52
|
+
if scope == "org":
|
|
53
|
+
return (out or Path.cwd()) / "managed-settings.json"
|
|
54
|
+
if scope == "team":
|
|
55
|
+
return project / f".{HOST}" / "settings.json"
|
|
56
|
+
if scope == "local":
|
|
57
|
+
return project / f".{HOST}" / "settings.local.json"
|
|
58
|
+
if scope == "personal":
|
|
59
|
+
return Path.home() / f".{HOST}" / "settings.json"
|
|
60
|
+
raise ValueError(f"unknown scope: {scope}")
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def mcp_path(scope: str, project: Path, out: Path | None = None) -> Path | None:
|
|
64
|
+
"""File-based connector scopes. `local` and `personal` go through the host CLI instead."""
|
|
65
|
+
if scope == "org":
|
|
66
|
+
return (out or Path.cwd()) / "managed-mcp.json"
|
|
67
|
+
if scope == "team":
|
|
68
|
+
return project / ".mcp.json"
|
|
69
|
+
return None
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def merge(existing: dict, incoming: dict) -> dict:
|
|
73
|
+
"""Add incoming keys without overwriting anything the user already set.
|
|
74
|
+
|
|
75
|
+
Dicts merge recursively, lists gain only missing items, existing scalars win.
|
|
76
|
+
"""
|
|
77
|
+
out = dict(existing)
|
|
78
|
+
for key, value in incoming.items():
|
|
79
|
+
if key not in out:
|
|
80
|
+
out[key] = value
|
|
81
|
+
elif isinstance(out[key], dict) and isinstance(value, dict):
|
|
82
|
+
out[key] = merge(out[key], value)
|
|
83
|
+
elif isinstance(out[key], list) and isinstance(value, list):
|
|
84
|
+
out[key] = out[key] + [v for v in value if v not in out[key]]
|
|
85
|
+
return out
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def builtin_profiles() -> list[str]:
|
|
89
|
+
files = resources.files("one_xops.profiles").iterdir()
|
|
90
|
+
return sorted(f.name[:-5] for f in files if f.name.endswith(".json"))
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def load_profile(name_or_path: str) -> dict:
|
|
94
|
+
"""A built-in profile name (aws, azure, itsm) or a path to your own JSON file."""
|
|
95
|
+
path = Path(name_or_path)
|
|
96
|
+
if path.suffix == ".json" and path.is_file():
|
|
97
|
+
data = json.loads(path.read_text())
|
|
98
|
+
elif name_or_path in builtin_profiles():
|
|
99
|
+
data = json.loads(
|
|
100
|
+
resources.files("one_xops.profiles").joinpath(f"{name_or_path}.json").read_text()
|
|
101
|
+
)
|
|
102
|
+
else:
|
|
103
|
+
raise ValueError(
|
|
104
|
+
f"unknown profile '{name_or_path}': use one of {', '.join(builtin_profiles())} "
|
|
105
|
+
"or a path to a .json file with an 'mcpServers' object"
|
|
106
|
+
)
|
|
107
|
+
if not isinstance(data.get("mcpServers"), dict) or not data["mcpServers"]:
|
|
108
|
+
raise ValueError(f"profile '{name_or_path}' has no 'mcpServers' object")
|
|
109
|
+
return data
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def read_json(path: Path) -> dict:
|
|
113
|
+
if not path.exists() or not path.read_text().strip():
|
|
114
|
+
return {}
|
|
115
|
+
return json.loads(path.read_text())
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def dumps(data: dict) -> str:
|
|
119
|
+
return json.dumps(data, indent=2) + "\n"
|
one_xops/setup.py
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"""`1xops setup`: a guided terminal setup that writes 1xops.yaml, then shows and applies the changes."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import json
|
|
7
|
+
import os
|
|
8
|
+
import shutil
|
|
9
|
+
import subprocess
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
from rich.console import Console
|
|
13
|
+
from rich.prompt import Confirm, Prompt
|
|
14
|
+
|
|
15
|
+
from one_xops import config_file as cf
|
|
16
|
+
from one_xops import settings as s
|
|
17
|
+
|
|
18
|
+
console = Console()
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _out(cmd: list[str]) -> str:
|
|
22
|
+
if not shutil.which(cmd[0]):
|
|
23
|
+
return ""
|
|
24
|
+
try:
|
|
25
|
+
p = subprocess.run(cmd, check=False, capture_output=True, text=True, timeout=20)
|
|
26
|
+
except (OSError, subprocess.TimeoutExpired):
|
|
27
|
+
return ""
|
|
28
|
+
return p.stdout.strip() if p.returncode == 0 else ""
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def detect() -> dict[str, str | list[str]]:
|
|
32
|
+
"""Read-only lookups that make good defaults: AWS profiles and region, current Azure account."""
|
|
33
|
+
found: dict[str, str | list[str]] = {}
|
|
34
|
+
profiles = _out(["aws", "configure", "list-profiles"]).split()
|
|
35
|
+
if profiles:
|
|
36
|
+
found["aws_profiles"] = profiles
|
|
37
|
+
region = os.environ.get("AWS_REGION") or _out(["aws", "configure", "get", "region"])
|
|
38
|
+
if region:
|
|
39
|
+
found["AWS_REGION"] = region
|
|
40
|
+
account = _out(["az", "account", "show", "--query", "{t:tenantId,s:id}", "--output", "json"])
|
|
41
|
+
if account:
|
|
42
|
+
ids = json.loads(account)
|
|
43
|
+
found["AZURE_TENANT_ID"], found["AZURE_SUBSCRIPTION_ID"] = ids["t"], ids["s"]
|
|
44
|
+
return found
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def ask_value(var: str, found: dict) -> str:
|
|
48
|
+
default = os.environ.get(var) or found.get(var)
|
|
49
|
+
if var.endswith("_PROFILE") and found.get("aws_profiles"):
|
|
50
|
+
console.print(f" AWS profiles on this machine: {', '.join(found['aws_profiles'])}")
|
|
51
|
+
return Prompt.ask(f" {var} (blank to skip)", default=default or "", show_default=bool(default))
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def run(args: argparse.Namespace) -> int:
|
|
55
|
+
from one_xops import cli # imported here: cli imports this module
|
|
56
|
+
|
|
57
|
+
path = Path(args.file)
|
|
58
|
+
console.print("[bold]1xops setup[/] — non-secret values only; secrets stay in your sign-in.\n")
|
|
59
|
+
scope = Prompt.ask(
|
|
60
|
+
"Scope (org: managed files for IT · team: shared project or tenant folder · "
|
|
61
|
+
"local: you, this project · personal: you, every project)",
|
|
62
|
+
choices=list(s.SCOPES),
|
|
63
|
+
default="team",
|
|
64
|
+
)
|
|
65
|
+
config: dict = {"scope": scope}
|
|
66
|
+
if scope in ("team", "local"):
|
|
67
|
+
config["dir"] = Prompt.ask("Project or tenant folder", default=".")
|
|
68
|
+
if scope == "org":
|
|
69
|
+
config["out"] = Prompt.ask("Folder to write the managed files to", default=".")
|
|
70
|
+
|
|
71
|
+
found = detect()
|
|
72
|
+
connectors: dict[str, dict[str, str]] = {}
|
|
73
|
+
for name in s.builtin_profiles():
|
|
74
|
+
profile = s.load_profile(name)
|
|
75
|
+
if not Confirm.ask(f"Add {name}: {profile.get('description', '')}?", default=False):
|
|
76
|
+
continue
|
|
77
|
+
values = {v: ask_value(v, found) for v in cf.variables(profile)}
|
|
78
|
+
connectors[name] = {k: v for k, v in values.items() if v}
|
|
79
|
+
own = Prompt.ask("Your own profile .json file (blank to skip)", default="", show_default=False)
|
|
80
|
+
if own:
|
|
81
|
+
connectors[own] = {}
|
|
82
|
+
config["connectors"] = connectors
|
|
83
|
+
|
|
84
|
+
text = cf.dump(config)
|
|
85
|
+
console.print(f"\n[bold]{path}[/]\n{text}", markup=False, highlight=False)
|
|
86
|
+
if path.exists() and not Confirm.ask(f"{path} exists. Replace it?", default=False):
|
|
87
|
+
return 1
|
|
88
|
+
if not Confirm.ask(f"Write {path}?", default=True):
|
|
89
|
+
return 1
|
|
90
|
+
path.write_text(text)
|
|
91
|
+
cf.load(path) # same checks as `1xops config --file`
|
|
92
|
+
|
|
93
|
+
console.print("\nChanges this would make:")
|
|
94
|
+
if cli.main(["config", "--file", str(path)]) != 0:
|
|
95
|
+
return 2
|
|
96
|
+
if Confirm.ask("Apply them now?", default=False):
|
|
97
|
+
return cli.main(["config", "--file", str(path), "--yes"])
|
|
98
|
+
console.print(f"Apply later with: 1xops config --file {path} --yes")
|
|
99
|
+
return 0
|