NewStaticCredentials gets credentials from passing in cli context
(ctx context.Context, cliContext *cli.Context, ref string)
| 159 | |
| 160 | // NewStaticCredentials gets credentials from passing in cli context |
| 161 | func NewStaticCredentials(ctx context.Context, cliContext *cli.Context, ref string) (registry.CredentialHelper, error) { |
| 162 | username := cliContext.String("user") |
| 163 | var secret string |
| 164 | if i := strings.IndexByte(username, ':'); i > 0 { |
| 165 | secret = username[i+1:] |
| 166 | username = username[0:i] |
| 167 | } |
| 168 | if username != "" { |
| 169 | if secret == "" { |
| 170 | fmt.Printf("Password: ") |
| 171 | |
| 172 | var err error |
| 173 | secret, err = passwordPrompt() |
| 174 | if err != nil { |
| 175 | return nil, err |
| 176 | } |
| 177 | |
| 178 | fmt.Print("\n") |
| 179 | } |
| 180 | } else if rt := cliContext.String("refresh"); rt != "" { |
| 181 | secret = rt |
| 182 | } |
| 183 | |
| 184 | return &staticCredentials{ |
| 185 | ref: ref, |
| 186 | username: username, |
| 187 | secret: secret, |
| 188 | }, nil |
| 189 | } |
| 190 | |
| 191 | func (sc *staticCredentials) GetCredentials(ctx context.Context, ref, host string) (registry.Credentials, error) { |
| 192 | if ref == sc.ref { |
no test coverage detected
searching dependent graphs…