Skip to content

Commit 0734648

Browse files
committed
feat: updated readme
1 parent e6dc78b commit 0734648

File tree

1 file changed

+64
-41
lines changed

1 file changed

+64
-41
lines changed

README.md

Lines changed: 64 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,19 @@ pip install phase-dev
1111
## Import
1212

1313
```python
14-
from phase import Secrets
14+
from phase import Phase, CreateSecretsOptions, GetAllSecretsOptions, GetSecretOptions, SecretUpdateOptions, DeleteSecretOptions
1515
```
1616

1717
## Initialize
1818

1919
Initialize the SDK with your host and token:
2020

2121
```python
22-
phase = Secrets(
23-
host='https://your-phase-host.com',
22+
phase = Phase(
23+
init=False,
24+
host='https://your-phase-host.com',
2425
pss=PHASE_SERVICE_TOKEN
26+
2527
)
2628
```
2729

@@ -32,76 +34,96 @@ phase = Secrets(
3234
Create one or more secrets in a specified application and environment:
3335

3436
```python
35-
new_secrets = [
36-
phase.PhaseSecret(
37-
key="API_KEY",
38-
value="your-api-key",
39-
comment="API key for our service",
40-
path="/",
41-
tags=["api", "credentials"],
42-
overridden=False
43-
),
44-
# Add more secrets as needed
45-
]
46-
47-
response = phase.create(secrets=new_secrets, env_name="Development", app_name="Your App Name")
48-
print(f"Create Response Status Code: {response.status_code}")
37+
create_options = CreateSecretsOptions(
38+
env_name="Development",
39+
app_name="Your App Name",
40+
key_value_pairs=[
41+
{"API_KEY": "your-api-key"},
42+
{"DB_PASSWORD": "your-db-password"}
43+
],
44+
secret_path="/api"
45+
)
46+
result = phase.create_secrets(create_options)
47+
print(f"Create secrets result: {result}")
4948
```
5049

5150
### Get Secrets
5251

5352
Fetch one or more secrets from a specified application and environment:
5453

5554
```python
56-
secrets = phase.get(
57-
env_name="Development",
58-
keys=["API_KEY"], # Optional: specify keys to retrieve
55+
get_options = GetAllSecretsOptions(
56+
env_name="Development",
5957
app_name="Your App Name",
6058
tag="api", # Optional: filter by tag
61-
path="/" # Optional: specify path
59+
secret_path="/api" # Optional: specify path
6260
)
63-
61+
secrets = phase.get_all_secrets(get_options)
6462
for secret in secrets:
6563
print(f"Key: {secret.key}, Value: {secret.value}")
6664
```
6765

66+
To get a specific secret:
67+
68+
```python
69+
get_options = GetSecretOptions(
70+
env_name="Development",
71+
app_name="Your App Name",
72+
key_to_find="API_KEY",
73+
secret_path="/api"
74+
)
75+
secret = phase.get_secret(get_options)
76+
if secret:
77+
print(f"Key: {secret.key}, Value: {secret.value}")
78+
```
79+
6880
### Update Secrets
6981

7082
Update an existing secret in a specified application and environment:
7183

7284
```python
73-
updated_secret = phase.PhaseSecret(
85+
update_options = SecretUpdateOptions(
86+
env_name="Development",
87+
app_name="Your App Name",
7488
key="API_KEY",
7589
value="new-api-key-value",
76-
comment="Updated API key",
77-
path="/",
78-
tags=["api", "credentials", "updated"],
79-
overridden=False
80-
)
81-
82-
result = phase.update(
83-
secret=updated_secret,
84-
env_name="Development",
85-
app_name="Your App Name"
90+
secret_path="/api",
91+
destination_path="/new-api", # Optional: move secret to a new path
92+
override=False, # Optional: create a personal override
93+
toggle_override=False # Optional: toggle personal override
8694
)
95+
result = phase.update_secret(update_options)
8796
print(f"Update result: {result}")
8897
```
8998

9099
### Delete Secrets
91100

92-
Delete one or more secrets from a specified application and environment:
101+
Delete a secret from a specified application and environment:
93102

94103
```python
95-
keys_to_delete = ["API_KEY", "DB_PASSWORD"]
96-
result = phase.delete(
104+
delete_options = DeleteSecretOptions(
97105
env_name="Development",
98-
keys_to_delete=keys_to_delete,
99106
app_name="Your App Name",
100-
path="/" # Optional: specify path
107+
key_to_delete="API_KEY",
108+
secret_path="/api"
101109
)
110+
result = phase.delete_secret(delete_options)
111+
print(f"Delete result: {result}")
112+
```
102113

103-
print(f"Deleted secrets: {result['deleted']}")
104-
print(f"Secrets not found: {result['not_found']}")
114+
### Resolve Secret References
115+
116+
Resolve references in secret values:
117+
118+
```python
119+
get_options = GetAllSecretsOptions(
120+
env_name="Development",
121+
app_name="Your App Name"
122+
)
123+
secrets = phase.get_all_secrets(get_options)
124+
resolved_secrets = phase.resolve_references(secrets, "Development", "Your App Name")
125+
for secret in resolved_secrets:
126+
print(f"Key: {secret.key}, Resolved Value: {secret.value}")
105127
```
106128

107129
## Error Handling
@@ -110,7 +132,8 @@ The SDK methods may raise exceptions for various error conditions. It's recommen
110132

111133
```python
112134
try:
113-
secrets = phase.get(env_name="Development", app_name="Your App Name")
135+
get_options = GetAllSecretsOptions(env_name="Development", app_name="Your App Name")
136+
secrets = phase.get_all_secrets(get_options)
114137
except ValueError as e:
115138
print(f"An error occurred: {e}")
116139
```

0 commit comments

Comments
 (0)