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