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

ENHANCEMENT: ability to switch namespaces after Connection #665

Open
aram535 opened this issue Feb 1, 2021 · 9 comments
Open

ENHANCEMENT: ability to switch namespaces after Connection #665

aram535 opened this issue Feb 1, 2021 · 9 comments
Assignees

Comments

@aram535
Copy link

aram535 commented Feb 1, 2021

It would be nice to be able to switch namespaces for administration purpose scripts.

@jeffwecan
Copy link
Member

Exposing an explicit method to allow setting the currently selected namespace seems reasonable. In the meantime, one could accomplish this using a workaround like: hvac.Client()._adapater.namespace = '<a different namespace>'

@aram535
Copy link
Author

aram535 commented Feb 2, 2021

If you can tell me where (which file) you want it implemented in, I'll try submitting a PR for it.

@devlounge
Copy link
Contributor

devlounge commented Feb 9, 2021

if you're already connected, then a context manager could use your current client token and and create a namespace client using the root namespace token until the context ends.
Something like

client.<api>.<method>  <- uses the root namespace client
with client.namespace(<namespace name>):
    client.<api>.<method>  <- uses the namespace client
client.<api>.<method>  <- uses the root namespace client

maybe the implementation could leverage contextVars / contextlib

@jeffwecan
Copy link
Member

@devlounge: Oooh, that is a solid suggestion. I like it! In my own experience, referencing different namespaces within the same batch of "config" is often klunky (e.g., in the Vault terraform provider). That context manager idea fits with my own namespace usage patterns at least 😄

@aram535: As pretty much everything in this module goes through the "Client" class, I would vote for making this type of addition there. Adding a "set_namespace()" sort of method that propagates the value to any attendant classes (e.g., Client._adapter) would cover the initial in this issue. Though I'll probably look at how the context manager idea @devlounge suggested fits in as well.

@jeffwecan jeffwecan self-assigned this Apr 2, 2021
@bernardogza
Copy link

Hi, is this now possible to do in hvac ?

@twalker1998
Copy link

Hi, is this still a feature that is currently scoped for implementation? I have been using the workaround proposed by @jeffwecan without issues, but would still like to see this as a native feature of hvac.

@aram535
Copy link
Author

aram535 commented May 3, 2024

@jeffwecan did the _adapter get removed from hvac in recent versions? The existing code that worked is now failing with "VautClient object has no attribute _adapter".

If so, what's the proper way of switching namespaces now?

@rahulgauli
Copy link

@aram535 Were you able to find out the workaround to this ?

@aram535
Copy link
Author

aram535 commented May 31, 2024

@aram535 Were you able to find out the workaround to this ?

The adapter override still does work. I was incorrectly assigning the client in my module. After connection is established, you can manipulate the namespace with:

hvac.Client()._adapater.namespace = "namespace"

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

No branches or pull requests

6 participants