@@ -11,17 +11,19 @@ pip install phase-dev
11
11
## Import
12
12
13
13
``` python
14
- from phase import Secrets
14
+ from phase import Phase, CreateSecretsOptions, GetAllSecretsOptions, GetSecretOptions, SecretUpdateOptions, DeleteSecretOptions
15
15
```
16
16
17
17
## Initialize
18
18
19
19
Initialize the SDK with your host and token:
20
20
21
21
``` python
22
- phase = Secrets(
23
- host = ' https://your-phase-host.com' ,
22
+ phase = Phase(
23
+ init = False ,
24
+ host = ' https://your-phase-host.com' ,
24
25
pss = PHASE_SERVICE_TOKEN
26
+
25
27
)
26
28
```
27
29
@@ -32,76 +34,96 @@ phase = Secrets(
32
34
Create one or more secrets in a specified application and environment:
33
35
34
36
``` 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} " )
49
48
```
50
49
51
50
### Get Secrets
52
51
53
52
Fetch one or more secrets from a specified application and environment:
54
53
55
54
``` 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" ,
59
57
app_name = " Your App Name" ,
60
58
tag = " api" , # Optional: filter by tag
61
- path = " /" # Optional: specify path
59
+ secret_path = " /api " # Optional: specify path
62
60
)
63
-
61
+ secrets = phase.get_all_secrets(get_options)
64
62
for secret in secrets:
65
63
print (f " Key: { secret.key} , Value: { secret.value} " )
66
64
```
67
65
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
+
68
80
### Update Secrets
69
81
70
82
Update an existing secret in a specified application and environment:
71
83
72
84
``` python
73
- updated_secret = phase.PhaseSecret(
85
+ update_options = SecretUpdateOptions(
86
+ env_name = " Development" ,
87
+ app_name = " Your App Name" ,
74
88
key = " API_KEY" ,
75
89
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
86
94
)
95
+ result = phase.update_secret(update_options)
87
96
print (f " Update result: { result} " )
88
97
```
89
98
90
99
### Delete Secrets
91
100
92
- Delete one or more secrets from a specified application and environment:
101
+ Delete a secret from a specified application and environment:
93
102
94
103
``` python
95
- keys_to_delete = [" API_KEY" , " DB_PASSWORD" ]
96
- result = phase.delete(
104
+ delete_options = DeleteSecretOptions(
97
105
env_name = " Development" ,
98
- keys_to_delete = keys_to_delete,
99
106
app_name = " Your App Name" ,
100
- path = " /" # Optional: specify path
107
+ key_to_delete = " API_KEY" ,
108
+ secret_path = " /api"
101
109
)
110
+ result = phase.delete_secret(delete_options)
111
+ print (f " Delete result: { result} " )
112
+ ```
102
113
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} " )
105
127
```
106
128
107
129
## Error Handling
@@ -110,7 +132,8 @@ The SDK methods may raise exceptions for various error conditions. It's recommen
110
132
111
133
``` python
112
134
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)
114
137
except ValueError as e:
115
138
print (f " An error occurred: { e} " )
116
139
```
0 commit comments