-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add function to refresh credentials from config.json #1586
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
Conversation
Please sign your commits following these rules: $ git clone -b "refresh_credentials" git@github.com:terminalmage/docker-py.git somewhere
$ cd somewhere
$ git commit --amend -s --no-edit
$ git push -f Amending updates the existing PR. You DO NOT need to open a new one. |
0ca2663
to
c6645c8
Compare
c6645c8
to
59e1ad0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That feels like the wrong approach. You could have a Client.reload_config()
instead that would be a one-liner, and much more flexible.
@shin- That's a good idea. Would this be best added to the |
Since the |
Hmm, maybe not. It looks like, from a design perspective, the functionality in the |
59e1ad0
to
81927f0
Compare
@shin- I've removed the earlier commit and added the function to the |
This allows the client to reload the config.json for an existing APIClient instance. Signed-off-by: Erik Johnson <palehose@gmail.com>
81927f0
to
0f84341
Compare
See docker/docker-py#1586 This allows an existing client instance to disregard its cached auth config and use the most up-to-date login info from the config.json.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
This is headed in the right direction. Just a few comments to address.
docker/api/daemon.py
Outdated
url = self._url("/version", versioned_api=api_version) | ||
return self._result(self._get(url), json=True) | ||
|
||
def reload_config(self, dockercfg_path=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, since this is not an API call, it should probably be added to the APIClient
class instead.
docker/api/daemon.py
Outdated
# if so load that config. | ||
if dockercfg_path and os.path.exists(dockercfg_path): | ||
self._auth_configs = auth.load_config(dockercfg_path) | ||
self._auth_configs = self.reload_config(dockercfg_path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reload_config
returns None
, so this is probably not correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, duh. I was thinking of code re-use and obviously did not test this part of the code. Good catch. Since I'm moving this to the APIClient I'll just revert these two changes in the login func.
docker/api/daemon.py
Outdated
self._auth_configs = self.reload_config(dockercfg_path) | ||
elif not self._auth_configs: | ||
self._auth_configs = auth.load_config() | ||
self._auth_configs = self.reload_config() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
docker/api/daemon.py
Outdated
|
||
def reload_config(self, dockercfg_path=None): | ||
""" | ||
Forces a reload of the auth configuration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: "Force" instead of "Forces"
Also revert an incorrect change in the DaemonApiMixin's login func Signed-off-by: Erik Johnson <palehose@gmail.com>
313cc9e
to
550c31e
Compare
@shin- Thanks for the comments, I believe I have addressed them all. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, LGTM!
👍 |
SCENARIO
X-Registry-Auth
header in the API request (push, pull, etc.)docker login
is performed on the CLI to update the config.json.SOLUTION
Add arefresh
param (default:False
) todocker.auth.get_config_header()
which, whenTrue
, forces a refresh of the config.json.Update all functions which calldocker.auth.get_config_header()
to support arefresh_credentials
argument (default:False
) which is passed through asrefresh
whenget_config_header()
is called.Usingclient.push('myuser/myimage', tag='mytag', refresh_credentials=True)
, docker-py now has up-to-date auth configuration.A function has been added to the
DaemonApiMixin
which allows for the auth to be reloaded for an existingAPIClient
instance (e.g.client.reload_config()
)