5
5
import cloud .stackit .sdk .resourcemanager .model .CreateFolderPayload ;
6
6
import cloud .stackit .sdk .resourcemanager .model .CreateProjectPayload ;
7
7
import cloud .stackit .sdk .resourcemanager .model .FolderResponse ;
8
+ import cloud .stackit .sdk .resourcemanager .model .ListFoldersResponse ;
9
+ import cloud .stackit .sdk .resourcemanager .model .ListProjectsResponse ;
10
+ import cloud .stackit .sdk .resourcemanager .model .Member ;
11
+ import cloud .stackit .sdk .resourcemanager .model .OrganizationResponse ;
12
+ import cloud .stackit .sdk .resourcemanager .model .PartialUpdateFolderPayload ;
13
+ import cloud .stackit .sdk .resourcemanager .model .PartialUpdateProjectPayload ;
8
14
import cloud .stackit .sdk .resourcemanager .model .Project ;
9
15
import java .io .IOException ;
16
+ import java .util .Arrays ;
10
17
import java .util .Collections ;
11
18
import java .util .UUID ;
12
19
@@ -16,23 +23,88 @@ public static void main(String[] args) throws IOException {
16
23
// STACKIT_SERVICE_ACCOUNT_KEY_PATH / STACKIT_SERVICE_ACCOUNT_KEY
17
24
ResourceManagerApi resourceManagerApi = new ResourceManagerApi ();
18
25
19
- // replace this with something useful for real use
20
- UUID containerParentId = UUID .randomUUID ();
26
+ // Read the organization id and the member subject from the environment
27
+ String organizationIdString = System .getenv ("STACKIT_ORGANIZATION_ID" );
28
+ String memberSubjectString = System .getenv ("STACKIT_MEMBER_SUBJECT" );
29
+ if (organizationIdString == null || organizationIdString .isEmpty ()) {
30
+ System .err .println ("Environment variable 'STACKIT_ORGANIZATION_ID' not found." );
31
+ return ;
32
+ }
33
+ if (memberSubjectString == null || memberSubjectString .isEmpty ()) {
34
+ System .err .println ("Environment variable 'STACKIT_MEMBER_SUBJECT' not found." );
35
+ return ;
36
+ }
37
+ UUID containerParentId = UUID .fromString (organizationIdString );
38
+
39
+ Member member =
40
+ new Member ()
41
+ .role ("project.owner" )
42
+ .subject (memberSubjectString ); // replace with an existing subject
21
43
22
44
try {
23
45
/* create a project */
24
46
Project project =
25
47
resourceManagerApi .createProject (
26
48
new CreateProjectPayload ()
27
49
.containerParentId (containerParentId .toString ())
50
+ .name ("java-test-project" )
51
+ .addMembersItem (member )
28
52
.labels (Collections .singletonMap ("foo" , "bar" )));
53
+ System .out .println ("Project:\n " + project .toString ());
54
+
55
+ /* list projects */
56
+ ListProjectsResponse responseListProject =
57
+ resourceManagerApi .listProjects (
58
+ organizationIdString , null , null , null , null , null );
59
+ System .out .println ("Project List:\n " + responseListProject .toString ());
29
60
30
61
/* create a folder */
31
62
FolderResponse folder =
32
63
resourceManagerApi .createFolder (
33
64
new CreateFolderPayload ()
34
65
.containerParentId (containerParentId .toString ())
66
+ .name ("java-testing-folder" )
35
67
.labels (Collections .singletonMap ("foo" , "bar" )));
68
+ System .out .println ("Folder: \n " + folder .toString ());
69
+
70
+ /* list folders */
71
+ ListFoldersResponse responseListFolders =
72
+ resourceManagerApi .listFolders (
73
+ organizationIdString , null , null , null , null , null );
74
+ System .out .println ("Folder List:\n " + responseListFolders .toString ());
75
+
76
+ /* delete a project label */
77
+ resourceManagerApi .deleteProjectLabels (project .getContainerId (), Arrays .asList ("foo" ));
78
+
79
+ /* delete a folder label */
80
+ resourceManagerApi .deleteFolderLabels (folder .getContainerId (), Arrays .asList ("foo" ));
81
+
82
+ /* update folder labels */
83
+ resourceManagerApi .partialUpdateFolder (
84
+ folder .getContainerId (),
85
+ new PartialUpdateFolderPayload ()
86
+ .labels (Collections .singletonMap ("foo2" , "bar2" )));
87
+
88
+ /* update project move to created folder */
89
+ resourceManagerApi .partialUpdateProject (
90
+ project .getContainerId (),
91
+ new PartialUpdateProjectPayload ().containerParentId (folder .getContainerId ()));
92
+
93
+ /* get organization details */
94
+ OrganizationResponse organizationResponse =
95
+ resourceManagerApi .getOrganization (organizationIdString );
96
+ System .out .println ("Organization List:\n " + organizationResponse .toString ());
97
+
98
+ /* since you cannot delete a folder when a project is present we need to move the project out again */
99
+ resourceManagerApi .partialUpdateProject (
100
+ project .getContainerId (),
101
+ new PartialUpdateProjectPayload ().containerParentId (organizationIdString ));
102
+
103
+ /* delete project */
104
+ resourceManagerApi .deleteProject (project .getContainerId ());
105
+
106
+ /* delete folder */
107
+ resourceManagerApi .deleteFolder (folder .getContainerId (), true );
36
108
} catch (ApiException e ) {
37
109
throw new RuntimeException (e );
38
110
}
0 commit comments