@aws-amplify/cli-internal
Version:
Amplify CLI
81 lines • 4.27 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.StackFacade = void 0;
const client_cloudformation_1 = require("@aws-sdk/client-cloudformation");
const client_cognito_identity_provider_1 = require("@aws-sdk/client-cognito-identity-provider");
const amplify_cli_core_1 = require("@aws-amplify/amplify-cli-core");
class StackFacade {
constructor(clients, rootStackName) {
this.clients = clients;
this.rootStackName = rootStackName;
}
async fetchNestedStacks() {
var _a;
const results = [];
const paginator = (0, client_cloudformation_1.paginateListStackResources)({ client: this.clients.cloudFormation }, { StackName: this.rootStackName });
for await (const page of paginator) {
for (const resource of (_a = page.StackResourceSummaries) !== null && _a !== void 0 ? _a : []) {
if (resource.ResourceType === 'AWS::CloudFormation::Stack') {
results.push(resource);
}
}
}
return results;
}
async fetchTemplate(stackId) {
const response = await this.clients.cloudFormation.send(new client_cloudformation_1.GetTemplateCommand({ StackName: stackId, TemplateStage: 'Original' }));
if (!response.TemplateBody) {
throw new amplify_cli_core_1.AmplifyError('InvalidStackError', { message: `Stack '${stackId}' returned an empty template` });
}
return JSON.parse(response.TemplateBody);
}
async fetchStack(stackId) {
var _a;
const response = await this.clients.cloudFormation.send(new client_cloudformation_1.DescribeStacksCommand({ StackName: stackId }));
const stack = (_a = response.Stacks) === null || _a === void 0 ? void 0 : _a[0];
if (!stack) {
throw new amplify_cli_core_1.AmplifyError('StackNotFoundError', { message: `Stack '${stackId}' not found` });
}
return stack;
}
async fetchStackResources(stackId) {
var _a;
const results = [];
const paginator = (0, client_cloudformation_1.paginateListStackResources)({ client: this.clients.cloudFormation }, { StackName: stackId });
for await (const page of paginator) {
results.push(...((_a = page.StackResourceSummaries) !== null && _a !== void 0 ? _a : []));
}
return results;
}
async fetchUserPoolId(stackId) {
var _a;
const resources = await this.fetchStackResources(stackId);
const pools = resources.filter((r) => r.ResourceType === 'AWS::Cognito::UserPool');
if (pools.length > 1) {
const physicalIds = pools.map((p) => { var _a; return (_a = p.PhysicalResourceId) !== null && _a !== void 0 ? _a : '<unknown>'; }).join(', ');
throw new amplify_cli_core_1.AmplifyError('MigrationError', {
message: `Expected exactly one UserPool in stack '${stackId}', found ${pools.length}: ${physicalIds}`,
});
}
return (_a = pools[0]) === null || _a === void 0 ? void 0 : _a.PhysicalResourceId;
}
async fetchSocialAuthConfig(userPoolId) {
var _a, _b, _c;
const pool = await this.clients.cognitoIdentityProvider.send(new client_cognito_identity_provider_1.DescribeUserPoolCommand({ UserPoolId: userPoolId }));
const domain = (_a = pool === null || pool === void 0 ? void 0 : pool.UserPool) === null || _a === void 0 ? void 0 : _a.Domain;
if (!domain)
return undefined;
const list = await this.clients.cognitoIdentityProvider.send(new client_cognito_identity_provider_1.ListIdentityProvidersCommand({ UserPoolId: userPoolId }));
const providers = [];
for (const p of (_b = list === null || list === void 0 ? void 0 : list.Providers) !== null && _b !== void 0 ? _b : []) {
if (!p.ProviderName)
continue;
providers.push({ providerName: p.ProviderName, providerType: (_c = p.ProviderType) !== null && _c !== void 0 ? _c : p.ProviderName });
}
if (providers.length === 0)
return undefined;
return { userPoolId, domain, providers };
}
}
exports.StackFacade = StackFacade;
//# sourceMappingURL=stack-facade.js.map