MCPcopy Index your code
hub / github.com/cli/cli / setRun

Function setRun

pkg/cmd/secret/set/set.go:203–322  ·  view source on GitHub ↗
(opts *SetOptions)

Source from the content-addressed store, hash-verified

201}
202
203func setRun(opts *SetOptions) error {
204 orgName := opts.OrgName
205 envName := opts.EnvName
206
207 var host string
208 var baseRepo ghrepo.Interface
209 if orgName == "" && !opts.UserSecrets {
210 var err error
211 baseRepo, err = opts.BaseRepo()
212 if err != nil {
213 return err
214 }
215
216 host = baseRepo.RepoHost()
217 } else {
218 cfg, err := opts.Config()
219 if err != nil {
220 return err
221 }
222 host, _ = cfg.Authentication().DefaultHost()
223 }
224
225 secrets, err := getSecretsFromOptions(opts)
226 if err != nil {
227 return err
228 }
229
230 c, err := opts.HttpClient()
231 if err != nil {
232 return fmt.Errorf("could not create http client: %w", err)
233 }
234 client := api.NewClientFromHTTP(c)
235
236 secretEntity, err := shared.GetSecretEntity(orgName, envName, opts.UserSecrets)
237 if err != nil {
238 return err
239 }
240
241 secretApp, err := shared.GetSecretApp(opts.Application, secretEntity)
242 if err != nil {
243 return err
244 }
245
246 if !shared.IsSupportedSecretEntity(secretApp, secretEntity) {
247 return fmt.Errorf("%s secrets are not supported for %s", secretEntity, secretApp)
248 }
249
250 var pk *PubKey
251 switch secretEntity {
252 case shared.Organization:
253 pk, err = getOrgPublicKey(client, host, orgName, secretApp)
254 case shared.Environment:
255 pk, err = getEnvPubKey(client, baseRepo, envName)
256 case shared.User:
257 pk, err = getUserPublicKey(client, host)
258 default:
259 pk, err = getRepoPubKey(client, baseRepo, secretApp)
260 }

Callers 6

NewCmdSetFunction · 0.70
Test_setRun_repoFunction · 0.70
Test_setRun_envFunction · 0.70
Test_setRun_orgFunction · 0.70
Test_setRun_userFunction · 0.70

Calls 15

RepoHostMethod · 0.95
NewClientFromHTTPFunction · 0.92
GetSecretEntityFunction · 0.92
GetSecretAppFunction · 0.92
IsSupportedSecretEntityFunction · 0.92
FullNameFunction · 0.92
getSecretsFromOptionsFunction · 0.85
getOrgPublicKeyFunction · 0.85
getEnvPubKeyFunction · 0.85
getUserPublicKeyFunction · 0.85
getRepoPubKeyFunction · 0.85
mapRepoNamesToIDsFunction · 0.85

Tested by 5

Test_setRun_repoFunction · 0.56
Test_setRun_envFunction · 0.56
Test_setRun_orgFunction · 0.56
Test_setRun_userFunction · 0.56