Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image: add basic auth support to download source image #1157

Merged
merged 1 commit into from
Feb 8, 2021

Conversation

binchenX
Copy link
Contributor

@binchenX binchenX commented Feb 1, 2021

No description provided.

@theopenlab-ci
Copy link

theopenlab-ci bot commented Feb 1, 2021

Build succeeded.

@kayrus
Copy link
Collaborator

kayrus commented Feb 1, 2021

@pierrchen thanks for the PR. Did you try to set a password in a URL, e.g. https://username:password@example.com/file.img?

@binchenX
Copy link
Contributor Author

binchenX commented Feb 1, 2021

@kayrus It doesn't seems work for me and if the password contains an @ the url became invalid. Is that expected to be a legit way to set the basic Auth for you?

@kayrus
Copy link
Collaborator

kayrus commented Feb 2, 2021

According to golang/go#24572 it should work. Have you tried to escape the @ in the password field? What kind of error do you receive?

@kayrus
Copy link
Collaborator

kayrus commented Feb 2, 2021

See also https://golang.org/src/net/http/client.go#L239
https://golang.org/pkg/net/url/#Userinfo
Go automatically parses Username and Password from the URL.

@binchenX
Copy link
Contributor Author

binchenX commented Feb 3, 2021

@kayrus sorry, I made some mistake in my experiment and I can confirm (with a standalone go programe) putting user name and password in url do works (even with @ in the password - curl will complain about this).

However, I have some questions:

  1. Do you think provide separate username and password will be better alternative? IMO having the url and password in the URL is a bad practice and will cause some confusions especially in the Terraform user cases I will mention below.
  2. If we have the credential in the url, when credential changes, does Terraform consider it is a new resource and thus take actions it shouldn't?
  3. Putting credential in the url, will cause the url to be sensitive, and thus be mask out in the plan output, which make it hard for review, say if the url is correctly set.

And in either case, we need additional check the response status, since an non-2xx response won't cause error be return, and thus it will an error json file be uploaded as an image.

Let me know how you want to proceed:
A. Have separate user name and password config as this patch does.
B. Putting url and password in the url, but add the response error check.

Thanks,

if resp.StatusCode != http.StatusOK {
return "", fmt.Errorf("Error downloading image from %q, statusCode is %d", furl, resp.StatusCode)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kayrus this is the required error check I mentioned.

@binchenX
Copy link
Contributor Author

binchenX commented Feb 3, 2021

@ozerovandrei would you like to have a review on this? thanks

Copy link
Collaborator

@kayrus kayrus left a comment

Choose a reason for hiding this comment

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

Do you think provide separate username and password will be better alternative? IMO having the url and password in the URL is a bad practice and will cause some confusions especially in the Terraform user cases I will mention below.

Yes, I agree.

If we have the credential in the url, when credential changes, does Terraform consider it is a new resource and thus take actions it shouldn't?

Yes it will consider it as a new resource.

Putting credential in the url, will cause the url to be sensitive, and thus be mask out in the plan output, which make it hard for review, say if the url is correctly set.

Agree. See my comments.

And in either case, we need additional check the response status, since an non-2xx response won't cause error be return, and thus it will an error json file be uploaded as an image.

Agree.

A. Have separate user name and password config as this patch does.
B. Putting url and password in the url, but add the response error check.

Both is fine.

openstack/images_image_v2.go Outdated Show resolved Hide resolved
openstack/resource_openstack_images_image_v2.go Outdated Show resolved Hide resolved
website/docs/r/images_image_v2.html.markdown Show resolved Hide resolved
openstack/resource_openstack_images_image_v2.go Outdated Show resolved Hide resolved
@theopenlab-ci
Copy link

theopenlab-ci bot commented Feb 5, 2021

Build failed.

@binchenX
Copy link
Contributor Author

binchenX commented Feb 5, 2021

Not familiar with how to interpreter the acceptance test failure so not sure if it is related with the my change or it is false positive?

website/docs/r/images_image_v2.html.markdown Show resolved Hide resolved
openstack/images_image_v2.go Outdated Show resolved Hide resolved
@binchenX
Copy link
Contributor Author

binchenX commented Feb 5, 2021

Not entirely sure about this comments and it was marked as resolved so I didn't make any change. Let me know if I should.

@theopenlab-ci
Copy link

theopenlab-ci bot commented Feb 5, 2021

Build failed.

Copy link
Collaborator

@kayrus kayrus left a comment

Choose a reason for hiding this comment

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

LGTM
Let's wait for openlab issues to be fixed.

@theopenlab-ci
Copy link

theopenlab-ci bot commented Feb 7, 2021

Build succeeded.

@kayrus kayrus merged commit de4cc97 into terraform-provider-openstack:main Feb 8, 2021
@kayrus
Copy link
Collaborator

kayrus commented Feb 8, 2021

@pierrchen merged, thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants