Skip to content

Commit 5fb3428

Browse files
authored
add tags to clone and update (#400)
* add tags to clone and update * buid fix * Update common.py * change "Tag" to "Environment", and "Custom Tags" to "Tags" * add list projects * change set tags to update tags * revert unnecessary changes * fix diff * fix diff space * Revert "fix diff space" This reverts commit 1ea141f. * fix diff space * fix prehook * Update requirements.txt * Update requirements.txt
1 parent cdc1581 commit 5fb3428

File tree

5 files changed

+338
-185
lines changed

5 files changed

+338
-185
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -1281,6 +1281,9 @@ create a new one.
12811281
# Change the project name
12821282
descope_client.mgmt.project.change_name("new-project-name")
12831283

1284+
# Change project's tags
1285+
descope_client.mgmt.project.update_tags(["new", "python"])
1286+
12841287
# Clone the current project, including its settings and configurations.
12851288
# Note that this action is supported only with a pro license or above.
12861289
# Users, tenants and access keys are not cloned.

descope/management/common.py

+2
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,11 @@ class MgmtV1:
131131

132132
# Project
133133
project_update_name = "/v1/mgmt/project/update/name"
134+
project_update_tags = "/v1/mgmt/project/update/tags"
134135
project_clone = "/v1/mgmt/project/clone"
135136
project_export = "/v1/mgmt/project/export"
136137
project_import = "/v1/mgmt/project/import"
138+
project_list_projects = "/v1/mgmt/projects/list"
137139

138140

139141
class AssociatedTenant:

descope/management/project.py

+64-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Optional
1+
from typing import List, Optional
22

33
from descope._auth_base import AuthBase
44
from descope.management.common import MgmtV1
@@ -25,10 +25,60 @@ def update_name(
2525
pswd=self._auth.management_key,
2626
)
2727

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+
2877
def clone(
2978
self,
3079
name: str,
31-
tag: Optional[str] = None,
80+
environment: Optional[str] = None,
81+
tags: Optional[List[str]] = None,
3282
):
3383
"""
3484
Clone the current project, including its settings and configurations.
@@ -37,10 +87,11 @@ def clone(
3787
3888
Args:
3989
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.
4192
4293
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).
4495
4596
Raise:
4697
AuthException: raised if clone operation fails
@@ -49,7 +100,8 @@ def clone(
49100
MgmtV1.project_clone,
50101
{
51102
"name": name,
52-
"tag": tag,
103+
"environment": environment,
104+
"tags": tags,
53105
},
54106
pswd=self._auth.management_key,
55107
)
@@ -95,11 +147,17 @@ def import_project(
95147
Raise:
96148
AuthException: raised if import operation fails
97149
"""
98-
response = self._auth.do_post(
150+
self._auth.do_post(
99151
MgmtV1.project_import,
100152
{
101153
"files": files,
102154
},
103155
pswd=self._auth.management_key,
104156
)
105157
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

Comments
 (0)