@mmerterden/multi-agent-pipeline 23.6.0 → 24.0.0
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.
- package/CHANGELOG.md +56 -1
- package/README.md +61 -27
- package/README.tr.md +46 -12
- package/SECURITY.md +3 -3
- package/docs/architecture.md +47 -8
- package/docs/ecosystem.md +20 -18
- package/docs/engineering.md +1 -1
- package/docs/facts.json +8 -6
- package/docs/features.md +59 -15
- package/install/_codex-agents.mjs +13 -8
- package/install/_common.mjs +24 -0
- package/install/_dev-only-files.mjs +4 -0
- package/install/_mcp-register.mjs +6 -2
- package/install/_rewrite-tree.mjs +197 -0
- package/install/codex.mjs +96 -180
- package/install/copilot.mjs +24 -54
- package/install/index.mjs +29 -11
- package/install/templates/codex-instructions.md +21 -5
- package/install/templates/copilot-instructions.md +21 -14
- package/manifest.json +2082 -0
- package/package.json +6 -2
- package/pipeline/commands/multi-agent/SKILL.md +7 -5
- package/pipeline/commands/multi-agent/analysis/SKILL.md +4 -0
- package/pipeline/commands/multi-agent/autopilot-on/SKILL.md +31 -3
- package/pipeline/commands/multi-agent/autopilot-status/SKILL.md +5 -1
- package/pipeline/commands/multi-agent/channels/SKILL.md +16 -8
- package/pipeline/commands/multi-agent/log/SKILL.md +2 -0
- package/pipeline/commands/multi-agent/resume/SKILL.md +2 -0
- package/pipeline/commands/multi-agent/review-rounds/SKILL.md +94 -0
- package/pipeline/commands/multi-agent/stack/SKILL.md +1 -1
- package/pipeline/commands/multi-agent/sync/SKILL.md +3 -3
- package/pipeline/contract/manifest.json +1 -1
- package/pipeline/contract/types/index.d.ts +1 -0
- package/pipeline/lib/_jira-auth.sh +50 -78
- package/pipeline/lib/_service-account.sh +191 -0
- package/pipeline/lib/credential-inventory.sh +49 -37
- package/pipeline/lib/credential-store.sh +48 -3
- package/pipeline/lib/fetch-confluence.sh +76 -92
- package/pipeline/lib/fetch-crashlytics.sh +30 -59
- package/pipeline/lib/fetch-figma-annotations.sh +9 -9
- package/pipeline/lib/fetch-fortify.sh +77 -81
- package/pipeline/lib/fetch-graylog.sh +38 -77
- package/pipeline/lib/figma-mcp-refresh.sh +23 -4
- package/pipeline/lib/figma-screenshot.sh +7 -8
- package/pipeline/lib/figma-token.sh +39 -46
- package/pipeline/lib/host.mjs +138 -0
- package/pipeline/lib/host.sh +48 -0
- package/pipeline/lib/issue-fetcher.sh +25 -41
- package/pipeline/lib/jira-publish.sh +23 -21
- package/pipeline/lib/local-model.mjs +93 -0
- package/pipeline/lib/md2confluence-v3.py +37 -30
- package/pipeline/lib/model-dispatch.sh +41 -4
- package/pipeline/lib/model-resolve.mjs +58 -0
- package/pipeline/lib/post-pr-review.sh +38 -53
- package/pipeline/lib/reviewer-families.mjs +70 -0
- package/pipeline/lib/service-account.mjs +2131 -0
- package/pipeline/lib/service-account.sh +35 -0
- package/pipeline/lib/usage-names.generated.mjs +3 -0
- package/pipeline/lib/usage-token.mjs +64 -24
- package/pipeline/lib/usage-vocab.mjs +1 -1
- package/pipeline/lib/user-facing.mjs +11 -3
- package/pipeline/lib/vercel-deploy.sh +17 -26
- package/pipeline/multi-agent-refs/_entry-picker.md +62 -0
- package/pipeline/multi-agent-refs/_input-parser.md +1 -1
- package/pipeline/multi-agent-refs/analysis/intake.md +2 -0
- package/pipeline/multi-agent-refs/analysis/reusable-refs.md +1 -0
- package/pipeline/multi-agent-refs/analysis/unattended.md +135 -0
- package/pipeline/multi-agent-refs/autopilot-on/details.md +16 -0
- package/pipeline/multi-agent-refs/channels/generator.md +10 -2
- package/pipeline/multi-agent-refs/channels/menu.md +3 -1
- package/pipeline/multi-agent-refs/channels/preview.md +3 -1
- package/pipeline/multi-agent-refs/channels/reference.md +16 -2
- package/pipeline/multi-agent-refs/channels/report-file.md +188 -0
- package/pipeline/multi-agent-refs/component-dispatch.md +2 -2
- package/pipeline/multi-agent-refs/cross-cli-contract.md +38 -30
- package/pipeline/multi-agent-refs/features/autopilot-circuit-breaker.md +4 -4
- package/pipeline/multi-agent-refs/features/doctor.md +37 -11
- package/pipeline/multi-agent-refs/features/free-models.md +3 -3
- package/pipeline/multi-agent-refs/features/local-model.md +87 -0
- package/pipeline/multi-agent-refs/features/model-fallback.md +25 -10
- package/pipeline/multi-agent-refs/features/product-context.md +6 -5
- package/pipeline/multi-agent-refs/features/review-delta.md +1 -1
- package/pipeline/multi-agent-refs/features/review-rounds.md +40 -0
- package/pipeline/multi-agent-refs/features/rework-escalation.md +5 -4
- package/pipeline/multi-agent-refs/features/service-accounts.md +233 -0
- package/pipeline/multi-agent-refs/features/unattended-security.md +10 -1
- package/pipeline/multi-agent-refs/help/en.md +31 -2
- package/pipeline/multi-agent-refs/help/tr.md +31 -2
- package/pipeline/multi-agent-refs/orchestrator/copilot-pipeline.md +3 -2
- package/pipeline/multi-agent-refs/orchestrator/dispatcher.md +2 -1
- package/pipeline/multi-agent-refs/phases/modes.md +20 -1
- package/pipeline/multi-agent-refs/phases/operations.md +1 -1
- package/pipeline/multi-agent-refs/phases/phase-0-init.md +1 -1
- package/pipeline/multi-agent-refs/phases/phase-2-dev.md +4 -4
- package/pipeline/multi-agent-refs/phases/phase-3-review.md +7 -3
- package/pipeline/multi-agent-refs/phases/phase-5-report.md +12 -10
- package/pipeline/multi-agent-refs/phases.md +4 -3
- package/pipeline/multi-agent-refs/resume/details.md +2 -0
- package/pipeline/multi-agent-refs/review/panel.md +30 -18
- package/pipeline/multi-agent-refs/setup/discovery.md +17 -5
- package/pipeline/multi-agent-refs/setup/token-save-flow.md +21 -2
- package/pipeline/multi-agent-refs/sync/overview.md +11 -5
- package/pipeline/multi-agent-refs/tracker-contract.md +28 -10
- package/pipeline/office/index.html +4 -4
- package/pipeline/schemas/agent-state.schema.json +19 -1
- package/pipeline/schemas/autopilot-config.schema.json +29 -4
- package/pipeline/schemas/hosts.json +512 -0
- package/pipeline/schemas/hosts.schema.json +310 -0
- package/pipeline/schemas/launch.json +22 -2
- package/pipeline/schemas/launch.schema.json +2 -1
- package/pipeline/schemas/phases.json +21 -3
- package/pipeline/schemas/phases.schema.json +8 -0
- package/pipeline/schemas/prefs.schema.json +346 -7
- package/pipeline/schemas/token-budget.json +2 -2
- package/pipeline/scripts/.doctor-mut.47076.mjs +2253 -0
- package/pipeline/scripts/_autopilot-config.mjs +67 -4
- package/pipeline/scripts/_autopilot-item.mjs +67 -0
- package/pipeline/scripts/_autopilot-outcomes.mjs +6 -0
- package/pipeline/scripts/_cost.mjs +75 -3
- package/pipeline/scripts/analysis-sources.mjs +22 -5
- package/pipeline/scripts/analysis-unattended.mjs +360 -0
- package/pipeline/scripts/anonymize-findings.mjs +3 -7
- package/pipeline/scripts/autopilot-arming.mjs +19 -10
- package/pipeline/scripts/autopilot-intake.mjs +124 -27
- package/pipeline/scripts/autopilot-menubar.swift +7 -0
- package/pipeline/scripts/autopilot-runner.mjs +77 -48
- package/pipeline/scripts/autopilot-status.sh +32 -9
- package/pipeline/scripts/bulk-read.sh +37 -5
- package/pipeline/scripts/confluence-readback.mjs +15 -7
- package/pipeline/scripts/cost-table.json +65 -25
- package/pipeline/scripts/doctor.mjs +119 -32
- package/pipeline/scripts/entry-mode.mjs +101 -0
- package/pipeline/scripts/estimate.mjs +30 -16
- package/pipeline/scripts/feedback-send.mjs +11 -8
- package/pipeline/scripts/gen-facts.mjs +16 -13
- package/pipeline/scripts/jira-attach.sh +23 -28
- package/pipeline/scripts/jira-search.sh +5 -21
- package/pipeline/scripts/launch-request.mjs +15 -9
- package/pipeline/scripts/migrate-prefs.mjs +56 -0
- package/pipeline/scripts/phase-tracker.sh +146 -38
- package/pipeline/scripts/priority-review.mjs +14 -7
- package/pipeline/scripts/product-context.mjs +26 -7
- package/pipeline/scripts/prune-logs.sh +4 -2
- package/pipeline/scripts/report-file.mjs +285 -0
- package/pipeline/scripts/review-rounds.mjs +592 -0
- package/pipeline/scripts/rework-escalation.mjs +26 -7
- package/pipeline/scripts/service-read.mjs +19 -17
- package/pipeline/scripts/skill-siblings.mjs +17 -1
- package/pipeline/scripts/status-overview.mjs +20 -10
- package/pipeline/scripts/uninstall.mjs +145 -57
- package/pipeline/scripts/usage-register.mjs +34 -11
- package/pipeline/scripts/usage-report.mjs +31 -26
- package/pipeline/scripts/validate-state.mjs +19 -11
- package/pipeline/scripts/validate-triage.mjs +11 -1
- package/pipeline/scripts/work-items.mjs +25 -28
- package/pipeline/scripts/write-store-config.mjs +37 -11
- package/pipeline/skills/.skill-manifest.json +11 -7
- package/pipeline/skills/.skills-index.json +13 -2
- package/pipeline/skills/shared/README.md +4 -3
- package/pipeline/skills/shared/core/multi-agent/SKILL.md +14 -6
- package/pipeline/skills/shared/core/multi-agent-analysis/SKILL.md +2 -0
- package/pipeline/skills/shared/core/multi-agent-channels/SKILL.md +11 -8
- package/pipeline/skills/shared/core/multi-agent-resume/SKILL.md +1 -1
- package/pipeline/skills/shared/core/multi-agent-review-rounds/SKILL.md +92 -0
- package/pipeline/skills/shared/core/multi-agent-sync/SKILL.md +3 -3
- package/pipeline/skills/skills-index.md +2 -1
- package/pipeline/lib/credential-resolve.mjs +0 -75
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
# shellcheck shell=bash
|
|
2
|
+
# _service-account.sh - what a shell fetcher needs from the account resolver.
|
|
3
|
+
#
|
|
4
|
+
# Sourced, not executed. Every fetcher in the pipeline does the same four
|
|
5
|
+
# things: find the resolver, ask which host an account is for, get a curl
|
|
6
|
+
# config that carries the credential to that host and nowhere else, and say
|
|
7
|
+
# something useful when the answer is no. Written once here, those four are the
|
|
8
|
+
# same everywhere; written per fetcher they drifted, and a fetcher that builds
|
|
9
|
+
# its own `-H "Authorization: ..."` is a fetcher that can send it to a redirect.
|
|
10
|
+
#
|
|
11
|
+
# The credential never reaches argv, an environment variable, or a log: it is
|
|
12
|
+
# written to a config file only curl reads, with the mode set before anything
|
|
13
|
+
# is in it, and removed when the shell exits.
|
|
14
|
+
#
|
|
15
|
+
# Usage:
|
|
16
|
+
# . "$(dirname "$0")/_service-account.sh" # or the installed lib path
|
|
17
|
+
# cfg="$(sa_cfg jira "$url" bearer)" || exit $?
|
|
18
|
+
# curl --config "$cfg" ...
|
|
19
|
+
#
|
|
20
|
+
# sa_host jira # the host of the chosen account
|
|
21
|
+
# sa_base jira # scheme and host, port kept
|
|
22
|
+
# sa_reason # the last refusal, as JSON
|
|
23
|
+
|
|
24
|
+
SA_TRAP_SET=""
|
|
25
|
+
|
|
26
|
+
# One directory, created when this file is sourced, removed when the sourcing
|
|
27
|
+
# shell exits.
|
|
28
|
+
#
|
|
29
|
+
# It is made here rather than inside sa_cfg because sa_cfg is called from a
|
|
30
|
+
# command substitution, which is a subshell: a file registered for cleanup
|
|
31
|
+
# there is removed the moment that subshell ends, which is before the caller
|
|
32
|
+
# has read the path it just printed. A directory created in the parent is
|
|
33
|
+
# inherited by every subshell, and the parent's trap outlives all of them.
|
|
34
|
+
SA_TMPDIR="$(mktemp -d "${TMPDIR:-/tmp}/sa.XXXXXX")"
|
|
35
|
+
chmod 700 "$SA_TMPDIR"
|
|
36
|
+
|
|
37
|
+
# The last refusal is kept in a file, not a variable.
|
|
38
|
+
#
|
|
39
|
+
# Every caller reaches the resolver through a command substitution - that is
|
|
40
|
+
# what `cfg="$(sa_cfg ...)"` is - and a variable assigned inside one is assigned
|
|
41
|
+
# in a subshell that ends before the caller reads it. A refusal stored that way
|
|
42
|
+
# is gone by the time the caller asks why, and the caller reports whatever its
|
|
43
|
+
# default branch says instead of what actually happened. A file written in the
|
|
44
|
+
# subshell is there in the parent.
|
|
45
|
+
SA_ERROR_FILE="$SA_TMPDIR/last-refusal"
|
|
46
|
+
: >"$SA_ERROR_FILE"
|
|
47
|
+
|
|
48
|
+
sa_sweep() { [ -n "${SA_TMPDIR:-}" ] && rm -rf "$SA_TMPDIR"; return 0; }
|
|
49
|
+
|
|
50
|
+
if [ -z "$SA_TRAP_SET" ]; then
|
|
51
|
+
SA_EXISTING_TRAP="$(trap -p EXIT | sed -E "s/^trap -- '(.*)' EXIT$/\1/")"
|
|
52
|
+
if [ -n "$SA_EXISTING_TRAP" ]; then
|
|
53
|
+
# shellcheck disable=SC2064
|
|
54
|
+
trap "sa_sweep; $SA_EXISTING_TRAP" EXIT
|
|
55
|
+
else
|
|
56
|
+
trap sa_sweep EXIT
|
|
57
|
+
fi
|
|
58
|
+
SA_TRAP_SET=1
|
|
59
|
+
fi
|
|
60
|
+
|
|
61
|
+
# errexit is the caller's setting, not ours: a helper that turns it on for a
|
|
62
|
+
# script that ran without it changes how every later line of that script fails.
|
|
63
|
+
sa_begin() { case $- in *e*) SA_ERREXIT=1 ;; *) SA_ERREXIT="" ;; esac; set +e; }
|
|
64
|
+
sa_end() { [ -n "${SA_ERREXIT:-}" ] && set -e; return 0; }
|
|
65
|
+
|
|
66
|
+
# The resolver beside this file, or the installed one.
|
|
67
|
+
sa_locate() {
|
|
68
|
+
local here
|
|
69
|
+
here="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
|
|
70
|
+
if [ -x "$here/service-account.sh" ]; then
|
|
71
|
+
printf '%s' "$here/service-account.sh"
|
|
72
|
+
return 0
|
|
73
|
+
fi
|
|
74
|
+
if [ -x "$HOME/.claude/lib/service-account.sh" ]; then
|
|
75
|
+
printf '%s' "$HOME/.claude/lib/service-account.sh"
|
|
76
|
+
return 0
|
|
77
|
+
fi
|
|
78
|
+
return 1
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
# Run the resolver, keeping its refusal for sa_reason and passing its status on.
|
|
82
|
+
sa_run() {
|
|
83
|
+
local script status out err
|
|
84
|
+
script="$(sa_locate)" || {
|
|
85
|
+
printf '%s' '{"ok":false,"reason":"store-unavailable","message":"The account resolver is not installed.","remedy":"Run the installer, then /multi-agent:doctor."}' >"$SA_ERROR_FILE"
|
|
86
|
+
return 2
|
|
87
|
+
}
|
|
88
|
+
err="$(mktemp "$SA_TMPDIR/err.XXXXXX")"
|
|
89
|
+
sa_begin
|
|
90
|
+
out="$(bash "$script" "$@" 2>"$err")"
|
|
91
|
+
status=$?
|
|
92
|
+
sa_end
|
|
93
|
+
cat "$err" >"$SA_ERROR_FILE"
|
|
94
|
+
rm -f "$err"
|
|
95
|
+
[ "$status" -eq 0 ] && printf '%s' "$out"
|
|
96
|
+
return "$status"
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
# The refusal the last call produced, as the one JSON line every caller reads.
|
|
100
|
+
sa_reason() { cat "$SA_ERROR_FILE" 2>/dev/null; printf '\n'; }
|
|
101
|
+
|
|
102
|
+
# The machine-readable reason of the last refusal, for a fetcher that maps the
|
|
103
|
+
# resolver's vocabulary onto an exit contract its own callers already read.
|
|
104
|
+
sa_code() {
|
|
105
|
+
# shellcheck disable=SC2016 # the JSON reader is node source, not shell
|
|
106
|
+
node -e 'let s="";process.stdin.on("data",d=>s+=d).on("end",()=>{try{process.stdout.write(JSON.parse(s).reason||"")}catch{process.stdout.write("")}})' <"$SA_ERROR_FILE" 2>/dev/null
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
# One field of the last refusal, for a fetcher whose own contract turns on
|
|
110
|
+
# something the resolver knows and it does not.
|
|
111
|
+
sa_field() {
|
|
112
|
+
# shellcheck disable=SC2016 # the JSON reader is node source, not shell
|
|
113
|
+
FIELD="$1" node -e 'let s="";process.stdin.on("data",d=>s+=d).on("end",()=>{try{const v=JSON.parse(s)[process.env.FIELD];process.stdout.write(v===undefined||v===null?"":String(v))}catch{process.stdout.write("")}})' <"$SA_ERROR_FILE" 2>/dev/null
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
# A human-readable line for a refusal, for a fetcher that reports rather than exits.
|
|
117
|
+
sa_explain() {
|
|
118
|
+
# shellcheck disable=SC2016 # the JSON reader is node source, not shell
|
|
119
|
+
node -e 'let s="";process.stdin.on("data",d=>s+=d).on("end",()=>{try{const j=JSON.parse(s);process.stdout.write(`${j.message||"refused"} ${j.remedy||""}`.trim()+"\n");}catch{process.stdout.write("the account resolver refused this request\n");}})' <"$SA_ERROR_FILE" 2>/dev/null ||
|
|
120
|
+
printf 'the account resolver refused this request\n'
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
# The host the chosen account is for, so a caller can build its own URL.
|
|
124
|
+
#
|
|
125
|
+
# The reader runs on the answer rather than in the pipeline, so a refusal keeps
|
|
126
|
+
# its own exit status instead of being replaced by the reader's parse error.
|
|
127
|
+
sa_host() {
|
|
128
|
+
local service="$1" out status
|
|
129
|
+
shift
|
|
130
|
+
sa_begin
|
|
131
|
+
out="$(sa_run select --service "$service" "$@")"
|
|
132
|
+
status=$?
|
|
133
|
+
sa_end
|
|
134
|
+
[ "$status" -eq 0 ] || return "$status"
|
|
135
|
+
# shellcheck disable=SC2016 # the JSON reader is node source, not shell
|
|
136
|
+
printf '%s' "$out" |
|
|
137
|
+
node -e 'let s="";process.stdin.on("data",d=>s+=d).on("end",()=>{const a=JSON.parse(s);process.stdout.write((a.account.hosts||[])[0]||"");})' 2>/dev/null
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
# The scheme-and-host the chosen account is for, as a URL to build paths on.
|
|
141
|
+
#
|
|
142
|
+
# Separate from sa_host because a host is a name and an account may be reached
|
|
143
|
+
# on a port: `hosts` carries the name alone, and a caller that writes
|
|
144
|
+
# `https://$(sa_host ...)` loses the port with no sign that it did.
|
|
145
|
+
sa_base() {
|
|
146
|
+
local service="$1" out status
|
|
147
|
+
shift
|
|
148
|
+
sa_begin
|
|
149
|
+
out="$(sa_run select --service "$service" "$@")"
|
|
150
|
+
status=$?
|
|
151
|
+
sa_end
|
|
152
|
+
[ "$status" -eq 0 ] || return "$status"
|
|
153
|
+
# shellcheck disable=SC2016 # the JSON reader is node source, not shell
|
|
154
|
+
printf '%s' "$out" |
|
|
155
|
+
node -e 'let s="";process.stdin.on("data",d=>s+=d).on("end",()=>{const a=JSON.parse(s).account;const h=(a.hosts||[])[0]||"";process.stdout.write(a.baseUrl||(h?`https://${h}`:""));})' 2>/dev/null
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
# A curl config carrying the credential to this URL, as a file only curl reads.
|
|
159
|
+
#
|
|
160
|
+
# Prints the path. The file lives in a directory removed when the sourcing
|
|
161
|
+
# shell exits, so a caller that dies between writing and using it leaves no
|
|
162
|
+
# credential behind.
|
|
163
|
+
sa_cfg() {
|
|
164
|
+
local service="$1" url="$2" scheme="${3:-bearer}"
|
|
165
|
+
shift 3 2>/dev/null || shift $#
|
|
166
|
+
local file status
|
|
167
|
+
file="$(mktemp "$SA_TMPDIR/cfg.XXXXXX")" || return 2
|
|
168
|
+
chmod 600 "$file"
|
|
169
|
+
sa_begin
|
|
170
|
+
# The newline is added here because command substitution inside sa_run strips
|
|
171
|
+
# the one the config ends with. curl reads a last line without it, but a file
|
|
172
|
+
# whose shape depends on how it was captured is one nobody can reason about.
|
|
173
|
+
{ sa_run curl-config --service "$service" --url "$url" --scheme "$scheme" "$@" && printf '\n'; } >"$file"
|
|
174
|
+
status=$?
|
|
175
|
+
sa_end
|
|
176
|
+
if [ "$status" -ne 0 ]; then
|
|
177
|
+
rm -f "$file"
|
|
178
|
+
return "$status"
|
|
179
|
+
fi
|
|
180
|
+
printf '%s' "$file"
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
# The raw secret, for the few callers that cannot use a curl config.
|
|
184
|
+
#
|
|
185
|
+
# Prefer sa_cfg. A value in a shell variable is one `set -x`, one error trace
|
|
186
|
+
# and one `ps` away from being somewhere nobody meant it to be.
|
|
187
|
+
sa_token() {
|
|
188
|
+
local service="$1" url="$2"
|
|
189
|
+
shift 2
|
|
190
|
+
sa_run token --service "$service" --url "$url" "$@"
|
|
191
|
+
}
|
|
@@ -57,9 +57,39 @@ _MA_CI_HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
57
57
|
# shellcheck source=/dev/null
|
|
58
58
|
if [ -f "$_MA_CI_HERE/user-facing.sh" ]; then . "$_MA_CI_HERE/user-facing.sh"; else . "$HOME/.claude/lib/user-facing.sh"; fi
|
|
59
59
|
|
|
60
|
+
# The account resolver answers where each service lives. Sourced for sa_host,
|
|
61
|
+
# which reads the account rather than a host key, so this inventory names the
|
|
62
|
+
# same host the fetchers will actually call.
|
|
63
|
+
for _sa in "$_MA_CI_HERE/_service-account.sh" "$HOME/.claude/lib/_service-account.sh" \
|
|
64
|
+
"$HOME/.copilot/lib/_service-account.sh" "$HOME/.codex/lib/_service-account.sh" \
|
|
65
|
+
"$HOME/.codex-local/lib/_service-account.sh"; do
|
|
66
|
+
# shellcheck source=/dev/null
|
|
67
|
+
[ -f "$_sa" ] && { . "$_sa"; break; }
|
|
68
|
+
done
|
|
69
|
+
unset _sa
|
|
70
|
+
|
|
71
|
+
# The host of a service's account, or empty when no account answers for it.
|
|
72
|
+
# Called inside a command substitution, so it never exits.
|
|
73
|
+
account_host() {
|
|
74
|
+
if ! command -v sa_host >/dev/null 2>&1; then
|
|
75
|
+
return 0
|
|
76
|
+
fi
|
|
77
|
+
sa_host "$@" 2>/dev/null || true
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
# One slot of a service's account, for the destination that account was checked
|
|
81
|
+
# against, or empty. Same rule: no exit, and nothing printed on a refusal.
|
|
82
|
+
account_secret() {
|
|
83
|
+
if ! command -v sa_token >/dev/null 2>&1; then
|
|
84
|
+
return 0
|
|
85
|
+
fi
|
|
86
|
+
sa_token "$@" 2>/dev/null || true
|
|
87
|
+
}
|
|
88
|
+
|
|
60
89
|
STORE=""
|
|
61
90
|
for c in "$HOME/.claude/lib/credential-store.sh" "$HOME/.copilot/lib/credential-store.sh" \
|
|
62
|
-
"$HOME/.codex/lib/credential-store.sh" "$
|
|
91
|
+
"$HOME/.codex/lib/credential-store.sh" "$HOME/.codex-local/lib/credential-store.sh" \
|
|
92
|
+
"$(dirname "$0")/credential-store.sh"; do
|
|
63
93
|
[ -f "$c" ] && { STORE="$c"; break; }
|
|
64
94
|
done
|
|
65
95
|
|
|
@@ -78,24 +108,6 @@ while [ $# -gt 0 ]; do
|
|
|
78
108
|
esac
|
|
79
109
|
done
|
|
80
110
|
|
|
81
|
-
pref() { # pref <dotted.path> -> value or empty
|
|
82
|
-
[ -f "$PREFS" ] || return 0
|
|
83
|
-
python3 - "$PREFS" "$1" <<'PYPREF' 2>/dev/null
|
|
84
|
-
import json, sys
|
|
85
|
-
try:
|
|
86
|
-
d = json.load(open(sys.argv[1]))
|
|
87
|
-
except Exception:
|
|
88
|
-
sys.exit(0)
|
|
89
|
-
for k in sys.argv[2].split("."):
|
|
90
|
-
if not isinstance(d, dict):
|
|
91
|
-
sys.exit(0)
|
|
92
|
-
d = d.get(k)
|
|
93
|
-
if d is None:
|
|
94
|
-
sys.exit(0)
|
|
95
|
-
print(d if not isinstance(d, (dict, list)) else "")
|
|
96
|
-
PYPREF
|
|
97
|
-
}
|
|
98
|
-
|
|
99
111
|
# An authenticated request whose credential never appears in argv.
|
|
100
112
|
#
|
|
101
113
|
# `curl -H "Authorization: Bearer $TOK"` puts the secret in the process command line,
|
|
@@ -231,12 +243,11 @@ MCPCHK
|
|
|
231
243
|
# Reachability for one logical key. Never prints a credential; the value is piped
|
|
232
244
|
# straight into curl's stdin config and discarded.
|
|
233
245
|
#
|
|
234
|
-
# Hosts always come from
|
|
235
|
-
# Fortify / Graylog address is deployment-specific and must never be
|
|
236
|
-
# genuinely global public APIs are named literally.
|
|
237
|
-
#
|
|
238
|
-
#
|
|
239
|
-
# self-hosted service the user had actually configured.
|
|
246
|
+
# Hosts always come from the account resolver - a self-hosted Jira / Bitbucket /
|
|
247
|
+
# Confluence / Fortify / Graylog address is deployment-specific and must never be
|
|
248
|
+
# baked in. Only genuinely global public APIs are named literally. A service whose
|
|
249
|
+
# account names no host reads as no-host-configured, which is a setup gap rather
|
|
250
|
+
# than a broken credential.
|
|
240
251
|
probe_one() {
|
|
241
252
|
local key="$1" tok host status
|
|
242
253
|
tok=$(bash "$STORE" get "$key" 2>/dev/null) || { echo "no-credential"; return; }
|
|
@@ -244,19 +255,20 @@ probe_one() {
|
|
|
244
255
|
|
|
245
256
|
case "$key" in
|
|
246
257
|
jira)
|
|
247
|
-
host=$(
|
|
258
|
+
host=$(account_host jira)
|
|
248
259
|
[ -n "$host" ] || { echo "no-host-configured"; return; }
|
|
249
260
|
status=$(probe_http "https://${host}/rest/api/2/myself" "Authorization" "Bearer $tok") ;;
|
|
250
261
|
confluence)
|
|
251
|
-
host=$(
|
|
262
|
+
host=$(account_host confluence)
|
|
252
263
|
[ -n "$host" ] || { echo "no-host-configured"; return; }
|
|
253
264
|
status=$(probe_http "https://${host}/rest/api/user/current" "Authorization" "Bearer $tok") ;;
|
|
254
265
|
bitbucket_token)
|
|
255
|
-
host=$(
|
|
266
|
+
host=$(account_host bitbucket)
|
|
256
267
|
[ -n "$host" ] || { echo "no-host-configured"; return; }
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
bbuser
|
|
268
|
+
# The username is the other half of this account's login; the resolver
|
|
269
|
+
# hands it out only for the host the account itself names.
|
|
270
|
+
local bbuser
|
|
271
|
+
bbuser=$(account_secret bitbucket "https://${host}" --slot username)
|
|
260
272
|
if [ -n "$bbuser" ]; then
|
|
261
273
|
status=$(probe_basic "https://${host}/rest/api/1.0/repos?limit=1" "$bbuser" "$tok")
|
|
262
274
|
else
|
|
@@ -276,7 +288,7 @@ probe_one() {
|
|
|
276
288
|
npm)
|
|
277
289
|
status=$(probe_http "https://registry.npmjs.org/-/whoami" "Authorization" "Bearer $tok") ;;
|
|
278
290
|
fortify)
|
|
279
|
-
host=$(
|
|
291
|
+
host=$(account_host fortify)
|
|
280
292
|
[ -n "$host" ] || { echo "no-host-configured"; return; }
|
|
281
293
|
# Shapes copied from fetch-fortify.sh, which already works against SSC: the API
|
|
282
294
|
# lives under /ssc/, and SSC accepts either a Bearer token or its own
|
|
@@ -288,12 +300,12 @@ probe_one() {
|
|
|
288
300
|
"Authorization" "FortifyToken $(printf '%s' "$tok" | base64 | tr -d '\n')")
|
|
289
301
|
fi ;;
|
|
290
302
|
graylog|graylog_test)
|
|
291
|
-
# The test instance is a separate deployment with its own
|
|
292
|
-
# against the
|
|
303
|
+
# The test instance is a separate deployment with its own account; probing it
|
|
304
|
+
# against the production host would report a healthy token as broken.
|
|
293
305
|
if [ "$key" = "graylog_test" ]; then
|
|
294
|
-
host=$(
|
|
306
|
+
host=$(account_host graylog --environment test)
|
|
295
307
|
else
|
|
296
|
-
host=$(
|
|
308
|
+
host=$(account_host graylog --environment production)
|
|
297
309
|
fi
|
|
298
310
|
[ -n "$host" ] || { echo "no-host-configured"; return; }
|
|
299
311
|
# Graylog PATs authenticate as basic auth with the literal password "token", and
|
|
@@ -301,7 +313,7 @@ probe_one() {
|
|
|
301
313
|
status=$(probe_basic_hdr "https://${host}/api/system" "$tok" "token" \
|
|
302
314
|
"X-Requested-By" "multi-agent-pipeline") ;;
|
|
303
315
|
jenkins)
|
|
304
|
-
host=$(
|
|
316
|
+
host=$(account_host jenkins)
|
|
305
317
|
[ -n "$host" ] || { echo "no-host-configured"; return; }
|
|
306
318
|
status=$(probe_http "https://${host}/api/json" "Authorization" "Bearer $tok") ;;
|
|
307
319
|
firebase)
|
|
@@ -12,6 +12,11 @@
|
|
|
12
12
|
# keeps the secret off this script's argv (visible to
|
|
13
13
|
# ps). A literal "-" value cannot be stored this way.
|
|
14
14
|
# delete <key> Remove secret
|
|
15
|
+
# resolve <key> Print the store item NAME this logical key maps to,
|
|
16
|
+
# and never a value. The mapping is what decides which
|
|
17
|
+
# account a request is made as, so it has to be readable
|
|
18
|
+
# on its own: a check that can only observe it by reading
|
|
19
|
+
# the secret cannot run where secrets must not be printed.
|
|
15
20
|
# probe <key> Is the secret readable right now, without a prompt?
|
|
16
21
|
# Prints one word - readable | missing | locked - and
|
|
17
22
|
# never the value: the backend's stdout goes to
|
|
@@ -135,8 +140,30 @@ audit_lookup() {
|
|
|
135
140
|
do_get() {
|
|
136
141
|
local key="${1:-}"
|
|
137
142
|
[ -z "$key" ] && { echo "usage: $0 get <key>" >&2; exit 3; }
|
|
138
|
-
|
|
139
|
-
|
|
143
|
+
read_item "$(resolve_key "$key")" "$key"
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
# Read an item by its exact store name, with no mapping pass.
|
|
147
|
+
#
|
|
148
|
+
# `get` takes a logical key and maps it; a caller that already holds an item
|
|
149
|
+
# name has nothing left to map, and sending it through `resolve_key` a second
|
|
150
|
+
# time would let a name that happens to match a mapping key become a different
|
|
151
|
+
# item. The audit label is passed separately so the trail keeps naming the
|
|
152
|
+
# logical thing that was asked for rather than the item that answered it.
|
|
153
|
+
do_get_item() {
|
|
154
|
+
local item="${1:-}" label="${2:-}"
|
|
155
|
+
[ -z "$item" ] && { echo "usage: $0 get-item <item-name> [audit-label]" >&2; exit 3; }
|
|
156
|
+
read_item "$item" "${label:-$item}"
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
# The body both of the above share: one exact-name read, one audit line.
|
|
160
|
+
#
|
|
161
|
+
# Exit codes are the caller's contract: 1 absent or empty, 2 backend
|
|
162
|
+
# unavailable, 4 backend error, 5 the store is locked. 5 is told apart from 1
|
|
163
|
+
# because "there is no such secret" and "I may not look" ask for different
|
|
164
|
+
# things from the person reading the message.
|
|
165
|
+
read_item() {
|
|
166
|
+
local key="${1:-}" logical="${2:-$1}"
|
|
140
167
|
if delegate_to_python; then
|
|
141
168
|
local val rc
|
|
142
169
|
val=$(python3 "$KEYCHAIN_PY" get "$key" 2>/dev/null) || rc=$?
|
|
@@ -167,6 +194,12 @@ do_get() {
|
|
|
167
194
|
fi
|
|
168
195
|
if [ -z "$val" ]; then
|
|
169
196
|
audit_lookup "$logical" false
|
|
197
|
+
# A locked keychain refuses every read with the same emptiness an absent
|
|
198
|
+
# item gives, so the refusal text is the only thing that tells them apart.
|
|
199
|
+
case "$attrs" in
|
|
200
|
+
*"User interaction is not allowed"*|*"-25308"*)
|
|
201
|
+
echo "ERR: credential store is locked" >&2; return 5 ;;
|
|
202
|
+
esac
|
|
170
203
|
return 1
|
|
171
204
|
fi
|
|
172
205
|
audit_lookup "$logical" true
|
|
@@ -281,13 +314,25 @@ do_doctor() {
|
|
|
281
314
|
|| echo "Backend: security ✗ MISSING (impossible on macOS)"
|
|
282
315
|
}
|
|
283
316
|
|
|
317
|
+
do_resolve() {
|
|
318
|
+
local key="${1:-}"
|
|
319
|
+
if [ -z "$key" ]; then
|
|
320
|
+
echo "usage: $0 resolve <key>" >&2
|
|
321
|
+
return 3
|
|
322
|
+
fi
|
|
323
|
+
resolve_key "$key"
|
|
324
|
+
printf '\n'
|
|
325
|
+
}
|
|
326
|
+
|
|
284
327
|
case "$CMD" in
|
|
285
328
|
get) do_get "$@" ;;
|
|
329
|
+
get-item) do_get_item "$@" ;;
|
|
330
|
+
resolve) do_resolve "$@" ;;
|
|
286
331
|
set) do_set "$@" ;;
|
|
287
332
|
delete) do_delete "$@" ;;
|
|
288
333
|
probe) do_probe "$@" ;;
|
|
289
334
|
list) do_list ;;
|
|
290
335
|
platform) echo "$PLATFORM" ;;
|
|
291
336
|
doctor) do_doctor ;;
|
|
292
|
-
*) echo "usage: $0 {get|set|delete|probe|list|platform|doctor} [args]" >&2; exit 3 ;;
|
|
337
|
+
*) echo "usage: $0 {get|get-item|set|resolve|delete|probe|list|platform|doctor} [args]" >&2; exit 3 ;;
|
|
293
338
|
esac
|
|
@@ -13,11 +13,12 @@
|
|
|
13
13
|
#
|
|
14
14
|
# Optional env:
|
|
15
15
|
# CONFLUENCE_TIMEOUT_SECONDS default 20
|
|
16
|
-
# CONFLUENCE_AUTH_TOKEN_KEY
|
|
17
|
-
#
|
|
18
|
-
# CONFLUENCE_HOST_OVERRIDE forces the host (overrides URL host extraction)
|
|
19
|
-
#
|
|
20
|
-
#
|
|
16
|
+
# CONFLUENCE_AUTH_TOKEN_KEY names a store item, when the account is to be
|
|
17
|
+
# chosen by the item it holds
|
|
18
|
+
# CONFLUENCE_HOST_OVERRIDE forces the host (overrides URL host extraction).
|
|
19
|
+
# It still has to be a host a configured account
|
|
20
|
+
# covers: an override names which account, it
|
|
21
|
+
# does not excuse one from being checked.
|
|
21
22
|
#
|
|
22
23
|
# Output (stdout, single JSON object):
|
|
23
24
|
# {
|
|
@@ -36,22 +37,24 @@
|
|
|
36
37
|
# 2 missing token or auth failure (after Save Flow trigger)
|
|
37
38
|
# 3 network / HTTP error
|
|
38
39
|
# 4 bad usage
|
|
39
|
-
# 6 host refused:
|
|
40
|
-
# (host-not-allowed), or
|
|
41
|
-
#
|
|
42
|
-
#
|
|
40
|
+
# 6 host refused: no Confluence account covers the page's host
|
|
41
|
+
# (host-not-allowed), or none is configured at all (host-not-configured).
|
|
42
|
+
# Decided before any secret is read, so the token never travels to a host
|
|
43
|
+
# no account names.
|
|
43
44
|
#
|
|
44
45
|
# Notes on auth:
|
|
45
|
-
#
|
|
46
|
-
#
|
|
47
|
-
# and
|
|
48
|
-
#
|
|
46
|
+
# Auth goes through the account resolver: the credential is written into a
|
|
47
|
+
# curl config that also carries the URL it is for, so the two cannot be
|
|
48
|
+
# separated and a redirect is refused rather than followed with the header
|
|
49
|
+
# on. The token never reaches a shell variable, argv or a log. When no
|
|
50
|
+
# account can answer, the script prints a structured "blocked" JSON to
|
|
51
|
+
# stderr and exits 2 - the orchestrator handles the Save Flow + retry. The
|
|
52
|
+
# script itself never prompts.
|
|
49
53
|
|
|
50
54
|
set -euo pipefail
|
|
51
55
|
|
|
52
56
|
URL=""
|
|
53
|
-
|
|
54
|
-
HOST_OVERRIDE="$ENV_HOST_OVERRIDE"
|
|
57
|
+
HOST_OVERRIDE="${CONFLUENCE_HOST_OVERRIDE:-}"
|
|
55
58
|
PAGE_ID=""
|
|
56
59
|
TIMEOUT="${CONFLUENCE_TIMEOUT_SECONDS:-20}"
|
|
57
60
|
|
|
@@ -129,84 +132,24 @@ if ! [[ "$HOST" =~ ^[A-Za-z0-9.-]+(:[0-9]{1,5})?$ ]] || { [[ "$HOST" == *:* ]] &
|
|
|
129
132
|
fi
|
|
130
133
|
|
|
131
134
|
# The link usually comes from ticket text, so its host is attacker-choosable.
|
|
132
|
-
# The
|
|
133
|
-
#
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
except Exception:
|
|
143
|
-
allowed = ""
|
|
144
|
-
allowed = allowed.lower().strip().rstrip("/").split("://")[-1].split("/")[0].split(":")[0]
|
|
145
|
-
if allowed:
|
|
146
|
-
ok = host == allowed or host.endswith("." + allowed)
|
|
147
|
-
print("ok" if ok else "host-not-allowed")
|
|
148
|
-
else:
|
|
149
|
-
print("ok" if host.endswith(".atlassian.net") else "host-not-configured")
|
|
150
|
-
PY
|
|
151
|
-
)
|
|
152
|
-
if [ "$HOST_VERDICT" != "ok" ]; then
|
|
153
|
-
printf '%s\n' '{"status":"blocked","reason":"'"$HOST_VERDICT"'","service":"confluence","expected_pref":"global.hosts.confluence"}' >&2
|
|
154
|
-
exit 6
|
|
155
|
-
fi
|
|
156
|
-
fi
|
|
157
|
-
|
|
158
|
-
# Resolve token via keychainMapping with sane fallback.
|
|
159
|
-
TOKEN_KEY="${CONFLUENCE_AUTH_TOKEN_KEY:-}"
|
|
160
|
-
if [ -z "$TOKEN_KEY" ] && [ -f "$PREFS" ]; then
|
|
161
|
-
TOKEN_KEY=$(python3 -c "
|
|
162
|
-
import json
|
|
163
|
-
try:
|
|
164
|
-
p = json.load(open('$PREFS'))
|
|
165
|
-
print(p.get('global', {}).get('keychainMapping', {}).get('confluence') or '')
|
|
166
|
-
except Exception:
|
|
167
|
-
print('')
|
|
168
|
-
")
|
|
169
|
-
fi
|
|
170
|
-
[ -z "$TOKEN_KEY" ] && TOKEN_KEY="${USER}_Confluence_Access_Token"
|
|
171
|
-
|
|
172
|
-
# Locate the resolver with an existence check, not a `.`-chain.
|
|
173
|
-
#
|
|
174
|
-
# Sourcing a file that does not exist aborts the shell under `set -e` - `||` included -
|
|
175
|
-
# so `. <candidate> || . <candidate> || { error }` reaches neither its later candidates
|
|
176
|
-
# nor its error branch. Every fetcher used that shape starting from `$HOME/.claude/...`,
|
|
177
|
-
# so on a Copilot-only or Codex-only install they all died with a bare exit 1 and no
|
|
178
|
-
# message. Reordering does not help: whichever candidate is absent aborts at that point.
|
|
179
|
-
# Checking for the file before sourcing it is the only safe form.
|
|
180
|
-
for _cred_resolver in \
|
|
181
|
-
"$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)/credential-store-resolver.sh" \
|
|
182
|
-
"$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")/../lib" 2>/dev/null && pwd)/credential-store-resolver.sh" \
|
|
183
|
-
"$HOME/.claude/lib/credential-store-resolver.sh" \
|
|
184
|
-
"$HOME/.copilot/lib/credential-store-resolver.sh" \
|
|
185
|
-
"$HOME/.codex/lib/credential-store-resolver.sh"; do
|
|
186
|
-
[ -f "$_cred_resolver" ] || continue
|
|
187
|
-
# shellcheck source=/dev/null
|
|
188
|
-
. "$_cred_resolver" 2>/dev/null || true
|
|
189
|
-
# `if`, not `[ ... ] && break`: the latter is the loop body's last command and returns
|
|
190
|
-
# 1 when CRED_STORE is still empty, which under `set -e` kills the loop on the first
|
|
191
|
-
# candidate that does not resolve - the very case the loop exists to survive.
|
|
192
|
-
if [ -n "${CRED_STORE:-}" ]; then break; fi
|
|
193
|
-
done
|
|
194
|
-
unset _cred_resolver
|
|
195
|
-
if [ -z "${CRED_STORE:-}" ]; then
|
|
196
|
-
printf '%s\n' '{"status":"blocked","reason":"missing-credential-helper","service":"confluence","expected_key":"'"$TOKEN_KEY"'"}' >&2
|
|
135
|
+
# The account resolver decides whether any configured account covers it, and
|
|
136
|
+
# writes the credential only into a config pinned to that one URL.
|
|
137
|
+
_MA_FC_HERE="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
|
|
138
|
+
# shellcheck source=/dev/null
|
|
139
|
+
if [ -f "$_MA_FC_HERE/_service-account.sh" ]; then
|
|
140
|
+
. "$_MA_FC_HERE/_service-account.sh"
|
|
141
|
+
elif [ -f "$HOME/.claude/lib/_service-account.sh" ]; then
|
|
142
|
+
. "$HOME/.claude/lib/_service-account.sh"
|
|
143
|
+
else
|
|
144
|
+
printf '%s\n' '{"status":"blocked","reason":"missing-credential-helper","service":"confluence"}' >&2
|
|
197
145
|
exit 2
|
|
198
146
|
fi
|
|
199
147
|
|
|
200
|
-
|
|
201
|
-
if [ -
|
|
202
|
-
|
|
203
|
-
exit 2
|
|
148
|
+
SA_PICK=(--host "$HOST")
|
|
149
|
+
if [ -n "${CONFLUENCE_AUTH_TOKEN_KEY:-}" ]; then
|
|
150
|
+
SA_PICK+=(--item "$CONFLUENCE_AUTH_TOKEN_KEY")
|
|
204
151
|
fi
|
|
205
152
|
|
|
206
|
-
# Bearer auth via a curl config fed through process substitution so the token
|
|
207
|
-
# never appears in argv (argv is visible to ps).
|
|
208
|
-
confluence_auth_cfg() { printf 'header = "Authorization: Bearer %s"\n' "$TOKEN"; }
|
|
209
|
-
|
|
210
153
|
# Endpoint resolution: Confluence Cloud (<tenant>.atlassian.net/wiki/rest/api)
|
|
211
154
|
# vs Server/Data Center (<host>/rest/api). The same paths exist on both.
|
|
212
155
|
case "$HOST" in
|
|
@@ -214,6 +157,47 @@ case "$HOST" in
|
|
|
214
157
|
*) API_BASE="https://$HOST/rest/api" ;;
|
|
215
158
|
esac
|
|
216
159
|
|
|
160
|
+
# Sets CONFLUENCE_CFG rather than printing it: a caller that read it through a
|
|
161
|
+
# command substitution would run this in a subshell, where the refusal branch's
|
|
162
|
+
# `exit` ends the subshell and the script carries on unauthenticated.
|
|
163
|
+
CONFLUENCE_CFG=""
|
|
164
|
+
confluence_cfg() {
|
|
165
|
+
CONFLUENCE_CFG="$(sa_cfg confluence "$1" bearer "${SA_PICK[@]+"${SA_PICK[@]}"}")"
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
confluence_blocked() {
|
|
169
|
+
local reason code
|
|
170
|
+
case "$(sa_code)" in
|
|
171
|
+
host-mismatch|no-account-for-target|identity-mismatch|insecure-url)
|
|
172
|
+
reason="host-not-allowed"; code=6 ;;
|
|
173
|
+
not-configured|unknown-account)
|
|
174
|
+
# No account exists. Whether that is a credential still to be saved or a
|
|
175
|
+
# link to a host nobody named turns on whether anything says where this
|
|
176
|
+
# service lives: the file for a Server install, the tenant name itself on
|
|
177
|
+
# Cloud. The first is the Save Flow's case, the second is not.
|
|
178
|
+
case "$HOST" in
|
|
179
|
+
*.atlassian.net) reason="missing-token"; code=2 ;;
|
|
180
|
+
*)
|
|
181
|
+
if [ "$(sa_field hostKnown)" = "true" ]; then
|
|
182
|
+
reason="missing-token"; code=2
|
|
183
|
+
else
|
|
184
|
+
reason="host-not-configured"; code=6
|
|
185
|
+
fi ;;
|
|
186
|
+
esac ;;
|
|
187
|
+
prefs-unreadable|invalid-config)
|
|
188
|
+
reason="host-not-configured"; code=6 ;;
|
|
189
|
+
store-unavailable)
|
|
190
|
+
reason="missing-credential-helper"; code=2 ;;
|
|
191
|
+
*)
|
|
192
|
+
reason="missing-token"; code=2 ;;
|
|
193
|
+
esac
|
|
194
|
+
printf '%s\n' '{"status":"blocked","reason":"'"$reason"'","service":"confluence","expected_pref":"global.hosts.confluence"}' >&2
|
|
195
|
+
exit "$code"
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
# Decided once, before any request: a host nothing covers never reaches a curl.
|
|
199
|
+
confluence_cfg "$API_BASE/content" || confluence_blocked
|
|
200
|
+
|
|
217
201
|
# When we have a page URL but no pageId yet, resolve via title lookup.
|
|
218
202
|
if [ -z "$PAGE_ID_RESOLVED" ] && [ -n "$SPACE_KEY" ] && [ -n "$URL" ]; then
|
|
219
203
|
TITLE_RAW=$(python3 -c "
|
|
@@ -225,11 +209,11 @@ print(up.unquote(m.group(1)) if m else '')
|
|
|
225
209
|
" "$URL")
|
|
226
210
|
if [ -n "$TITLE_RAW" ]; then
|
|
227
211
|
LOOKUP=$(curl -sS --fail --max-time "$TIMEOUT" --connect-timeout 5 \
|
|
228
|
-
|
|
212
|
+
--config "$CONFLUENCE_CFG" -H "Accept: application/json" \
|
|
229
213
|
--data-urlencode "spaceKey=$SPACE_KEY" \
|
|
230
214
|
--data-urlencode "title=$TITLE_RAW" \
|
|
231
215
|
--data-urlencode "expand=" \
|
|
232
|
-
-G
|
|
216
|
+
-G 2>/dev/null || true)
|
|
233
217
|
PAGE_ID_RESOLVED=$(printf '%s' "$LOOKUP" | python3 -c "
|
|
234
218
|
import sys, json
|
|
235
219
|
try:
|
|
@@ -248,9 +232,9 @@ if [ -z "$PAGE_ID_RESOLVED" ]; then
|
|
|
248
232
|
fi
|
|
249
233
|
|
|
250
234
|
# Fetch the page body in storage format.
|
|
235
|
+
confluence_cfg "$API_BASE/content/$PAGE_ID_RESOLVED?expand=body.storage,space" || confluence_blocked
|
|
251
236
|
PAGE_JSON=$(curl -sS --fail --max-time "$TIMEOUT" --connect-timeout 5 \
|
|
252
|
-
|
|
253
|
-
"$API_BASE/content/$PAGE_ID_RESOLVED?expand=body.storage,space" 2>/dev/null || true)
|
|
237
|
+
--config "$CONFLUENCE_CFG" -H "Accept: application/json" 2>/dev/null || true)
|
|
254
238
|
|
|
255
239
|
if [ -z "$PAGE_JSON" ]; then
|
|
256
240
|
echo "ERR: Confluence GET failed for pageId=$PAGE_ID_RESOLVED" >&2
|