+4
-10
appview/pages/templates/repo/settings/pipelines.html
+4
-10
appview/pages/templates/repo/settings/pipelines.html
···
110
110
class="flex flex-col gap-2"
111
111
>
112
112
<p class="uppercase p-0 font-bold">ADD SECRET</p>
113
-
<p class="text-sm text-gray-500 dark:text-gray-400">Secrets are available as environment variables in the workflow.</p>
114
-
<input
115
-
type="text"
116
-
id="secret-key"
117
-
name="key"
118
-
required
119
-
placeholder="SECRET_NAME"
120
-
/>
113
+
<p class="text-sm text-gray-500 dark:text-gray-400">Secrets are available as environment variables in the workflow. You can add multiple secrets.</p>
121
114
<textarea
122
115
type="text"
123
116
id="secret-value"
124
-
name="value"
117
+
name="values"
125
118
required
126
-
placeholder="secret value"></textarea>
119
+
placeholder="SECRET1=VALUE
120
+
SECRET2=VALUE"></textarea>
127
121
<div class="flex gap-2 pt-2">
128
122
<button
129
123
type="button"
+44
-20
appview/repo/settings.go
+44
-20
appview/repo/settings.go
···
111
111
return
112
112
}
113
113
114
-
key := r.FormValue("key")
115
-
if key == "" {
116
-
w.WriteHeader(http.StatusBadRequest)
117
-
return
118
-
}
119
-
120
114
switch r.Method {
121
115
case http.MethodPut:
122
116
errorId := "add-secret-error"
123
117
124
-
value := r.FormValue("value")
118
+
value := r.FormValue("values")
125
119
if value == "" {
126
120
w.WriteHeader(http.StatusBadRequest)
127
121
return
128
122
}
129
123
130
-
err = tangled.RepoAddSecret(
131
-
r.Context(),
132
-
spindleClient,
133
-
&tangled.RepoAddSecret_Input{
134
-
Repo: f.RepoAt().String(),
135
-
Key: key,
136
-
Value: value,
137
-
},
138
-
)
139
-
if err != nil {
140
-
l.Error("Failed to add secret.", "err", err)
141
-
rp.pages.Notice(w, errorId, "Failed to add secret.")
142
-
return
124
+
secretsMap := parseSecrets(value)
125
+
for secretKey, secretValue := range secretsMap {
126
+
err = tangled.RepoAddSecret(
127
+
r.Context(),
128
+
spindleClient,
129
+
&tangled.RepoAddSecret_Input{
130
+
Repo: f.RepoAt().String(),
131
+
Key: secretKey,
132
+
Value: secretValue,
133
+
},
134
+
)
135
+
if err != nil {
136
+
l.Error("Failed to add secret.", "err", err)
137
+
rp.pages.Notice(w, errorId, "Failed to add secret.")
138
+
return
139
+
}
143
140
}
144
141
145
142
case http.MethodDelete:
146
143
errorId := "operation-error"
147
144
145
+
key := r.FormValue("key")
146
+
if key == "" {
147
+
w.WriteHeader(http.StatusBadRequest)
148
+
return
149
+
}
150
+
148
151
err = tangled.RepoRemoveSecret(
149
152
r.Context(),
150
153
spindleClient,
···
163
166
rp.pages.HxRefresh(w)
164
167
}
165
168
169
+
func parseSecrets(content string) map[string]string {
170
+
secrets := make(map[string]string)
171
+
lines := strings.SplitSeq(content, "\n")
172
+
173
+
for line := range lines {
174
+
line = strings.TrimSpace(line)
175
+
if line == "" {
176
+
continue
177
+
}
178
+
179
+
parts := strings.SplitN(line, "=", 2)
180
+
if len(parts) == 2 {
181
+
key := strings.TrimSpace(parts[0])
182
+
value := strings.TrimSpace(parts[1])
183
+
secrets[key] = value
184
+
}
185
+
}
186
+
187
+
return secrets
188
+
}
189
+
166
190
func (rp *Repo) Settings(w http.ResponseWriter, r *http.Request) {
167
191
tabVal := r.URL.Query().Get("tab")
168
192
if tabVal == "" {
History
1 round
2 comments
samanthanguyen.me
submitted
#0
1 commit
expand
collapse
appview/settings/pipelines: allow adding multiple secrets
Fixes https://tangled.org/tangled.org/core/issues/371
Signed-off-by: Samantha Nguyen <contact@samanthanguyen.me>
no conflicts, ready to merge
expand 2 comments
Re: everything, makes sense! I'm aiming to look at implementing the UI suggestions + updating the lexicon this Fri/this weekend.
RepoAddSecretrequest in a loop, can we modify the lexicon to allow for multiple secrets at a time?strings.Linesinstead