| 87 | } |
| 88 | |
| 89 | func removeRun(opts *DeleteOptions) error { |
| 90 | c, err := opts.HttpClient() |
| 91 | if err != nil { |
| 92 | return fmt.Errorf("could not create http client: %w", err) |
| 93 | } |
| 94 | client := api.NewClientFromHTTP(c) |
| 95 | |
| 96 | orgName := opts.OrgName |
| 97 | envName := opts.EnvName |
| 98 | |
| 99 | secretEntity, err := shared.GetSecretEntity(orgName, envName, opts.UserSecrets) |
| 100 | if err != nil { |
| 101 | return err |
| 102 | } |
| 103 | |
| 104 | var baseRepo ghrepo.Interface |
| 105 | if secretEntity == shared.Repository || secretEntity == shared.Environment { |
| 106 | baseRepo, err = opts.BaseRepo() |
| 107 | if err != nil { |
| 108 | return err |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | secretApp, err := shared.GetSecretApp(opts.Application, secretEntity) |
| 113 | if err != nil { |
| 114 | return err |
| 115 | } |
| 116 | |
| 117 | if !shared.IsSupportedSecretEntity(secretApp, secretEntity) { |
| 118 | return fmt.Errorf("%s secrets are not supported for %s", secretEntity, secretApp) |
| 119 | } |
| 120 | |
| 121 | cfg, err := opts.Config() |
| 122 | if err != nil { |
| 123 | return err |
| 124 | } |
| 125 | |
| 126 | var path string |
| 127 | var host string |
| 128 | switch secretEntity { |
| 129 | case shared.Organization: |
| 130 | path = fmt.Sprintf("orgs/%s/%s/secrets/%s", orgName, secretApp, opts.SecretName) |
| 131 | host, _ = cfg.Authentication().DefaultHost() |
| 132 | case shared.Environment: |
| 133 | path = fmt.Sprintf("repos/%s/environments/%s/secrets/%s", ghrepo.FullName(baseRepo), envName, opts.SecretName) |
| 134 | host = baseRepo.RepoHost() |
| 135 | case shared.User: |
| 136 | path = fmt.Sprintf("user/codespaces/secrets/%s", opts.SecretName) |
| 137 | host, _ = cfg.Authentication().DefaultHost() |
| 138 | case shared.Repository: |
| 139 | path = fmt.Sprintf("repos/%s/%s/secrets/%s", ghrepo.FullName(baseRepo), secretApp, opts.SecretName) |
| 140 | host = baseRepo.RepoHost() |
| 141 | } |
| 142 | |
| 143 | err = client.REST(host, "DELETE", path, nil, nil) |
| 144 | if err != nil { |
| 145 | return fmt.Errorf("failed to delete secret %s: %w", opts.SecretName, err) |
| 146 | } |