Skip to content

expose config and credential functionalities to 3rd parties - #197

Closed
AkihiroSuda wants to merge 5 commits into
docker:masterfrom
AkihiroSuda:config
Closed

expose config and credential functionalities to 3rd parties#197
AkihiroSuda wants to merge 5 commits into
docker:masterfrom
AkihiroSuda:config

Conversation

@AkihiroSuda

Copy link
Copy Markdown
Collaborator

- What I did

expose config and credential fuhnctionalities to 3rd parties

Example: contrib/client-with-cli-config (but without whole cli)
See also moby/moby#30817

- How I did it

moby/moby#30817

- How to verify it

$ go run ./contrib/client-with-cli-config/main.go push example.com/foo/bar
$ go run ./contrib/client-with-cli-config/main.go pull example.com/foo/bar

- Description for the changelog

expose config and credential fuhnctionalities to 3rd parties

- A picture of a cute animal (not mandatory but encouraged)

penguin

Signed-off-by: Daniel Nephin <dnephin@docker.com>
@AkihiroSuda

Copy link
Copy Markdown
CollaboratorAuthor

Example: contrib/client-with-cli-config (but without whole cli)
See also moby/moby#30817
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
@AkihiroSudaAkihiroSuda changed the title expose config and credential fuhnctionalities to 3rd partiesexpose config and credential functionalities to 3rd partiesJun 15, 2017
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
@codecov-io

Copy link
Copy Markdown

Codecov Report

Merging #197 into master will increase coverage by 1.11%.
The diff coverage is 27.18%.

@@ Coverage Diff @@## master #197 +/- ##
==========================================
+ Coverage 45.67% 46.79% +1.11% 
==========================================
Files 171 165 -6 Lines 11513 11231 -282 ==========================================
- Hits 5259 5255 -4 + Misses 5947 5670 -277 + Partials 307 306 -1

@boaz0boaz0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@vdemeestervdemeester left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🐮

@dnephindnephin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the "fix unintentional change" and "fix CI failure" commits can be squashed to another commit.

"testing"

"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"golang.org/x/net/context"

// Prevents a circular import with "github.com/docker/cli/cli/internal/test"
. "github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/internal/test"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Comment threadregistry/registry.go
)

// ElectAuthServer returns the default registry to use (by asking the daemon)
func ElectAuthServer(ctx context.Context, c client.APIClient) (string, []error, error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed you added an error return value, but it seems to always be nil. Can we remove it?

@@ -0,0 +1,85 @@
// demonstration of using REST API client with cli config (push/pull with credential)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this could be a in a gist or a separate example repo that we can link to from docs?

if err != nil {
return err
}
encodedAuth, err := registry.EncodeAuthToBase64(authConfig)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I notice this code seems to be duplicated a bunch of times. I looked through the use of authConfigs and it seems that in almost every single case we either immediately encode them, or in a few cases we pass it around a bit, then encode it later on.

I'd like to suggest a refactoring which will remove this duplication. Since we're making this change to expose an interface I think it's probably the right time to fix this, as changing it later will break the interface.

Instead of running these 3 returns values, I propose we return a new AuthConfig struct (as noted elsewhere I believe that err is unnecessary and can be removed).

In registry/registry.go:

typeAuthConfigstruct {
config types.AuthConfigwarnings []string
}
func (a*AuthConfig) PrintWarnings(out io.Writer) {
...// the for loop and fmt.Printf()
}
func (s*AuthConfig) Encode() (string, error) {
returnEncodeAuthToBase64(s.config)
}
func (s*AuthConfig) Config() types.AuthConfig {
returns.config
}

Then consuming code could call:

authConfig:=registry.ResolveAuthConfig(ctx, dockerCli.Client(), dockerCli.ConfigFile(), repoInfo.Index)
authConfig.PrintWarnings(dockerCli.Err())
encodedAuth, err:=authConfig.Encode()
iferr!=nil {
returnerr
}

Or it could pass around the authConfig and worry about encoding later.

WDYT?

Comment threadregistry/config.go

// GetAllCredentials returns all of the credentials stored in all of the
// configured credential stores.
func GetAllCredentials(configFile *configfile.ConfigFile) (map[string]types.AuthConfig, error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see this used. Is the code still using the old function?

Comment threadregistry/config.go
// CredentialsStore returns a new credentials store based
// on the settings provided in the configuration file. Empty string returns
// the default credential store.
func CredentialsStore(configFile *configfile.ConfigFile, serverAddress string) credentials.Store {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, not used?

Comment threadregistry/config.go
@@ -0,0 +1,56 @@
package registry

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this file belongs in config/. It does return registry types, but it's operating on the config file more than anything else.

@dnephin

Copy link
Copy Markdown
Contributor

I need this change to support unit testing of some build functions. I'm going to resolve the conflicts and address my comments so I can cherry-pick these commits.

@dnephin

Copy link
Copy Markdown
Contributor

I addressed the config part in #227 I haven't touched the registry functions yet

@AkihiroSuda

Copy link
Copy Markdown
CollaboratorAuthor

Thank you, seems I should close this?

nobiit pushed a commit to nobidev/docker-cli that referenced this pull request Nov 19, 2025
[17.06] vndr libnetwork to bring in fix for overlay network ip reuse
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@AkihiroSuda@codecov-io@dnephin@vdemeester@boaz0@GordonTheTurtle