Skip to content
This repository has been archived by the owner on Feb 2, 2021. It is now read-only.

Add a password STDIN option to registry login #171

Merged
merged 1 commit into from
Dec 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,15 @@ After the installation has completed in a later step, you will need to create DN

ofc-bootstrap has a command to generate the registry auth file in the correct format.

If you are using Dockerhub you only need to supply your `--username` and `--password`.
If you are using Dockerhub you only need to supply your `--username` and `--password-stdin` (or `--password`, but this leaves the password in history).
```sh
ofc-bootstrap registry-login --username <your-registry-username> --password <your-registry-password>

ofc-bootstrap registry-login --username <your-registry-username> --password-stdin
(the enter your password and hit return)
```

You could also have you password in a file, or environment variable and echo/cat this instead of entering interactively

If you are using a different registry (that is not ECR) then also provide a `--server` as well.


Expand Down
15 changes: 13 additions & 2 deletions cmd/registry_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@ import (
"io/ioutil"
"os"
"path/filepath"
"strings"
)

func init() {
rootCommand.AddCommand(registryLoginCommand)
registryLoginCommand.Flags().String("server", "https://index.docker.io/v1/", "The server URL, it is defaulted to the docker registry")
registryLoginCommand.Flags().String("username", "", "The Registry Username")
registryLoginCommand.Flags().String("password", "", "The registry password")
registryLoginCommand.Flags().BoolP("password-stdin", "s", false, "Reads the gateway password from stdin")

registryLoginCommand.Flags().Bool("ecr", false, "If we are using ECR we need a different set of flags, so if this is set, we need to set --username and --password-stdin")
registryLoginCommand.Flags().Bool("ecr", false, "If we are using ECR we need a different set of flags, so if this is set, we need to set --username and --password")
registryLoginCommand.Flags().String("account-id", "", "Your AWS Account id")
registryLoginCommand.Flags().String("region", "", "Your AWS region")
}
Expand All @@ -36,11 +38,20 @@ func generateRegistryAuthFile(command *cobra.Command, _ []string) error {
username, _ := command.Flags().GetString("username")
password, _ := command.Flags().GetString("password")
server, _ := command.Flags().GetString("server")
passStdIn, _ := command.Flags().GetBool("password-stdin")

if ecrEnabled {
return generateECRFile(accountID, region)
} else {
return generateFile(username, password, server)
if passStdIn {
passwordStdin, err := ioutil.ReadAll(os.Stdin)
if err != nil {
return err
}
return generateFile(username, strings.TrimSpace(string(passwordStdin)), server)
} else {
return generateFile(username, password, server)
}
}
}

Expand Down