Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Add options to docker login azure to support Service Principal login. Use it in E2E tests #448

Merged
merged 2 commits into from
Aug 11, 2020

Conversation

gtardif
Copy link
Contributor

@gtardif gtardif commented Aug 10, 2020

What I did
Expose service principal login in the CLI, use it in E2E tests.

Related issue
docker-archive/cloud-integration-beta#21

(not mandatory) A picture of a cute animal, if possible in relation with what you did
image

aci/backend_test.go Show resolved Hide resolved
aci/backend.go Outdated
}

func (cs *aciCloudService) Login(ctx context.Context, params interface{}) error {
createOpts := params.(LoginParams)
return cs.loginService.Login(ctx, createOpts.TenantID)
loginOpts := params.(LoginParams)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need a check here to make sure the cast was good?

We can just call this opts as we're in the login function.

Suggested change
loginOpts := params.(LoginParams)
opts := params.(LoginParams)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

aci/backend.go Outdated
loginOpts := params.(LoginParams)
if loginOpts.ClientID != "" {
if loginOpts.ClientSecret == "" || loginOpts.TenantID == "" {
return errors.New("for Service Principal login, 3 options must be specified : --client-id, --client-secret and --tenant-id")
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: when we put in place cleaner errors, we should specify things like flags at the CLI level instead of in the backend.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I wasn't sure where to put this validation code ; I've put this next to the check for clientID required anyway to call LoginServiceProvider, but that could be moved somewhere else...

Copy link
Contributor

Choose a reason for hiding this comment

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

aci.LoginParams could have a Validate function or something

Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved to a Validate() on LoginParams (and called from the corba command)

@gtardif gtardif force-pushed the azure_sp_login branch 2 times, most recently from 5113013 to 3846ab5 Compare August 11, 2020 07:31
ClientID: "someID",
})

assert.Error(t, err, "for Service Principal login, 3 options must be specified : --client-id, --client-secret and --tenant-id")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
assert.Error(t, err, "for Service Principal login, 3 options must be specified : --client-id, --client-secret and --tenant-id")
assert.Error(t, err, "for Service Principal login, 3 options must be specified: --client-id, --client-secret and --tenant-id")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

cli/cmd/login/azurelogin.go Outdated Show resolved Hide resolved
Co-authored-by: Djordje Lukic <djordje.lukic@docker.com>
Copy link
Contributor

@chris-crone chris-crone left a comment

Choose a reason for hiding this comment

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

LGTM

@gtardif gtardif merged commit ba6e804 into main Aug 11, 2020
@gtardif gtardif deleted the azure_sp_login branch August 11, 2020 14:22
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants