forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdesktop_beta_admission_control.yml
More file actions
110 lines (104 loc) · 3.72 KB
/
Copy pathdesktop_beta_admission_control.yml
File metadata and controls
110 lines (104 loc) · 3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
name: Control Desktop Beta Admission
run-name: ${{ inputs.operation }} desktop Beta automation by ${{ github.actor }}
on:
workflow_dispatch:
inputs:
operation:
description: 'Enable or disable signed desktop Beta promotion'
required: true
type: choice
options:
- enable
- disable
confirm:
description: 'Type ENABLE BETA AUTOMATION or DISABLE BETA AUTOMATION'
required: true
type: string
reason:
description: 'Auditable reason for changing the Beta admission fence'
required: true
type: string
permissions: {}
concurrency:
group: desktop-beta-promotion
cancel-in-progress: false
jobs:
control-beta-admission:
environment: prod
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Validate explicit Beta admission intent
env:
OPERATION: ${{ inputs.operation }}
CONFIRM: ${{ inputs.confirm }}
REASON: ${{ inputs.reason }}
run: |
set -euo pipefail
case "$OPERATION" in
enable)
expected='ENABLE BETA AUTOMATION'
;;
disable)
expected='DISABLE BETA AUTOMATION'
;;
*)
echo 'ERROR: operation must be enable or disable' >&2
exit 1
;;
esac
[[ "$CONFIRM" == "$expected" ]] || {
echo "ERROR: confirm must exactly equal $expected" >&2
exit 1
}
[[ -n "${REASON//[[:space:]]/}" ]] || {
echo 'ERROR: reason must not be empty' >&2
exit 1
}
- name: Use the existing production Google identity
uses: google-github-actions/auth@v3
with:
credentials_json: ${{ secrets.GCP_CREDENTIALS }}
- name: Change only the desktop Beta admission fence
env:
PROJECT_ID: ${{ vars.GCP_PROJECT_ID }}
OPERATION: ${{ inputs.operation }}
REASON: ${{ inputs.reason }}
ACTOR: ${{ github.actor }}
run: |
set -euo pipefail
case "$OPERATION" in
enable) promotion_enabled=true ;;
disable) promotion_enabled=false ;;
*) echo 'ERROR: invalid validated operation' >&2; exit 1 ;;
esac
ADMIN_KEY="$(gcloud secrets versions access latest --secret=ADMIN_KEY --project "$PROJECT_ID")"
[[ -n "$ADMIN_KEY" ]] || {
echo 'ERROR: ADMIN_KEY is empty' >&2
exit 1
}
echo "::add-mask::$ADMIN_KEY"
response="$(mktemp)"
trap 'rm -f "$response"; unset ADMIN_KEY' EXIT
jq -cn --argjson promotion_enabled "$promotion_enabled" \
'{promotion_enabled: $promotion_enabled}' \
| curl --fail-with-body --silent --show-error --request PUT \
--header 'Content-Type: application/json' \
--header "secret-key: $ADMIN_KEY" \
--data-binary @- \
https://api.omi.me/v2/desktop/beta/admission \
--output "$response"
jq -e --argjson expected "$promotion_enabled" \
'keys == ["generation", "promotion_enabled"] and
.promotion_enabled == $expected and
(.generation | type == "number" and . >= 0 and floor == .)' \
"$response" >/dev/null
generation="$(jq -r '.generation' "$response")"
{
echo '## Desktop Beta admission control'
echo "- operation: $OPERATION"
echo "- promotion_enabled: $promotion_enabled"
echo "- generation: $generation"
echo "- actor: $ACTOR"
echo "- reason: $REASON"
} >> "$GITHUB_STEP_SUMMARY"