-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add tag support * Add tag support * Add tag support * Review changes/suggestions * Add credentials * Add chunking to tag fetching * Update rate limiter * Remove imports * Remove imports * Fix tag fetching * Changeset * Changeset
- Loading branch information
1 parent
a9ae20c
commit 0b1e46c
Showing
18 changed files
with
691 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@mirohq/cloud-data-import': minor | ||
--- | ||
|
||
Add tag support |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,42 @@ | ||
import type {ProcessedData, Resources} from '@/types' | ||
import type {ProcessedData, Resources, ResourceTags} from '@/types' | ||
|
||
import {getPlacementData} from './getPlacementData' | ||
import {getProcessedResources} from './resources' | ||
import {getProcessedContainers} from './containers' | ||
import {ProcessingErrorManager} from './utils/ProcessingErrorManager' | ||
|
||
export const getProcessedData = (resources: Resources): ProcessedData => { | ||
export const getProcessedData = (resources: Resources, resourceTags: ResourceTags): ProcessedData => { | ||
const processingErrorsManager = new ProcessingErrorManager() | ||
|
||
// Get the placement data which is a simplified version of the resources focusing on the location of the resources | ||
const placementData = getPlacementData(resources) | ||
|
||
// Calculate the containers, connections and resources | ||
const processedResources = getProcessedResources(placementData) | ||
const processedResources = getProcessedResources(placementData, resourceTags) | ||
const containers = getProcessedContainers(placementData, resources, processingErrorsManager) | ||
|
||
// Log all collected errors | ||
processingErrorsManager.render() | ||
|
||
// Tag values | ||
let possibleTagValues: {[key: string]: string[]} = {} | ||
for (const [_arn, tags] of Object.entries(resourceTags)) { | ||
for (const [key, value] of Object.entries(tags)) { | ||
if (!possibleTagValues[key]) { | ||
possibleTagValues[key] = [] | ||
} | ||
|
||
if (value && !possibleTagValues[key].includes(value)) { | ||
possibleTagValues[key].push(value) | ||
} | ||
} | ||
} | ||
|
||
// Return the processed data | ||
return { | ||
resources: processedResources, | ||
connections: [], | ||
containers, | ||
tags: possibleTagValues, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import {Credentials, RateLimiter, ResourceTags} from '@/types' | ||
import {GetResourcesCommand, ResourceGroupsTaggingAPIClient} from '@aws-sdk/client-resource-groups-tagging-api' | ||
|
||
export const fetchTags = async (credentials: Credentials, rateLimiter: RateLimiter): Promise<ResourceTags> => { | ||
const client = new ResourceGroupsTaggingAPIClient({credentials}) | ||
const tagResult: Record<string, Record<string, string | undefined>> = {} | ||
|
||
try { | ||
let paginationToken: string | undefined = undefined | ||
|
||
do { | ||
const command: GetResourcesCommand = new GetResourcesCommand({ | ||
PaginationToken: paginationToken, | ||
}) | ||
|
||
const response = await rateLimiter.throttle(() => client.send(command)) | ||
paginationToken = response.PaginationToken | ||
|
||
for (const resourceData of response.ResourceTagMappingList ?? []) { | ||
for (const tagData of resourceData.Tags ?? []) { | ||
if (!resourceData.ResourceARN || !tagData.Key) { | ||
continue | ||
} | ||
|
||
if (!tagResult[resourceData.ResourceARN]) { | ||
tagResult[resourceData.ResourceARN] = {} | ||
} | ||
|
||
tagResult[resourceData.ResourceARN][tagData.Key] = tagData.Value | ||
} | ||
} | ||
} while (paginationToken) | ||
} catch (error) { | ||
console.error('Error fetching tag resources:', error) | ||
} | ||
|
||
return tagResult | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.