1Password / connect-sdk-python

Python SDK for 1Password Connect
https://developer.1password.com/docs/connect
MIT License
200 stars 31 forks source link

Error calling onepasswordconnectsdk.load_dict() #35

Closed si-kotic closed 2 years ago

si-kotic commented 2 years ago

Your environment

SDK Version: 1.1.0

Connect Server Version:1.5.0

OS: Ubuntu 20.04

Python Version: 3.8.2

What happened?

When following the instructions to create a dict to limit the fields returned, I receive the following error: load_dict() missing 1 required positional argument: 'config' If I copy and paste the text from the README, I get the same error.

What did you expect to happen?

The variable values_dict to be set with the the value returned from onepasswordconnectsdk.load_dict(CONFIG)

Steps to reproduce

import onepasswordconnectsdk

CONFIG = {
    "server": {
        "opitem": "My database item",
        "opfield": "specific_section.hostname",
        "opvault": "some_vault_id",
    },
    "database": {
        "opitem": "My database item",
        "opfield": ".database",
    },
    "username": {
        "opitem": "My database item",
        "opfield": ".username",
    },
    "password": {
        "opitem": "My database item",
        "opfield": ".password",
    },
}

values_dict = onepasswordconnectsdk.load_dict(CONFIG)
Marton6 commented 2 years ago

Thank you for reporting this issue!

It seems the docs are incorrect. The load_dict function requires two parameters, the first one being a onepasswordconnectsdk.Client and the second one being the config.

So you should call load_dict like this:

import onepasswordconnectsdk

CONFIG = {
    "server": {
        "opitem": "My database item",
        "opfield": "specific_section.hostname",
        "opvault": "some_vault_id",
    },
    "database": {
        "opitem": "My database item",
        "opfield": ".database",
    },
    "username": {
        "opitem": "My database item",
        "opfield": ".username",
    },
    "password": {
        "opitem": "My database item",
        "opfield": ".password",
    },
}

client = new_client_from_environment()
values_dict = onepasswordconnectsdk.load_dict(client, CONFIG)

I will open a PR and fix the docs soon!

Marton6 commented 2 years ago

Closed. Please reopen the issue if you run into any other problems related to this!