Skip to content

Commit 4032af0

Browse files
committed
Initial 1Password Connect Python SDK Commit
0 parents  commit 4032af0

26 files changed

+4182
-0
lines changed

.gitignore

+146
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
share/python-wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
MANIFEST
28+
29+
# PyInstaller
30+
# Usually these files are written by a python script from a template
31+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32+
*.manifest
33+
*.spec
34+
35+
# Installer logs
36+
pip-log.txt
37+
pip-delete-this-directory.txt
38+
39+
# Unit test / coverage reports
40+
htmlcov/
41+
.tox/
42+
.nox/
43+
.coverage
44+
.coverage.*
45+
.cache
46+
nosetests.xml
47+
coverage.xml
48+
*.cover
49+
*.py,cover
50+
.hypothesis/
51+
.pytest_cache/
52+
cover/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
.pybuilder/
76+
target/
77+
78+
# Jupyter Notebook
79+
.ipynb_checkpoints
80+
81+
# IPython
82+
profile_default/
83+
ipython_config.py
84+
85+
# pyenv
86+
# For a library or package, you might want to ignore these files since the code is
87+
# intended to run in multiple environments; otherwise, check them in:
88+
# .python-version
89+
90+
# pipenv
91+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
93+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
94+
# install all needed dependencies.
95+
#Pipfile.lock
96+
97+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
98+
__pypackages__/
99+
100+
# Celery stuff
101+
celerybeat-schedule
102+
celerybeat.pid
103+
104+
# SageMath parsed files
105+
*.sage.py
106+
107+
# Environments
108+
.env
109+
.venv
110+
env/
111+
venv/
112+
ENV/
113+
env.bak/
114+
venv.bak/
115+
116+
# Spyder project settings
117+
.spyderproject
118+
.spyproject
119+
120+
# Rope project settings
121+
.ropeproject
122+
123+
# mkdocs documentation
124+
/site
125+
126+
# mypy
127+
.mypy_cache/
128+
.dmypy.json
129+
dmypy.json
130+
131+
# Pyre type checker
132+
.pyre/
133+
134+
# pytype static type analyzer
135+
.pytype/
136+
137+
# Cython debug symbols
138+
cython_debug/
139+
140+
# VScode
141+
.vscode/
142+
143+
# Goland
144+
.idea/
145+
146+
.DS_Store

LICENSE.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) [2020] [1Password]
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+189
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
# 1Password Connect Python SDK
2+
3+
The 1Password Connect SDK provides access to the 1Password via 1Password Connect hosted on your infrastructure. The library is intended to be used by Python applications to simplify accessing `items` in 1Password `vaults`.
4+
5+
## Prerequisites:
6+
7+
- 1Password Connect deployed in your infrastructure.
8+
## Installation
9+
10+
`pip install https://github.com/1Password/connect-sdk-python/archive/v{version}.zip`
11+
12+
## Usage
13+
14+
**Import 1Password Connect Python SDK**
15+
16+
```python
17+
import onepasswordconnectsdk
18+
```
19+
20+
**Environment Variables**
21+
22+
- **OP_CONNECT_TOKEN** – The token to be used to authenticate with the 1Password Connect API.
23+
- **OP_VAULT** - The default vault to fetch items from if not specified.
24+
25+
**Creating a Client**
26+
27+
There are two methods available for creating a client:
28+
29+
- `new_client_from_environment`: Builds a new client for interacting with 1Password Connect using the `OP_CONNECT_TOKEN` *environment variable (ie a 1Password Connect API token)* and the hostname of 1Password Connect.
30+
- `new_client`: Builds a new client for interacting with 1Password Connect. Accepts the hostname of 1Password Connect and the API token generated for the application.
31+
32+
```python
33+
:from onepasswordconnectsdk.client import (
34+
Client,
35+
new_client_from_environment
36+
)
37+
38+
# creating client using OP_CONNECT_TOKEN environment variable
39+
client: Client = new_client_from_environment(
40+
"{1Password_Connect_Host}")
41+
42+
# creating client by supplying hostname and 1Password Connect API token
43+
client: Client = new_client_from_environment(
44+
"{1Password_Connect_Host}",
45+
"{1Password_Connect_API_Token}")
46+
```
47+
48+
**Get Item**
49+
50+
Get a specific item by item and vault uuids:
51+
52+
```python
53+
client.get_item("{item_id}", "{vault_id}")
54+
```
55+
56+
**Get Item By Title**
57+
58+
Get item by item title and vault id
59+
60+
```python
61+
client.get_item_by_title("{item_title}", "{vault_id}")
62+
```
63+
64+
**Get Items**
65+
66+
Get a summarized list of all items for a specified vault
67+
68+
```python
69+
client.get_items("{vault_id}")
70+
```
71+
72+
**Delete Item**
73+
74+
Delete an item by item and vault ids:
75+
76+
```python
77+
client.delete_item("{item_id}", "{vault_id}")
78+
```
79+
80+
**Create Item**
81+
82+
Create an item in the specified vault.
83+
84+
```python
85+
# Example item creation. Create an item with your desired arguments.
86+
item = onepasswordconnectsdk.models.FullItem(vault=ItemVault(id="av223f76ydutdngislnkbz6z5u"),
87+
id="kp2td65r4wbuhocwhhijpdbfqq",
88+
title="newtitle",
89+
category="LOGIN",
90+
tags=["1password-connect"],
91+
fields=[FullItemAllOfFields(value="new_user",
92+
purpose="USERNAME")],
93+
)
94+
client.create_item("{vault_id}", item)
95+
```
96+
97+
**Update Item**
98+
99+
Item the item with the specified item and vault ids. The existing item will be overwritten with the newly supplied item.
100+
101+
```python
102+
# Example item creation. Create an item with your desired arguments.
103+
item = onepasswordconnectsdk.models.FullItem(vault=ItemVault(id="av223f76ydutdngislnkbz6z5u"),
104+
id="kp2td65r4wbuhocwhhijpdbfqq",
105+
title="newtitle",
106+
category="LOGIN",
107+
tags=["1password-connect"],
108+
fields=[FullItemAllOfFields(value="new_user",
109+
purpose="USERNAME")],
110+
)
111+
client.update_item("{item_id}", "{vault_id}", item)
112+
```
113+
114+
**Get Vault**
115+
116+
Get vault by vault id
117+
118+
```python
119+
client.get_vault("{vault_id}")
120+
```
121+
122+
**Get Vaults**
123+
124+
Retrieve all vaults available to the service account.
125+
126+
```python
127+
client.get_vaults()
128+
```
129+
130+
**Load Configuration**
131+
132+
Users can create `classes` or `dicts` that describe fields they wish to get the values from in 1Password. Two convienience methods are provided that will handle the fetching of values for these fields:
133+
134+
- **load_dict**: Takes a dictionary with keys specifying the user desired naming scheme of the values to return. Each key's value is a dictionary that includes information on where to find the item field value in 1Password. This returns a dictionary of user specified keys with values retrieved from 1Password
135+
- **load**: Takes an object with class attributes annotated with tags describing where to find desired fields in 1Password. Manipulates given object and fills attributes in with 1Password item field values.
136+
137+
```python
138+
# example dict configuration for onepasswordconnectsdk.load_dict(CONFIG)
139+
CONFIG = {
140+
"server": {
141+
"opitem": "My database item",
142+
"opfield": "specific_section.hostname",
143+
"opvault": "some_vault_id",
144+
},
145+
"database": {
146+
"opitem": "My database item",
147+
"opfield": ".database",
148+
},
149+
"username": {
150+
"opitem": "My database item",
151+
"opfield": ".username",
152+
},
153+
"password": {
154+
"opitem": "My database item",
155+
"opfield": ".password",
156+
},
157+
}
158+
159+
values_dict = onepasswordconnectsdk.load_dict(CONFIG)
160+
```
161+
162+
```python
163+
# example class configuration for onepasswordconnectsdk.load(CONFIG)
164+
class Config:
165+
server: 'opitem:"My database item" opvault:some_vault_id opfield:specific_section.hostname' = None
166+
database: 'opitem:"My database item" opfield:.database' = None
167+
username: 'opitem:"My database item" opfield:.username' = None
168+
password: 'opitem:"My database item" opfield:.password' = None
169+
170+
CONFIG = Config()
171+
172+
values_object = onepasswordconnectsdk.load(CONFIG)
173+
```
174+
175+
## Development
176+
177+
**Testing**
178+
179+
```bash
180+
$ pytest
181+
```
182+
183+
## Security
184+
185+
1Password requests you practice responsible disclosure if you discover a vulnerability.
186+
187+
Please file requests via [**BugCrowd**](https://bugcrowd.com/agilebits).
188+
189+
For information about security practices, please visit our [Security homepage](https://bugcrowd.com/agilebits).

0 commit comments

Comments
 (0)