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