@cloud-copilot/iam-collect 0.1.15 → 0.1.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/README.md +13 -9
  2. package/dist/cjs/persistence/AwsIamStore.d.ts +99 -0
  3. package/dist/cjs/persistence/AwsIamStore.d.ts.map +1 -1
  4. package/dist/cjs/persistence/file/FileSystemAwsIamStore.d.ts +43 -1
  5. package/dist/cjs/persistence/file/FileSystemAwsIamStore.d.ts.map +1 -1
  6. package/dist/cjs/persistence/file/FileSystemAwsIamStore.js +120 -25
  7. package/dist/cjs/persistence/file/FileSystemAwsIamStore.js.map +1 -1
  8. package/dist/cjs/services.d.ts +1 -1
  9. package/dist/cjs/services.d.ts.map +1 -1
  10. package/dist/cjs/services.js +1 -1
  11. package/dist/cjs/services.js.map +1 -1
  12. package/dist/cjs/syncs/organizations/organizations.d.ts +49 -0
  13. package/dist/cjs/syncs/organizations/organizations.d.ts.map +1 -0
  14. package/dist/cjs/syncs/organizations/organizations.js +347 -0
  15. package/dist/cjs/syncs/organizations/organizations.js.map +1 -0
  16. package/dist/cjs/syncs/syncMap.d.ts.map +1 -1
  17. package/dist/cjs/syncs/syncMap.js +8 -1
  18. package/dist/cjs/syncs/syncMap.js.map +1 -1
  19. package/dist/esm/persistence/AwsIamStore.d.ts +99 -0
  20. package/dist/esm/persistence/AwsIamStore.d.ts.map +1 -1
  21. package/dist/esm/persistence/file/FileSystemAwsIamStore.d.ts +43 -1
  22. package/dist/esm/persistence/file/FileSystemAwsIamStore.d.ts.map +1 -1
  23. package/dist/esm/persistence/file/FileSystemAwsIamStore.js +120 -25
  24. package/dist/esm/persistence/file/FileSystemAwsIamStore.js.map +1 -1
  25. package/dist/esm/services.d.ts +1 -1
  26. package/dist/esm/services.d.ts.map +1 -1
  27. package/dist/esm/services.js +1 -1
  28. package/dist/esm/services.js.map +1 -1
  29. package/dist/esm/syncs/organizations/organizations.d.ts +49 -0
  30. package/dist/esm/syncs/organizations/organizations.d.ts.map +1 -0
  31. package/dist/esm/syncs/organizations/organizations.js +339 -0
  32. package/dist/esm/syncs/organizations/organizations.js.map +1 -0
  33. package/dist/esm/syncs/syncMap.d.ts.map +1 -1
  34. package/dist/esm/syncs/syncMap.js +8 -1
  35. package/dist/esm/syncs/syncMap.js.map +1 -1
  36. package/package.json +2 -1
@@ -9,6 +9,30 @@ export class FileSystemAwsIamStore {
9
9
  this.baseFolder = join(baseFolder, 'aws', partition);
10
10
  this.fsAdapter = fsAdapter || new FileSystemAdapter();
11
11
  }
12
+ organizationPath(organizationId) {
13
+ return join(this.baseFolder, 'organizations', organizationId).toLowerCase();
14
+ }
15
+ organizationMetadataPath(organizationId, metadataType) {
16
+ return join(this.organizationPath(organizationId), `${metadataType}.json`).toLowerCase();
17
+ }
18
+ organizationalUnitsPath(organizationId) {
19
+ return join(this.organizationPath(organizationId), 'ous').toLowerCase();
20
+ }
21
+ organizationalUnitPath(organizationId, ouId) {
22
+ return join(this.organizationalUnitsPath(organizationId), ouId).toLowerCase();
23
+ }
24
+ organizationPoliciesPath(organizationId, policyType) {
25
+ return join(this.organizationPath(organizationId), policyType).toLowerCase();
26
+ }
27
+ organizationPolicyPath(organizationId, policyType, policyId) {
28
+ return join(this.organizationPoliciesPath(organizationId, policyType), policyId).toLowerCase();
29
+ }
30
+ organizationPolicyMetadataPath(organizationId, policyType, policyId, metadataType) {
31
+ return join(this.organizationPolicyPath(organizationId, policyType, policyId), `${metadataType}.json`).toLowerCase();
32
+ }
33
+ organizationalUnitMetadataPath(organizationId, ouId, metadataType) {
34
+ return join(this.organizationalUnitPath(organizationId, ouId), `${metadataType}.json`).toLowerCase();
35
+ }
12
36
  accountPath(accountId) {
13
37
  return join(this.baseFolder, 'accounts', accountId).toLowerCase();
14
38
  }
@@ -20,29 +44,13 @@ export class FileSystemAwsIamStore {
20
44
  return join(prefix, `${metadataType}.json`).toLowerCase();
21
45
  }
22
46
  async saveResourceMetadata(accountId, arn, metadataType, data) {
23
- if (typeof data === 'string') {
24
- data = data.trim();
25
- }
26
- if (data === undefined ||
27
- data === null ||
28
- data === '' ||
29
- data === '{}' ||
30
- data === '[]' ||
31
- (Array.isArray(data) && data.length === 0) ||
32
- (typeof data === 'object' && Object.keys(data).length === 0)) {
33
- await this.deleteResourceMetadata(accountId, arn, metadataType);
34
- return;
35
- }
36
- const content = typeof data === 'string' ? data : JSON.stringify(data, null, 2);
37
47
  const filePath = this.buildMetadataPath(accountId, arn, metadataType);
38
- await this.fsAdapter.writeFile(filePath, content);
48
+ await this.saveOrDeleteFile(filePath, data);
39
49
  }
40
50
  async listResourceMetadata(accountId, arn) {
41
51
  // List all files in the resource directory to find metadata types
42
52
  const dirPath = this.buildResourcePath(accountId, arn);
43
- // console.log(dirPath)
44
53
  const files = await this.fsAdapter.listDirectory(dirPath);
45
- // console.log(files)
46
54
  // Filter for files that match the pattern of *.json
47
55
  const metadataTypes = files
48
56
  .filter((file) => file.endsWith('.json'))
@@ -51,11 +59,7 @@ export class FileSystemAwsIamStore {
51
59
  }
52
60
  async getResourceMetadata(accountId, arn, metadataType, defaultValue) {
53
61
  const filePath = this.buildMetadataPath(accountId, arn, metadataType);
54
- const contents = await this.fsAdapter.readFile(filePath);
55
- if (!contents) {
56
- return defaultValue;
57
- }
58
- return JSON.parse(contents);
62
+ return this.contentOrDefault(filePath, defaultValue);
59
63
  }
60
64
  async deleteResourceMetadata(accountId, arn, metadataType) {
61
65
  const filePath = this.buildMetadataPath(accountId, arn, metadataType);
@@ -76,14 +80,105 @@ export class FileSystemAwsIamStore {
76
80
  const resourceDir = this.buildResourcePath(accountId, desiredArn);
77
81
  return resourceDir;
78
82
  }));
79
- // console.log(desiredDirs)
80
83
  // Identify resources that exist in storage but not in desiredResources.
81
84
  const resourcesToDelete = existingSubDirs.filter((s) => !desiredDirs.has(s));
82
85
  for (const resource of resourcesToDelete) {
83
- // const resourceDir = join(dirPath, resource)
84
- // console.log('Deleting resource directory:', resource)
85
86
  await this.fsAdapter.deleteDirectory(resource);
86
87
  }
87
88
  }
89
+ async saveOrganizationMetadata(organizationId, metadataType, data) {
90
+ const filePath = this.organizationMetadataPath(organizationId, metadataType);
91
+ await this.saveOrDeleteFile(filePath, data);
92
+ }
93
+ async deleteOrganizationMetadata(organizationId, metadataType) {
94
+ const filePath = this.organizationMetadataPath(organizationId, metadataType);
95
+ await this.fsAdapter.deleteFile(filePath);
96
+ }
97
+ async listOrganizationalUnits(organizationId) {
98
+ const dirPath = this.organizationalUnitsPath(organizationId);
99
+ return await this.fsAdapter.listDirectory(dirPath);
100
+ }
101
+ async deleteOrganizationalUnitMetadata(organizationId, ouId, metadataType) {
102
+ const filePath = this.organizationalUnitMetadataPath(organizationId, ouId, metadataType);
103
+ await this.fsAdapter.deleteFile(filePath);
104
+ }
105
+ async saveOrganizationalUnitMetadata(organizationId, ouId, metadataType, data) {
106
+ const filePath = this.organizationalUnitMetadataPath(organizationId, ouId, metadataType);
107
+ await this.saveOrDeleteFile(filePath, data);
108
+ }
109
+ async getOrganizationalUnitMetadata(organizationId, ouId, metadataType, defaultValue) {
110
+ const filePath = this.organizationalUnitMetadataPath(organizationId, ouId, metadataType);
111
+ return this.contentOrDefault(filePath, defaultValue);
112
+ }
113
+ async deleteOrganizationalUnit(organizationId, ouId) {
114
+ const dirPath = this.organizationalUnitPath(organizationId, ouId);
115
+ await this.fsAdapter.deleteDirectory(dirPath);
116
+ }
117
+ async deleteOrganizationPolicyMetadata(organizationId, policyType, policyId, metadataType) {
118
+ const filePath = this.organizationPolicyMetadataPath(organizationId, policyType, policyId, metadataType);
119
+ await this.fsAdapter.deleteFile(filePath);
120
+ }
121
+ async saveOrganizationPolicyMetadata(organizationId, policyType, policyId, metadataType, data) {
122
+ const filePath = this.organizationPolicyMetadataPath(organizationId, policyType, policyId, metadataType);
123
+ await this.saveOrDeleteFile(filePath, data);
124
+ }
125
+ async getOrganizationPolicyMetadata(organizationId, policyType, policyId, metadataType, defaultValue) {
126
+ const filePath = this.organizationPolicyMetadataPath(organizationId, policyType, policyId, metadataType);
127
+ return this.contentOrDefault(filePath, defaultValue);
128
+ }
129
+ async deleteOrganizationPolicy(organizationId, policyType, policyId) {
130
+ const dirPath = this.organizationPolicyPath(organizationId, policyType, policyId);
131
+ await this.fsAdapter.deleteDirectory(dirPath);
132
+ }
133
+ async listOrganizationPolicies(organizationId, policyType) {
134
+ const dirPath = this.organizationPoliciesPath(organizationId, policyType);
135
+ return await this.fsAdapter.listDirectory(dirPath);
136
+ }
137
+ /**
138
+ * Checks if a given content value is empty.
139
+ *
140
+ * @param content The content to check.
141
+ * @returns true if the content is empty, false otherwise.
142
+ */
143
+ isEmptyContent(content) {
144
+ return (content === undefined ||
145
+ content === null ||
146
+ content === '' ||
147
+ content === '{}' ||
148
+ content === '[]' ||
149
+ (Array.isArray(content) && content.length === 0) ||
150
+ (typeof content === 'object' && Object.keys(content).length === 0));
151
+ }
152
+ /**
153
+ * Read the content of a file or return a default value if the file does not exist.
154
+ *
155
+ * @param filePath the path to the file
156
+ * @param defaultValue the default value to return if the file does not exist
157
+ * @returns the content of the file or the default value
158
+ */
159
+ async contentOrDefault(filePath, defaultValue) {
160
+ const contents = await this.fsAdapter.readFile(filePath);
161
+ if (!contents) {
162
+ return defaultValue;
163
+ }
164
+ return JSON.parse(contents);
165
+ }
166
+ /**
167
+ * Either saves the provided data to a file or deletes the file if the data is empty.
168
+ *
169
+ * @param filePath the path to the file
170
+ * @param data the data to save in the file
171
+ */
172
+ async saveOrDeleteFile(filePath, data) {
173
+ if (typeof data === 'string') {
174
+ data = data.trim();
175
+ }
176
+ if (this.isEmptyContent(data)) {
177
+ await this.fsAdapter.deleteFile(filePath);
178
+ return;
179
+ }
180
+ const content = typeof data === 'string' ? data : JSON.stringify(data, null, 2);
181
+ await this.fsAdapter.writeFile(filePath, content);
182
+ }
88
183
  }
89
184
  //# sourceMappingURL=FileSystemAwsIamStore.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"File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;YACd,OAAO,YAAiB,CAAA;QAC1B,CAAC;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAM,CAAA;IAClC,CAAC;IAED;;;;;OAKG;IACK,KAAK,CAAC,gBAAgB,CAAC,QAAgB,EAAE,IAAS;QACxD,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC7B,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,CAAA;QACpB,CAAC;QACD,IAAI,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC;YAC9B,MAAM,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAA;YACzC,OAAM;QACR,CAAC;QAED,MAAM,OAAO,GAAG,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;QAC/E,MAAM,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;IACnD,CAAC;CACF"}
@@ -1,3 +1,3 @@
1
- export type AwsService = 'iam' | 'kms' | 'lambda' | 's3';
1
+ export type AwsService = 'iam' | 'kms' | 'lambda' | 'organizations' | 's3';
2
2
  export declare const allServices: AwsService[];
3
3
  //# sourceMappingURL=services.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"services.d.ts","sourceRoot":"","sources":["../../src/services.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,KAAK,GAAG,QAAQ,GAAG,IAAI,CAAA;AAExD,eAAO,MAAM,WAAW,EAAE,UAAU,EAAmC,CAAA"}
1
+ {"version":3,"file":"services.d.ts","sourceRoot":"","sources":["../../src/services.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,KAAK,GAAG,QAAQ,GAAG,eAAe,GAAG,IAAI,CAAA;AAE1E,eAAO,MAAM,WAAW,EAAE,UAAU,EAAoD,CAAA"}
@@ -1,2 +1,2 @@
1
- export const allServices = ['iam', 'kms', 'lambda', 's3'];
1
+ export const allServices = ['iam', 'kms', 'lambda', 'organizations', 's3'];
2
2
  //# sourceMappingURL=services.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"services.js","sourceRoot":"","sources":["../../src/services.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,WAAW,GAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAA"}
1
+ {"version":3,"file":"services.js","sourceRoot":"","sources":["../../src/services.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,WAAW,GAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,IAAI,CAAC,CAAA"}
@@ -0,0 +1,49 @@
1
+ import { Account, Organization, OrganizationalUnit, OrganizationsClient, Root } from '@aws-sdk/client-organizations';
2
+ import { Sync } from '../sync.js';
3
+ export declare const OrganizationSync: Sync;
4
+ /**
5
+ * Get the details of an organization or an account.
6
+ *
7
+ * @param client The OrganizationsClient to use
8
+ * @returns the details of the organization the account belongs to or undefined if the account is not part of an organization or does not have permission.
9
+ */
10
+ export declare function getOrganizationDetails(client: OrganizationsClient): Promise<Organization | undefined>;
11
+ /**
12
+ * Get the root Organizational Unit for an organization
13
+ *
14
+ * @param client The OrganizationsClient to use
15
+ * @returns the root Organizational Unit for the organization if it exists
16
+ */
17
+ export declare function getOrganizationRoot(client: OrganizationsClient): Promise<Root | undefined>;
18
+ /**
19
+ * Get the tags for an Organizational Unit
20
+ *
21
+ * @param client The OrganizationsClient to use
22
+ * @param ouId The AWS id of the Organizational Unit to get the tags for
23
+ * @returns The tags for the Organizational Unit
24
+ */
25
+ export declare function getTagsForOu(client: OrganizationsClient, ouId: string): Promise<Record<string, string>>;
26
+ /**
27
+ * Get the tags for an account
28
+ * @param client The OrganizationsClient to use
29
+ * @param accountId The AWS id of the account to get the tags for
30
+ * @returns The tags for the account
31
+ */
32
+ export declare function getTagsForAccount(client: OrganizationsClient, accountId: string): Promise<Record<string, string>>;
33
+ /**
34
+ * Get the organizational units for a parent organizational unit
35
+ *
36
+ * @param client The OrganizationsClient to use
37
+ * @param parentId The AWS id of the parent organizational unit
38
+ * @returns The organizational units directly under the parent
39
+ */
40
+ export declare function getChildOrgUnits(client: OrganizationsClient, parentId: string): Promise<OrganizationalUnit[]>;
41
+ /**
42
+ * Get the accounts for a parent organizational unit
43
+ *
44
+ * @param client The OrganizationsClient to use
45
+ * @param parentId The AWS id of the parent organizational unit
46
+ * @returns The accounts directly under the parent
47
+ */
48
+ export declare function getAccountsForParent(client: OrganizationsClient, parentId: string): Promise<Account[]>;
49
+ //# sourceMappingURL=organizations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"organizations.d.ts","sourceRoot":"","sources":["../../../../src/syncs/organizations/organizations.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EAUP,YAAY,EACZ,kBAAkB,EAClB,mBAAmB,EAGnB,IAAI,EACL,MAAM,+BAA+B,CAAA;AAKtC,OAAO,EAAE,IAAI,EAAe,MAAM,YAAY,CAAA;AA+B9C,eAAO,MAAM,gBAAgB,EAAE,IAmM9B,CAAA;AAED;;;;;GAKG;AACH,wBAAsB,sBAAsB,CAC1C,MAAM,EAAE,mBAAmB,GAC1B,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC,CAenC;AAED;;;;;GAKG;AACH,wBAAsB,mBAAmB,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,GAAG,SAAS,CAAC,CAchG;AAED;;;;;;GAMG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,mBAAmB,EAC3B,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAEjC;AAED;;;;;GAKG;AACH,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,mBAAmB,EAC3B,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAEjC;AA4BD;;;;;;GAMG;AACH,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,mBAAmB,EAC3B,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAQ/B;AAED;;;;;;GAMG;AACH,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,mBAAmB,EAC3B,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,OAAO,EAAE,CAAC,CAYpB"}
@@ -0,0 +1,339 @@
1
+ import { DescribeOrganizationCommand, DescribePolicyCommand, DescribeResourcePolicyCommand, ListAccountsForParentCommand, ListOrganizationalUnitsForParentCommand, ListPoliciesCommand, ListPoliciesForTargetCommand, ListRootsCommand, ListTagsForResourceCommand, OrganizationsClient, PolicyType, PolicyTypeStatus } from '@aws-sdk/client-organizations';
2
+ import { AwsClientPool } from '../../aws/ClientPool.js';
3
+ import { runAndCatch404, runAndCatchAccessDenied } from '../../utils/client-tools.js';
4
+ import { paginateResource } from '../typedSync.js';
5
+ export const OrganizationSync = {
6
+ awsService: 'organizations',
7
+ name: 'organization',
8
+ global: true,
9
+ execute: async function (accountId, region, credentials, storage, endpoint, syncOptions) {
10
+ var _a;
11
+ const organizationClient = AwsClientPool.defaultInstance.client(OrganizationsClient, credentials, region, endpoint);
12
+ const organization = await getOrganizationDetails(organizationClient);
13
+ if (!organization) {
14
+ return;
15
+ }
16
+ const organizationId = organization.Id;
17
+ const root = await getOrganizationRoot(organizationClient);
18
+ if (!root) {
19
+ return;
20
+ }
21
+ const features = root.PolicyTypes?.reduce((acc, type) => {
22
+ acc[type.Type] = type.Status === PolicyTypeStatus.ENABLED;
23
+ return acc;
24
+ }, {}) || {};
25
+ const scpsEnabled = !!features[PolicyType.SERVICE_CONTROL_POLICY];
26
+ const rcpsEnabled = !!features[PolicyType.RESOURCE_CONTROL_POLICY];
27
+ const allAccounts = {};
28
+ const allOus = {};
29
+ const ouDetails = {};
30
+ allOus[root.Id] = {
31
+ parent: undefined,
32
+ scps: await getPoliciesForTarget(organizationClient, root.Id, PolicyType.SERVICE_CONTROL_POLICY, scpsEnabled),
33
+ rcps: await getPoliciesForTarget(organizationClient, root.Id, PolicyType.RESOURCE_CONTROL_POLICY, rcpsEnabled)
34
+ };
35
+ ouDetails[root.Id] = await getOuDetails(organizationClient, root);
36
+ const structure = {
37
+ [root.Id]: {
38
+ children: {},
39
+ accounts: []
40
+ }
41
+ };
42
+ // const children = await getChildOrgUnits(organizationClient, root.Id!)
43
+ const parents = [structure];
44
+ let parent = parents.pop();
45
+ while (parent) {
46
+ for (const key in parent) {
47
+ // Get structure information
48
+ const children = await getChildOrgUnits(organizationClient, key);
49
+ for (const child of children) {
50
+ ouDetails[child.Id] = await getOuDetails(organizationClient, child);
51
+ const childId = child.Id;
52
+ allOus[childId] = {
53
+ parent: key,
54
+ scps: await getPoliciesForTarget(organizationClient, root.Id, PolicyType.SERVICE_CONTROL_POLICY, scpsEnabled),
55
+ rcps: await getPoliciesForTarget(organizationClient, root.Id, PolicyType.RESOURCE_CONTROL_POLICY, rcpsEnabled)
56
+ };
57
+ (_a = parent[key]).children || (_a.children = {});
58
+ parent[key].children[childId] = {
59
+ children: undefined,
60
+ accounts: undefined
61
+ };
62
+ }
63
+ const accounts = await getAccountsForParent(organizationClient, key);
64
+ if (accounts.length > 0) {
65
+ parent[key].accounts = [];
66
+ }
67
+ for (const account of accounts) {
68
+ let accountTags = await getTagsForAccount(organizationClient, account.Id);
69
+ if (Object.keys(accountTags).length === 0) {
70
+ accountTags = undefined;
71
+ }
72
+ allAccounts[account.Id] = {
73
+ ou: key,
74
+ scps: await getPoliciesForTarget(organizationClient, account.Id, PolicyType.SERVICE_CONTROL_POLICY, scpsEnabled),
75
+ rcps: await getPoliciesForTarget(organizationClient, account.Id, PolicyType.RESOURCE_CONTROL_POLICY, rcpsEnabled),
76
+ tags: accountTags
77
+ };
78
+ parent[key].accounts.push(account.Arn);
79
+ }
80
+ // parent[key].accounts = accounts.map((a) => a.Arn!)
81
+ if (parent[key].children) {
82
+ parents.push(parent[key].children);
83
+ }
84
+ }
85
+ parent = parents.pop();
86
+ }
87
+ storage.saveOrganizationMetadata(organizationId, 'structure', structure);
88
+ storage.saveOrganizationMetadata(organizationId, 'metadata', {
89
+ id: organizationId,
90
+ arn: organization.Arn,
91
+ rootOu: root.Id,
92
+ rootAccountArn: organization.MasterAccountArn,
93
+ rootAccountId: organization.MasterAccountId,
94
+ features
95
+ });
96
+ storage.saveOrganizationMetadata(organizationId, 'accounts', allAccounts);
97
+ storage.saveOrganizationMetadata(organizationId, 'ous', allOus);
98
+ // Sync OUs
99
+ const persistedOus = await storage.listOrganizationalUnits(organizationId);
100
+ const newOus = new Set(Object.keys(ouDetails));
101
+ const deletedOus = persistedOus.filter((ou) => !newOus.has(ou));
102
+ for (const ouToDelete of deletedOus) {
103
+ await storage.deleteOrganizationalUnit(organizationId, ouToDelete);
104
+ }
105
+ for (const ouId of Object.keys(ouDetails)) {
106
+ const ou = ouDetails[ouId];
107
+ await storage.saveOrganizationalUnitMetadata(organizationId, ouId, 'metadata', ou.metadata);
108
+ await storage.saveOrganizationalUnitMetadata(organizationId, ouId, 'tags', ou.tags);
109
+ }
110
+ // Sync policies
111
+ await syncPolicies(organizationId, organizationClient, storage, PolicyType.SERVICE_CONTROL_POLICY, 'scps', scpsEnabled);
112
+ await syncPolicies(organizationId, organizationClient, storage, PolicyType.RESOURCE_CONTROL_POLICY, 'rcps', rcpsEnabled);
113
+ // Sync organization resource policy
114
+ await syncOrganizationResourcePolicy(organizationClient, storage, organizationId);
115
+ }
116
+ };
117
+ /**
118
+ * Get the details of an organization or an account.
119
+ *
120
+ * @param client The OrganizationsClient to use
121
+ * @returns the details of the organization the account belongs to or undefined if the account is not part of an organization or does not have permission.
122
+ */
123
+ export async function getOrganizationDetails(client) {
124
+ const command = new DescribeOrganizationCommand();
125
+ try {
126
+ const response = await runAndCatch404(() => client.send(command));
127
+ if (!response) {
128
+ return undefined;
129
+ }
130
+ return response.Organization;
131
+ }
132
+ catch (e) {
133
+ if (e.name === 'AWSOrganizationsNotInUseException') {
134
+ return undefined;
135
+ }
136
+ }
137
+ return undefined;
138
+ }
139
+ /**
140
+ * Get the root Organizational Unit for an organization
141
+ *
142
+ * @param client The OrganizationsClient to use
143
+ * @returns the root Organizational Unit for the organization if it exists
144
+ */
145
+ export async function getOrganizationRoot(client) {
146
+ return runAndCatchAccessDenied(async () => {
147
+ const roots = await paginateResource(client, ListRootsCommand, 'Roots', {
148
+ inputKey: 'NextToken',
149
+ outputKey: 'NextToken'
150
+ }, {});
151
+ return roots.at(0);
152
+ });
153
+ }
154
+ /**
155
+ * Get the tags for an Organizational Unit
156
+ *
157
+ * @param client The OrganizationsClient to use
158
+ * @param ouId The AWS id of the Organizational Unit to get the tags for
159
+ * @returns The tags for the Organizational Unit
160
+ */
161
+ export async function getTagsForOu(client, ouId) {
162
+ return getTags(client, ouId);
163
+ }
164
+ /**
165
+ * Get the tags for an account
166
+ * @param client The OrganizationsClient to use
167
+ * @param accountId The AWS id of the account to get the tags for
168
+ * @returns The tags for the account
169
+ */
170
+ export async function getTagsForAccount(client, accountId) {
171
+ return getTags(client, accountId);
172
+ }
173
+ /**
174
+ * Get the tags for a resource in AWS Organizations
175
+ *
176
+ * @param client The OrganizationsClient to use
177
+ * @param resourceId The AWS id of the resource to get the tags for
178
+ * @returns The tags for the resource
179
+ */
180
+ async function getTags(client, resourceId) {
181
+ const command = new ListTagsForResourceCommand({ ResourceId: resourceId });
182
+ const response = await runAndCatch404(() => client.send(command));
183
+ if (!response) {
184
+ return {};
185
+ }
186
+ return (response.Tags || [])?.reduce((acc, tag) => {
187
+ acc[tag.Key] = tag.Value;
188
+ return acc;
189
+ }, {});
190
+ }
191
+ /**
192
+ * Get the organizational units for a parent organizational unit
193
+ *
194
+ * @param client The OrganizationsClient to use
195
+ * @param parentId The AWS id of the parent organizational unit
196
+ * @returns The organizational units directly under the parent
197
+ */
198
+ export async function getChildOrgUnits(client, parentId) {
199
+ return await paginateResource(client, ListOrganizationalUnitsForParentCommand, 'OrganizationalUnits', { inputKey: 'NextToken', outputKey: 'NextToken' }, { ParentId: parentId });
200
+ }
201
+ /**
202
+ * Get the accounts for a parent organizational unit
203
+ *
204
+ * @param client The OrganizationsClient to use
205
+ * @param parentId The AWS id of the parent organizational unit
206
+ * @returns The accounts directly under the parent
207
+ */
208
+ export async function getAccountsForParent(client, parentId) {
209
+ const accounts = await paginateResource(client, ListAccountsForParentCommand, 'Accounts', {
210
+ inputKey: 'NextToken',
211
+ outputKey: 'NextToken'
212
+ }, { ParentId: parentId });
213
+ return accounts;
214
+ }
215
+ /**
216
+ * Get the details of an Organizational Unit (OU).
217
+ *
218
+ * @param organizationClient the OrganizationsClient to use
219
+ * @param ou the Organizational Unit to get the details for
220
+ * @returns an object containing the OU's tags and metadata
221
+ */
222
+ async function getOuDetails(organizationClient, ou) {
223
+ return {
224
+ tags: await getTagsForOu(organizationClient, ou.Id),
225
+ metadata: {
226
+ arn: ou.Arn,
227
+ name: ou.Name
228
+ }
229
+ };
230
+ }
231
+ /**
232
+ * Get the policies for a target
233
+ *
234
+ * @param client the OrganizationsClient to use
235
+ * @param targetId the id of the target to get the policies for
236
+ * @param policyType the type of policy to get
237
+ * @param enabled whether the policy type is enabled
238
+ * @returns the Arns of the policies for the target
239
+ */
240
+ async function getPoliciesForTarget(client, targetId, policyType, enabled) {
241
+ if (!enabled) {
242
+ return [];
243
+ }
244
+ const policies = await paginateResource(client, ListPoliciesForTargetCommand, 'Policies', { inputKey: 'NextToken', outputKey: 'NextToken' }, {
245
+ TargetId: targetId,
246
+ Filter: policyType
247
+ });
248
+ return policies.map((policy) => policy.Arn);
249
+ }
250
+ /**
251
+ * Sync the policies for an organization and a specific policy type.
252
+ *
253
+ * @param organizationId the id of the organization to sync policies for
254
+ * @param organizationClient the OrganizationsClient to use
255
+ * @param storage the AwsIamStore to use for persistence
256
+ * @param policyType the type of policy to sync (e.g., SERVICE_CONTROL_POLICY, RESOURCE_CONTROL_POLICY)
257
+ * @param fileType the type of policy file to sync to storage (e.g., 'scps', 'rcps')
258
+ * @param enabled whether the policy type is enabled in the organization
259
+ */
260
+ async function syncPolicies(organizationId, organizationClient, storage, policyType, fileType, enabled) {
261
+ const existingPolicies = await storage.listOrganizationPolicies(organizationId, fileType);
262
+ if (!enabled) {
263
+ for (const policyId of existingPolicies) {
264
+ await storage.deleteOrganizationPolicy(organizationId, fileType, policyId);
265
+ }
266
+ return;
267
+ }
268
+ const policies = await paginateResource(organizationClient, ListPoliciesCommand, 'Policies', { inputKey: 'NextToken', outputKey: 'NextToken' }, {
269
+ Filter: policyType
270
+ });
271
+ const newPolicyIds = new Set(policies.map((p) => p.Id));
272
+ const policiesToDelete = existingPolicies.filter((id) => !newPolicyIds.has(id));
273
+ for (const policyToDelete of policiesToDelete) {
274
+ await storage.deleteOrganizationPolicy(organizationId, fileType, policyToDelete);
275
+ }
276
+ for (const policy of policies) {
277
+ const metadata = {
278
+ arn: policy.Arn,
279
+ name: policy.Name,
280
+ description: policy.Description,
281
+ awsManaged: policy.AwsManaged
282
+ };
283
+ await storage.saveOrganizationPolicyMetadata(organizationId, fileType, policy.Id, 'metadata', metadata);
284
+ const content = await getPolicyContent(organizationClient, policy.Id);
285
+ await storage.saveOrganizationPolicyMetadata(organizationId, fileType, policy.Id, 'policy', content);
286
+ const tags = await getTags(organizationClient, policy.Id);
287
+ await storage.saveOrganizationPolicyMetadata(organizationId, fileType, policy.Id, 'tags', tags);
288
+ }
289
+ }
290
+ /**
291
+ * Get the content of a policy by its ID.
292
+ *
293
+ * @param organizationClient the OrganizationsClient to use
294
+ * @param policyId the ID of the policy to get the content for
295
+ * @returns the content of the policy as a parsed JSON object, or undefined if the policy does not exist or has no content
296
+ */
297
+ async function getPolicyContent(organizationClient, policyId) {
298
+ const command = new DescribePolicyCommand({ PolicyId: policyId });
299
+ const response = await runAndCatch404(() => organizationClient.send(command));
300
+ if (response?.Policy?.Content) {
301
+ return JSON.parse(response.Policy.Content);
302
+ }
303
+ return undefined;
304
+ }
305
+ /**
306
+ * Sync the organization resource policy.
307
+ *
308
+ * @param organizationClient the OrganizationsClient to use
309
+ * @param storage the AwsIamStore to use for persistence
310
+ * @param organizationId the id of the organization to sync the resource policy for
311
+ */
312
+ async function syncOrganizationResourcePolicy(organizationClient, storage, organizationId) {
313
+ const policy = await getOrganizationResourcePolicy(organizationClient, organizationId);
314
+ await storage.saveOrganizationMetadata(organizationId, 'policy', policy);
315
+ }
316
+ /**
317
+ * Get the resource policy for an organization.
318
+ *
319
+ * @param organizationClient the OrganizationsClient to use
320
+ * @param organizationId the id of the organization to get the resource policy for
321
+ * @returns the resource policy as a parsed JSON object, or undefined if the policy does not exist or has no content
322
+ */
323
+ async function getOrganizationResourcePolicy(organizationClient, organizationId) {
324
+ const command = new DescribeResourcePolicyCommand({ PolicyId: organizationId });
325
+ try {
326
+ const response = await organizationClient.send(command);
327
+ if (response?.ResourcePolicy?.Content) {
328
+ return JSON.parse(response.ResourcePolicy.Content);
329
+ }
330
+ return undefined;
331
+ }
332
+ catch (error) {
333
+ if (error.name === 'ResourcePolicyNotFoundException') {
334
+ return undefined;
335
+ }
336
+ throw error;
337
+ }
338
+ }
339
+ //# sourceMappingURL=organizations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"organizations.js","sourceRoot":"","sources":["../../../../src/syncs/organizations/organizations.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,2BAA2B,EAC3B,qBAAqB,EACrB,6BAA6B,EAC7B,4BAA4B,EAC5B,uCAAuC,EACvC,mBAAmB,EACnB,4BAA4B,EAC5B,gBAAgB,EAChB,0BAA0B,EAG1B,mBAAmB,EACnB,UAAU,EACV,gBAAgB,EAEjB,MAAM,+BAA+B,CAAA;AAEtC,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CA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