DockerCLI/cli/command
Laura Brehm d0c1a80617
login: handle non-tty scenario consistently
Running `docker login` in a non-interactive environment sometimes errors
out if no username/pwd is provided. This handling is somewhat
inconsistent – this commit addresses that.

Before:
| `--username` | `--password` | Result                                                             |
|:------------:|:------------:| ------------------------------------------------------------------ |
|            |            |                                                                  |
|            |            | `Error: Cannot perform an interactive login from a non TTY device` |
|            |            | `Error: Cannot perform an interactive login from a non TTY device` |
|            |            | hangs                                                              |

After:
| `--username` | `--password` | Result                                                             |
|:------------:|:------------:| ------------------------------------------------------------------ |
|            |            |                                                                  |
|            |            | `Error: Cannot perform an interactive login from a non TTY device` |
|            |            | `Error: Cannot perform an interactive login from a non TTY device` |
|            |            | `Error: Cannot perform an interactive login from a non TTY device` |

It's worth calling out a separate scenario – if there are previous,
valid credentials, then running `docker login` with no username or
password provided will use the previously stored credentials, and not
error out.

```console
cat ~/.docker/config.json
{
        "auths": {
                "https://index.docker.io/v1/": {
                        "auth": "xxxxxxxxxxx"
                }
        }
}
⭑ docker login 0>/dev/null
Authenticating with existing credentials...

Login Succeeded
```

This commit also applies the same non-interactive handling logic to the
new web-based login flow, which means that now, if there are no prior
credentials stored and a user runs `docker login`, instead of initiating
the new web-based login flow, an error is returned.

Signed-off-by: Laura Brehm <laurabrehm@hey.com>
(cherry picked from commit bbb6e7643d)
Signed-off-by: Laura Brehm <laurabrehm@hey.com>
2024-09-03 15:39:17 +01:00
..
builder test spring-cleaning 2024-07-19 13:37:27 +02:00
checkpoint test spring-cleaning 2024-07-19 13:37:27 +02:00
commands remove exec, push, pull, ps, images, info from "legacy" commands 2022-04-08 16:55:39 +02:00
completion cli/command/completion: add FromList utility 2024-07-19 01:56:24 +02:00
config test spring-cleaning 2024-07-19 13:37:27 +02:00
container tests/run: fix flaky `RunAttachTermination` test 2024-08-07 12:05:30 +02:00
context Update go:build comments to go1.21 2024-06-18 12:17:13 +02:00
formatter cli/formatter: bracket IPv6 addrs prepended to ports 2024-08-21 11:45:56 +02:00
idresolver Update go:build comments to go1.21 2024-06-18 12:17:13 +02:00
image list/tree: No extra spacing for graphdriver 2024-08-19 13:28:13 +02:00
inspect Update go:build comments to go1.21 2024-06-18 12:17:13 +02:00
manifest cli/command: fix n-constant format string in call (govet) 2024-08-26 14:38:40 +02:00
network test spring-cleaning 2024-07-19 13:37:27 +02:00
node test spring-cleaning 2024-07-19 13:37:27 +02:00
plugin test spring-cleaning 2024-07-19 13:37:27 +02:00
registry login: handle non-tty scenario consistently 2024-09-03 15:39:17 +01:00
secret test spring-cleaning 2024-07-19 13:37:27 +02:00
service cli/command: fix n-constant format string in call (govet) 2024-08-26 14:38:40 +02:00
stack cli/command: fix n-constant format string in call (govet) 2024-08-26 14:38:40 +02:00
swarm test spring-cleaning 2024-07-19 13:37:27 +02:00
system cli/command/system: remove redundant nil-check (gosimple) 2024-08-26 14:38:37 +02:00
task linting: address slice-append issues found by gocritic 2023-11-20 16:02:17 +01:00
testdata Dynamically register kubernetes context store endpoint type. 2019-05-20 13:28:11 +01:00
trust test spring-cleaning 2024-07-19 13:37:27 +02:00
volume test spring-cleaning 2024-07-19 13:37:27 +02:00
cli.go add support for DOCKER_CUSTOM_HEADERS env-var (experimental) 2024-07-19 15:07:06 +02:00
cli_options.go add support for DOCKER_CUSTOM_HEADERS env-var (experimental) 2024-07-19 15:07:06 +02:00
cli_options_test.go golangci-lint: enable thelper linter 2023-11-20 16:02:17 +01:00
cli_test.go add support for DOCKER_CUSTOM_HEADERS env-var (experimental) 2024-07-19 15:07:06 +02:00
context.go Update go:build comments to go1.21 2024-06-18 12:17:13 +02:00
context_test.go Update go:build comments to go1.21 2024-06-18 12:17:13 +02:00
defaultcontextstore.go Update go:build comments to go1.21 2024-06-18 12:17:13 +02:00
defaultcontextstore_test.go Update go:build comments to go1.21 2024-06-18 12:17:13 +02:00
registry.go login: handle non-tty scenario consistently 2024-09-03 15:39:17 +01:00
registry_test.go linting: fmt.Sprintf can be replaced with string concatenation (perfsprint) 2024-06-10 21:19:32 +02:00
telemetry.go OTel: implement missing MeterProvider `ForceFlush` 2024-05-15 00:05:31 +01:00
telemetry_docker.go Update go:build comments to go1.21 2024-06-18 12:17:13 +02:00
telemetry_options.go cli: make initializing the global meter- and tracing providers optional 2024-06-24 15:44:20 +02:00
telemetry_utils.go cli: Wrap Err stream 2024-06-11 17:59:48 +02:00
telemetry_utils_test.go cli: Wrap Err stream 2024-06-11 17:59:48 +02:00
trust.go Refactor content_trust cli/flags handling 2018-03-08 15:00:43 -05:00
utils.go cli/command: fix n-constant format string in call (govet) 2024-08-26 14:38:40 +02:00
utils_test.go fix: ctx cancellation on login prompt 2024-07-19 01:46:16 +02:00