connectortestpython


Nameconnectortestpython JSON
Version 1.0.1 PyPI version JSON
download
home_pagehttps://github.com/dimavladimirov/mini_connector
SummaryTest module
upload_time2024-04-21 13:51:49
maintainerNone
docs_urlNone
authordimavladimirov
requires_python>=3.10
licenseNone
keywords example python
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ## About the API
Passwork API lets you retrieve, create, update passwords, folders and vaults. It is an easy way how you can integrate Passwork with your infrastructure. Use our Passwork Python Connector to make the integration smoother. The API operates behalf of the user whom API Key is used.
Check for all available methods in
[Passwork API Methods](connectortestpython/passwork_api.py)

## How to install
⚠️<b style='color:YELLOW'>WARNING</b> the connector will not work with python version less than <b>3.10</b>
```shell script
git clone https://github.com/passwork-me/python-connector.git .
pip install -r requirements.txt
```

## Environment variables
The following environment variables are required for operation:

<b>HOST:</b> The address of the API server, like `https://.../api/v4` <br>
<b>API_KEY:</b> Your API key for authentication, instructions for obtaining below <br>
<b>MASTER_PASSWORD:</b> Client-side encryption key. Only add it when client-side encryption is enabled <br>

Several available options for storing environment variables: <br>
1) [.env file](./.env)
2) run/debug configuration (IDLE)
3) system environment variables

### API Key

![alt text](connectortestpython/passwork.png)

- Sign in to your Passwork
- Menu → API Settings
- Enter your authorization key and generate the API Key

Use method `login()` on instance of [PassworkAPI class](connectortestpython/passwork_api.py) to retrieve a temporary API Token.
An API token is a session token. It is valid as long as you are accessing the API. After it expires, you will need to log in again.
API Token Lifetime can be set up in your Passwork.
The retrieved API token is stored as an instance variable named `session_options` within the [PassworkAPI class](connectortestpython/passwork_api.py) and is subsequently sent in an HTTP header.

## Step-by-step guide

### Create session (common step for all operations)
0. Create instance of API connection and open session.

```python
from package.passwork_api import PassworkAPI

# A way to overwrite the specified data in environment variables or not use environment variables at all
options_override = {
    "host": str(),
    "api_key": str(),
    "master_password": str(),
}

api = PassworkAPI(options_override=options_override)
api.login()
# api.logout()  # close session after all operations with Passwork API
```

### [Password search by parameters](connectortestpython/examples/search_password.py)

1. Fill data in `search_params` dict template with searching parameters to `search_password` method

```python
search_params = {
    "query": "",
    "tags": [],
    "colors": [],
    "vaultId": None,
    "includeShared": False,
    "includeShortcuts": False,
}
```

2. Search password

```python
found_passwords = api.search_password(**search_params)
```


### [Get full password info](connectortestpython/examples/get_password.py)
<b style='color:green'>NOTE</b> `PASSWORD_ID` must contain the identifier of the target password, in the example a non-existent identifier is specified
1. Get password and vault items
```python
PASSWORD_ID = "0123456789abcdefghijklmn"
password_item = api.get_password(password_id=PASSWORD_ID)
vault_id = password_item.get("vaultId")
vault_item = api.get_vault(vault_id=vault_id)
```

2. Receive vault password and password encryption key

```python
vault_password = api.get_vault_password(vault_item=vault_item)
password_encryption_key = api.get_password_encryption_key(
    password_item=password_item,
    vault_password=vault_password
)
```

3. Receive password customs, password plain text and download attachments 

```python
password_item["custom"] = api.get_customs(
    password_item=password_item,
    password_encryption_key=password_encryption_key
)

api.get_attachments(
    password_item=password_item,
    password_encryption_key=password_encryption_key
)

password_plain_text = api.get_password_plain_text(
    password_item=password_item,
    password_encryption_key=password_encryption_key
)
```

4. Show full password info in readable format

```python
full_password_info = {
    "password": password_item,
    "vault": vault_item,
    "vaultMasterKey": vault_password,
    "passwordMasterKey": password_encryption_key,
    "passwordPlainText": password_plain_text,
}

pretty_data = json.dumps(full_password_info, indent=4)
logger.success(pretty_data)
```

### [Add password](connectortestpython/examples/add_password.py)
<b style='color:green'>NOTE</b> If `VAULT_ID` is specified, the `PASSWORD_ID` variable may be empty.
Without specifying of `VAULT_ID`, the identifier of the vault where the password with id = `PASSWORD_ID` is stored will be taken. 
The identifiers `PASSWORD_ID` and `VAULT_ID` in the example are non-existent.

1. Receive vault item and vault password
```python
PASSWORD_ID = "0123456789abcdefghijklmn"
VAULT_ID = "0123456789abcdefghijklmn"

vault_id = VAULT_ID if VAULT_ID else api.get_password(password_id=PASSWORD_ID)["vaultId"]
vault_item = api.get_vault(vault_id=vault_id)
vault_password = api.get_vault_password(vault_item=vault_item)
```

2. Fill data in `password_adding_fields` dict template
```python
password_adding_fields = {}
```

3. Add password
```python
added_password_info = api.add_password(password_adding_fields, vault_item, vault_password)
logger.success(f"Password with id {added_password_info['id']} has been added")
```

### [Delete password](connectortestpython/examples/delete_password.py)
<b style='color:green'>NOTE</b> `PASSWORD_ID` must contain the identifier of the target password, in the example a non-existent identifier is specified

1. Delete a password by its id
```python
PASSWORD_ID = "0123456789abcdefghijklmn"
api.delete_password(password_id=PASSWORD_ID)
```

### Examples and algorithm of work with the connector
[Examples here](connectortestpython/examples)


### License
This project is licensed under the terms of the MIT license.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/dimavladimirov/mini_connector",
    "name": "connectortestpython",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "example python",
    "author": "dimavladimirov",
    "author_email": "vladimirovdmitry@mail.ru",
    "download_url": "https://files.pythonhosted.org/packages/51/4a/1e78843b3ad06177bc840aca27a7add712ddc66dba2dacc91b41c5a8d2fb/connectortestpython-1.0.1.tar.gz",
    "platform": null,
    "description": "## About the API\nPasswork API lets you retrieve, create, update passwords, folders and vaults. It is an easy way how you can integrate Passwork with your infrastructure. Use our Passwork Python Connector to make the integration smoother. The API operates behalf of the user whom API Key is used.\nCheck for all available methods in\n[Passwork API Methods](connectortestpython/passwork_api.py)\n\n## How to install\n\u26a0\ufe0f<b style='color:YELLOW'>WARNING</b> the connector will not work with python version less than <b>3.10</b>\n```shell script\ngit clone https://github.com/passwork-me/python-connector.git .\npip install -r requirements.txt\n```\n\n## Environment variables\nThe following environment variables are required for operation:\n\n<b>HOST:</b> The address of the API server, like `https://.../api/v4` <br>\n<b>API_KEY:</b> Your API key for authentication, instructions for obtaining below <br>\n<b>MASTER_PASSWORD:</b> Client-side encryption key. Only add it when client-side encryption is enabled <br>\n\nSeveral available options for storing environment variables: <br>\n1) [.env file](./.env)\n2) run/debug configuration (IDLE)\n3) system environment variables\n\n### API Key\n\n![alt text](connectortestpython/passwork.png)\n\n- Sign in to your Passwork\n- Menu \u2192 API Settings\n- Enter your authorization key and generate the API Key\n\nUse method `login()` on instance of [PassworkAPI class](connectortestpython/passwork_api.py) to retrieve a temporary API Token.\nAn API token is a session token. It is valid as long as you are accessing the API. After it expires, you will need to log in again.\nAPI Token Lifetime can be set up in your Passwork.\nThe retrieved API token is stored as an instance variable named `session_options` within the [PassworkAPI class](connectortestpython/passwork_api.py) and is subsequently sent in an HTTP header.\n\n## Step-by-step guide\n\n### Create session (common step for all operations)\n0. Create instance of API connection and open session.\n\n```python\nfrom package.passwork_api import PassworkAPI\n\n# A way to overwrite the specified data in environment variables or not use environment variables at all\noptions_override = {\n    \"host\": str(),\n    \"api_key\": str(),\n    \"master_password\": str(),\n}\n\napi = PassworkAPI(options_override=options_override)\napi.login()\n# api.logout()  # close session after all operations with Passwork API\n```\n\n### [Password search by parameters](connectortestpython/examples/search_password.py)\n\n1. Fill data in `search_params` dict template with searching parameters to `search_password` method\n\n```python\nsearch_params = {\n    \"query\": \"\",\n    \"tags\": [],\n    \"colors\": [],\n    \"vaultId\": None,\n    \"includeShared\": False,\n    \"includeShortcuts\": False,\n}\n```\n\n2. Search password\n\n```python\nfound_passwords = api.search_password(**search_params)\n```\n\n\n### [Get full password info](connectortestpython/examples/get_password.py)\n<b style='color:green'>NOTE</b> `PASSWORD_ID` must contain the identifier of the target password, in the example a non-existent identifier is specified\n1. Get password and vault items\n```python\nPASSWORD_ID = \"0123456789abcdefghijklmn\"\npassword_item = api.get_password(password_id=PASSWORD_ID)\nvault_id = password_item.get(\"vaultId\")\nvault_item = api.get_vault(vault_id=vault_id)\n```\n\n2. Receive vault password and password encryption key\n\n```python\nvault_password = api.get_vault_password(vault_item=vault_item)\npassword_encryption_key = api.get_password_encryption_key(\n    password_item=password_item,\n    vault_password=vault_password\n)\n```\n\n3. Receive password customs, password plain text and download attachments \n\n```python\npassword_item[\"custom\"] = api.get_customs(\n    password_item=password_item,\n    password_encryption_key=password_encryption_key\n)\n\napi.get_attachments(\n    password_item=password_item,\n    password_encryption_key=password_encryption_key\n)\n\npassword_plain_text = api.get_password_plain_text(\n    password_item=password_item,\n    password_encryption_key=password_encryption_key\n)\n```\n\n4. Show full password info in readable format\n\n```python\nfull_password_info = {\n    \"password\": password_item,\n    \"vault\": vault_item,\n    \"vaultMasterKey\": vault_password,\n    \"passwordMasterKey\": password_encryption_key,\n    \"passwordPlainText\": password_plain_text,\n}\n\npretty_data = json.dumps(full_password_info, indent=4)\nlogger.success(pretty_data)\n```\n\n### [Add password](connectortestpython/examples/add_password.py)\n<b style='color:green'>NOTE</b> If `VAULT_ID` is specified, the `PASSWORD_ID` variable may be empty.\nWithout specifying of `VAULT_ID`, the identifier of the vault where the password with id = `PASSWORD_ID` is stored will be taken. \nThe identifiers `PASSWORD_ID` and `VAULT_ID` in the example are non-existent.\n\n1. Receive vault item and vault password\n```python\nPASSWORD_ID = \"0123456789abcdefghijklmn\"\nVAULT_ID = \"0123456789abcdefghijklmn\"\n\nvault_id = VAULT_ID if VAULT_ID else api.get_password(password_id=PASSWORD_ID)[\"vaultId\"]\nvault_item = api.get_vault(vault_id=vault_id)\nvault_password = api.get_vault_password(vault_item=vault_item)\n```\n\n2. Fill data in `password_adding_fields` dict template\n```python\npassword_adding_fields = {}\n```\n\n3. Add password\n```python\nadded_password_info = api.add_password(password_adding_fields, vault_item, vault_password)\nlogger.success(f\"Password with id {added_password_info['id']} has been added\")\n```\n\n### [Delete password](connectortestpython/examples/delete_password.py)\n<b style='color:green'>NOTE</b> `PASSWORD_ID` must contain the identifier of the target password, in the example a non-existent identifier is specified\n\n1. Delete a password by its id\n```python\nPASSWORD_ID = \"0123456789abcdefghijklmn\"\napi.delete_password(password_id=PASSWORD_ID)\n```\n\n### Examples and algorithm of work with the connector\n[Examples here](connectortestpython/examples)\n\n\n### License\nThis project is licensed under the terms of the MIT license.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Test module",
    "version": "1.0.1",
    "project_urls": {
        "Documentation": "https:/www.google.com",
        "Homepage": "https://github.com/dimavladimirov/mini_connector"
    },
    "split_keywords": [
        "example",
        "python"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "514a1e78843b3ad06177bc840aca27a7add712ddc66dba2dacc91b41c5a8d2fb",
                "md5": "c38e40ee67c17dbf316e5b992a9203a0",
                "sha256": "ac5f5a629e9c21e79a6d26f60b452297e95744c46d5b05000ed3191599a034b8"
            },
            "downloads": -1,
            "filename": "connectortestpython-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "c38e40ee67c17dbf316e5b992a9203a0",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 14666,
            "upload_time": "2024-04-21T13:51:49",
            "upload_time_iso_8601": "2024-04-21T13:51:49.693979Z",
            "url": "https://files.pythonhosted.org/packages/51/4a/1e78843b3ad06177bc840aca27a7add712ddc66dba2dacc91b41c5a8d2fb/connectortestpython-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-21 13:51:49",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "dimavladimirov",
    "github_project": "mini_connector",
    "github_not_found": true,
    "lcname": "connectortestpython"
}
        
Elapsed time: 2.93708s