Skip to content

Commit a94ca57

Browse files
CopilotEMaher
andauthored
refactor: remove SHORT_TO_OFFICIAL map; derive official cloud name from OFFICIAL_NAME_MAP
getOfficialCloudName() now reverses OFFICIAL_NAME_MAP via Object.entries() instead of maintaining a separate duplicate map. Agent-Logs-Url: https://github.com/Azure/apiops-cli/sessions/a60420c6-8b02-4652-a14e-8c24fbbdf9ca Co-authored-by: EMaher <9244742+EMaher@users.noreply.github.com>
1 parent 1a22c42 commit a94ca57

1 file changed

Lines changed: 6 additions & 16 deletions

File tree

src/lib/cloud-config.ts

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,6 @@ const OFFICIAL_NAME_MAP: Record<OfficialCloudName, CloudName> = {
5151
AzureGermanCloud: 'germany',
5252
};
5353

54-
/** Map canonical short names to official Azure cloud environment names */
55-
const SHORT_TO_OFFICIAL: Record<CloudName, OfficialCloudName> = {
56-
public: 'AzureCloud',
57-
china: 'AzureChinaCloud',
58-
usgov: 'AzureUSGovernment',
59-
germany: 'AzureGermanCloud',
60-
};
61-
6254
/**
6355
* Resolve a cloud name (short or official long form) to its configuration.
6456
* Throws if the name is not recognized.
@@ -90,18 +82,16 @@ export function getCloudConfig(cloudName: string): CloudConfig {
9082
* official name, such as Azure DevOps service connection JSON bodies.
9183
*/
9284
export function getOfficialCloudName(cloudName: string): string {
93-
// Already an official name?
85+
// Already an official name (key in OFFICIAL_NAME_MAP) — return as-is
9486
if (cloudName in OFFICIAL_NAME_MAP) {
9587
return cloudName;
9688
}
97-
// Short name — map to official name
98-
const shortName = cloudName as CloudName;
99-
if (SHORT_TO_OFFICIAL[shortName]) {
100-
return SHORT_TO_OFFICIAL[shortName];
101-
}
102-
// Fall back to validation error via getCloudConfig
89+
// Short name — find the OFFICIAL_NAME_MAP key whose value matches it;
90+
// getCloudConfig validates and throws for unknown names
10391
getCloudConfig(cloudName);
104-
return 'AzureCloud'; // unreachable
92+
const entry = (Object.entries(OFFICIAL_NAME_MAP) as [string, CloudName][])
93+
.find(([, short]) => short === (cloudName as CloudName));
94+
return entry?.[0] ?? 'AzureCloud';
10595
}
10696

10797
/**

0 commit comments

Comments
 (0)