MCPcopy Create free account
hub / github.com/conforma/cli / setupKeys

Function setupKeys

acceptance/cli/cli.go:200–268  ·  view source on GitHub ↗
(ctx context.Context, vars map[string]string, environment []string)

Source from the content-addressed store, hash-verified

198}
199
200func setupKeys(ctx context.Context, vars map[string]string, environment []string) ([]string, map[string]string, error) {
201 // there could be several key pairs created, for testing
202 // signature validation against a wrong public key we want
203 // to avail all public keys that have been generated for
204 // substitution
205 publicKeys := crypto.PublicKeysFrom(ctx)
206 privateKeys := crypto.PrivateKeysFrom(ctx)
207
208 for name, publicKey := range publicKeys {
209 key, err := os.CreateTemp("", "*.pub")
210 if err != nil {
211 return environment, vars, err
212 }
213
214 if !testenv.Persisted(ctx) {
215 testenv.Testing(ctx).Cleanup(func() {
216 os.Remove(key.Name())
217 })
218 }
219
220 _, err = key.WriteString(publicKey)
221 if err != nil {
222 return environment, vars, err
223 }
224 err = key.Close()
225 if err != nil {
226 return environment, vars, err
227 }
228
229 vars[name+"_PUBLIC_KEY"] = key.Name()
230 // Handle some variations in indentation
231 vars[fmt.Sprintf("__________%s_PUBLIC_KEY", name)] = snaps.Indent(publicKey, 10)
232
233 vars[name+"_PUBLIC_KEY_JSON"] = strings.ReplaceAll(publicKey, "\n", "\\n")
234
235 publicKeyXML := bytes.Buffer{}
236 if err := xml.EscapeText(&publicKeyXML, []byte(publicKey)); err != nil {
237 return environment, vars, err
238 }
239 vars[name+"_PUBLIC_KEY_XML"] = publicKeyXML.String()
240 }
241
242 // Setup private keys for VSA functionality
243 for name, privateKey := range privateKeys {
244 privKey, err := os.CreateTemp("", "*.pem")
245 if err != nil {
246 return environment, vars, err
247 }
248
249 if !testenv.Persisted(ctx) {
250 testenv.Testing(ctx).Cleanup(func() {
251 os.Remove(privKey.Name())
252 })
253 }
254
255 _, err = privKey.WriteString(privateKey)
256 if err != nil {
257 return environment, vars, err

Callers 1

variablesFunction · 0.85

Calls 9

PublicKeysFromFunction · 0.92
PrivateKeysFromFunction · 0.92
PersistedFunction · 0.92
TestingFunction · 0.92
IndentFunction · 0.92
CleanupMethod · 0.80
NameMethod · 0.65
CloseMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected