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

Change version validation to not happen during initialization #202

Open
joewesch opened this issue Jun 18, 2024 · 1 comment · May be fixed by #225
Open

Change version validation to not happen during initialization #202

joewesch opened this issue Jun 18, 2024 · 1 comment · May be fixed by #225

Comments

@joewesch
Copy link
Contributor

When you first create the nautobot.api class it runs the self._validate_version method which tries to connect to the Nautobot instance immediately. This can cause issues if the end user needs to modify the http session settings.

One alternative would be to accept the http session parameters as kwargs to the Api class, but that can be a cat and mouse game of keeping up with all options - and is definitely not scalable - so I'm not a fan.

Another alternative would be to allow for users to bypass this validation on initialization and expose it as a public method to let them validate themselves. This is all well and good, but I'd still like it to happen automatically.

My initial thought would be to add a boolean flag like self._version_validated=False, and any time we are about to make a call to Nautobot we can check if it's false and run self._validate_version first.

I'm open to other ideas if anyone else would like to weigh in.

@tsm1th
Copy link
Contributor

tsm1th commented Jul 8, 2024

What if we just let the user pass in their own session instead of handling the kwargs ourselves?

Ex -

    def __init__(
        self,
        url,
        token=None,
        threading=False,
        max_workers=4,
        api_version=None,
        retries=0,
        verify=True,
        http_session=None,
    ):
        base_url = "{}/api".format(url if url[-1] != "/" else url[:-1])
        self.token = token
        self.headers = {"Authorization": f"Token {self.token}"}
        self.base_url = base_url
        self.http_session = requests.Session() if not http_session else http_session

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 a pull request may close this issue.

2 participants