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

Add option to force s3 virtual host addressing #655

Merged
merged 9 commits into from
Sep 30, 2015

Conversation

kyleknap
Copy link
Contributor

You can force virtual style addressing through the config file:

s3 =
    addressing_style = virtual_host

You can also specify it in the Config object passed in when a client is instantiated. The virtual host addressing no longer defaults to the s3 global endpoint. Instead, it will use the endpoint url determined from the region or if the endpoint url that is specified upon instantiation of a client:

session = botocore.session.get_session()
s3 = session.create_client('s3', config=Config(s3_addressing_style='virtual'))

If you force the virtual style addressing and the bucket name on an operation you call is not DNS compatible it will throw an error. Another important note to emphasize is that if you force the virtual style addressing, it will use the endpoint of the region you specified so you may hit PermanentRedirect errors. Otherwise if it is not forced, the requests will still be sent to the the global s3 endpoint.

As for testing, the s3 integration tests pass for both botocore and the CLI. I even tried running the integration tests with virtual style forced and the botocore tests passed and most of the CLI test passed (their were a few tests that randomly generated '.' in their name which would cause an error to be thrown as expected because the name is not DNS compatible).

Also, thanks to testing it in this fashion I fixed some bugs where if virtual style is forced and it is sigv4, we would get signature errors. We did not run into these bugs before because we would turn off virtual style if sigv4 is being used.

cc @jamesls @mtdowling @rayluo @JordonPhillips

@jamesls
Copy link
Member

jamesls commented Sep 23, 2015

Looking at this now I have some initial high level feedback before digging into this:
Given the scoped config is {'s3': {'addressing_style': 'virtual_host'}}, I think we should map as closely to that in the client config, so something like Config(s3={'addressing_style': 'virtual_host'}). It also makes it a little easier to see all the s3 specific config options rather than having to iterate over config.__dict__ and check if it starts with s3_.

@kyleknap
Copy link
Contributor Author

That sounds good. It would provide a precedence to prevent the Config file from becoming to bloated. Maybe name it to something more explicit like s3_options or s3_configuration?


# Determine if the user specified the use of virtual host addressing
# style for s3.
s3_addressing_style = 'default'
Copy link
Member

Choose a reason for hiding this comment

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

Can you move this out to a separate method? This method is getting pretty long.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah that's fine

@jamesls
Copy link
Member

jamesls commented Sep 23, 2015

Looks good, just had some small feedback.

@jamesls
Copy link
Member

jamesls commented Sep 24, 2015

@kyleknap I would prefer s3 instead of s3_configuration. I think the fact that it's in the Config object makes it clear that it's configuration data.

@kyleknap
Copy link
Contributor Author

Ok that's fair.

You can force virtual style addressing through the config file:
s3 =
    addresing_style = virtual_host

You can also specify it in the Config object passed in when a client
is instantiated. The virtual host addressing no longer defaults to the
s3 global endpoint. Instead, it will use the endpoint url determined from
the region or if the endpoint url that is specified upon instantaition of
a client.
You now specify it as a dictionary where 'addressing_style' is a key and the
value is a string representing the desired style.
Moved fix_s3_host to the client instantiation to make logic easier to build on.
@kyleknap
Copy link
Contributor Author

@jamesls
I updated based on feedback. I ended up adding support for 'path'. I also set it and ran it on the s3 CLI integration tests and all of those tests passed. So there should not be any auth issues.

@kyleknap kyleknap added pr/needs-review This PR needs a review from a member of the team. and removed incorporating-feedback labels Sep 26, 2015
s3_configuration = scoped_config.get('s3')

# Next the client config value takes precedence
if client_config is not None:
Copy link
Member

Choose a reason for hiding this comment

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

That's an interesting point. Should we maybe be merging the configs if a user has both scoped config and client config? As we add more s3 options, it would mean that a customer would typically have to grab the s3 config from the session, merge their options on top, and then create a Config object.

@jamesls
Copy link
Member

jamesls commented Sep 29, 2015

Changes look good. Just wondering what we should be doing about merging config. It makes it slightly more complicated for the user once they have various S3 options in their config and they want to override only specific options, but I suppose it's not that hard for them to manually merge the s3 config dicts before creating a client. What do you think?

Values in client config take precedence over value in scoped config
@kyleknap
Copy link
Contributor Author

@jamesls
We talked about this. Going with the merging of dictionaries approach. Should be good to look at again.

@jamesls
Copy link
Member

jamesls commented Sep 30, 2015

:shipit:

kyleknap added a commit that referenced this pull request Sep 30, 2015
Add option to force s3 virtual host addressing
@kyleknap kyleknap merged commit 8153860 into boto:develop Sep 30, 2015
@kyleknap kyleknap deleted the dns-style-host branch September 30, 2015 22:47
@kyleknap kyleknap restored the dns-style-host branch October 1, 2015 20:08
@kyleknap
Copy link
Contributor Author

kyleknap commented Oct 1, 2015

This broke some CLI integration tests reverting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr/needs-review This PR needs a review from a member of the team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants