runWithConfig method
Runs this command with prepared configuration (options). Subclasses should override this method.
Implementation
@override
Future<void> runWithConfig(
final Configuration<AttachCustomDomainCommandConfig> commandConfig,
) async {
final projectId = commandConfig.value(
AttachCustomDomainCommandConfig.projectId,
);
final domainName = commandConfig.value(
AttachCustomDomainCommandConfig.domainName,
);
final target = commandConfig.value(AttachCustomDomainCommandConfig.target);
final apiCloudClient = runner.serviceProvider.cloudApiClient;
late CustomDomainNameWithDefaultDomains customDomainNameWithDefaultDomains;
try {
customDomainNameWithDefaultDomains = await apiCloudClient.customDomainName
.add(
domainName: domainName,
target: target,
cloudCapsuleId: projectId,
);
} on Exception catch (e, stackTrace) {
throw FailureException.nested(
e,
stackTrace,
'Could not add the custom domain',
);
}
logger.success('Custom domain attached successfully!', newParagraph: true);
final targetDefaultDomain =
customDomainNameWithDefaultDomains.defaultDomainsByTarget[target];
if (targetDefaultDomain == null) {
throw FailureException(
error: 'Could not find the target domain for "$target".',
);
}
if (DomainUtils.isSubDomain(domainName)) {
_logDomainInstructions(
action:
'Add a CNAME record with the value "$targetDefaultDomain" '
'to the DNS configuration for this domain.',
logger: logger,
domainName: domainName,
projectId: projectId,
records: [(type: 'CNAME', value: targetDefaultDomain)],
);
return;
}
_logDomainInstructions(
action:
'Add a TXT record with the name "$targetDefaultDomain" and '
'value "${customDomainNameWithDefaultDomains.customDomainName.dnsRecordVerificationValue}".',
logger: logger,
domainName: domainName,
projectId: projectId,
records: [
(type: 'ANAME', value: targetDefaultDomain),
(
type: 'TXT',
value: customDomainNameWithDefaultDomains
.customDomainName
.dnsRecordVerificationValue,
),
],
);
}