| 105 | } |
| 106 | |
| 107 | func listRun(opts *ListOptions) error { |
| 108 | client, err := opts.HttpClient() |
| 109 | if err != nil { |
| 110 | return fmt.Errorf("could not create http client: %w", err) |
| 111 | } |
| 112 | |
| 113 | orgName := opts.OrgName |
| 114 | envName := opts.EnvName |
| 115 | |
| 116 | var baseRepo ghrepo.Interface |
| 117 | if orgName == "" && !opts.UserSecrets { |
| 118 | baseRepo, err = opts.BaseRepo() |
| 119 | if err != nil { |
| 120 | return err |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | secretEntity, err := shared.GetSecretEntity(orgName, envName, opts.UserSecrets) |
| 125 | if err != nil { |
| 126 | return err |
| 127 | } |
| 128 | |
| 129 | secretApp, err := shared.GetSecretApp(opts.Application, secretEntity) |
| 130 | if err != nil { |
| 131 | return err |
| 132 | } |
| 133 | |
| 134 | if !shared.IsSupportedSecretEntity(secretApp, secretEntity) { |
| 135 | return fmt.Errorf("%s secrets are not supported for %s", secretEntity, secretApp) |
| 136 | } |
| 137 | |
| 138 | // Since populating the `NumSelectedRepos` field costs further API requests |
| 139 | // (one per secret), it's important to avoid extra calls when the output will |
| 140 | // not present the field's value. So, we should only populate this field in |
| 141 | // these cases: |
| 142 | // 1. The command is run in the TTY mode without the `--json <fields>` option. |
| 143 | // 2. The command is run with `--json <fields>` option, and `numSelectedRepos` |
| 144 | // is among the selected fields. In this case, TTY mode is irrelevant. |
| 145 | showSelectedRepoInfo := opts.IO.IsStdoutTTY() |
| 146 | if opts.Exporter != nil { |
| 147 | // Note that if there's an exporter set, then we don't mind the TTY mode |
| 148 | // because we just have to populate the requested fields. |
| 149 | showSelectedRepoInfo = slices.Contains(opts.Exporter.Fields(), fieldNumSelectedRepos) |
| 150 | } |
| 151 | |
| 152 | var secrets []Secret |
| 153 | switch secretEntity { |
| 154 | case shared.Repository: |
| 155 | secrets, err = getRepoSecrets(client, baseRepo, secretApp) |
| 156 | case shared.Environment: |
| 157 | secrets, err = getEnvSecrets(client, baseRepo, envName) |
| 158 | case shared.Organization, shared.User: |
| 159 | var cfg gh.Config |
| 160 | var host string |
| 161 | |
| 162 | cfg, err = opts.Config() |
| 163 | if err != nil { |
| 164 | return err |