runWithConfig method
Runs this command with prepared configuration (options). Subclasses should override this method.
Implementation
@override
Future<void> runWithConfig(
final Configuration<BuildSecretSetCommandConfig> commandConfig,
) async {
final projectId = commandConfig.value(
BuildSecretSetCommandConfig.projectId,
);
final name = commandConfig.value(BuildSecretSetCommandConfig.name);
final value = commandConfig.optionalValue(
BuildSecretSetCommandConfig.value,
);
final valueFile = commandConfig.optionalValue(
BuildSecretSetCommandConfig.valueFile,
);
final buildSecretType = commandConfig.value(
BuildSecretSetCommandConfig.buildSecretType,
);
String valueToSet;
if (value != null) {
valueToSet = value;
} else if (valueFile != null) {
valueToSet = valueFile.readAsStringSync();
} else {
throw StateError('Expected one of the value options to be set.');
}
final apiCloudClient = runner.serviceProvider.cloudApiClient;
try {
await apiCloudClient.secrets.upsertBuildSecret(
cloudCapsuleId: projectId,
secretKey: name,
secretValue: valueToSet,
buildSecretType: buildSecretType,
);
} on Exception catch (e, s) {
throw FailureException.nested(e, s, 'Failed to set build secret');
}
logger.success('Successfully set build secret: $name.');
}