1
- from typing import Optional
1
+ from typing import List , Optional
2
2
3
3
from descope ._auth_base import AuthBase
4
4
from descope .management .common import MgmtV1
@@ -25,10 +25,60 @@ def update_name(
25
25
pswd = self ._auth .management_key ,
26
26
)
27
27
28
+ def update_tags (
29
+ self ,
30
+ tags : List [str ],
31
+ ):
32
+ """
33
+ Update the current project tags.
34
+
35
+ Args:
36
+ tags (List[str]): Array of free text tags.
37
+ Raise:
38
+ AuthException: raised if operation fails
39
+ """
40
+ self ._auth .do_post (
41
+ MgmtV1 .project_update_tags ,
42
+ {
43
+ "tags" : tags ,
44
+ },
45
+ pswd = self ._auth .management_key ,
46
+ )
47
+
48
+ def list_projects (
49
+ self ,
50
+ ) -> dict :
51
+ """
52
+ List of all the projects in the company.
53
+
54
+ Return value (dict):
55
+ Return dict in the format
56
+ {"projects": []}
57
+ "projects" contains a list of all of the projects and their information
58
+
59
+ Raise:
60
+ AuthException: raised if operation fails
61
+ """
62
+ response = self ._auth .do_post (
63
+ MgmtV1 .project_list_projects ,
64
+ {},
65
+ pswd = self ._auth .management_key ,
66
+ )
67
+ resp = response .json ()
68
+
69
+ projects = resp ["projects" ]
70
+ # Apply the function to the projects list
71
+ formatted_projects = self .remove_tag_field (projects )
72
+
73
+ # Return the same structure with 'tag' removed
74
+ result = {"projects" : formatted_projects }
75
+ return result
76
+
28
77
def clone (
29
78
self ,
30
79
name : str ,
31
- tag : Optional [str ] = None ,
80
+ environment : Optional [str ] = None ,
81
+ tags : Optional [List [str ]] = None ,
32
82
):
33
83
"""
34
84
Clone the current project, including its settings and configurations.
@@ -37,10 +87,11 @@ def clone(
37
87
38
88
Args:
39
89
name (str): The new name for the project.
40
- tag (str): Optional tag for the project. Currently, only the "production" tag is supported.
90
+ environment (str): Optional state for the project. Currently, only the "production" tag is supported.
91
+ tags(list[str]): Optional free text tags.
41
92
42
93
Return value (dict):
43
- Return dict Containing the new project details (name, id, and tag).
94
+ Return dict Containing the new project details (name, id, environment and tag).
44
95
45
96
Raise:
46
97
AuthException: raised if clone operation fails
@@ -49,7 +100,8 @@ def clone(
49
100
MgmtV1 .project_clone ,
50
101
{
51
102
"name" : name ,
52
- "tag" : tag ,
103
+ "environment" : environment ,
104
+ "tags" : tags ,
53
105
},
54
106
pswd = self ._auth .management_key ,
55
107
)
@@ -95,11 +147,17 @@ def import_project(
95
147
Raise:
96
148
AuthException: raised if import operation fails
97
149
"""
98
- response = self ._auth .do_post (
150
+ self ._auth .do_post (
99
151
MgmtV1 .project_import ,
100
152
{
101
153
"files" : files ,
102
154
},
103
155
pswd = self ._auth .management_key ,
104
156
)
105
157
return
158
+
159
+ # Function to remove 'tag' field from each project
160
+ def remove_tag_field (self , projects ):
161
+ return [
162
+ {k : v for k , v in project .items () if k != "tag" } for project in projects
163
+ ]
0 commit comments