runWithConfig method
Runs this command with prepared configuration (options). Subclasses should override this method.
Implementation
@override
Future<void> runWithConfig(
final Configuration<CreateSecretCommandConfig> commandConfig,
) async {
final projectId = commandConfig.value(CreateSecretCommandConfig.projectId);
final name = commandConfig.value(CreateSecretCommandConfig.name);
final value = commandConfig.optionalValue(CreateSecretCommandConfig.value);
final valueFile =
commandConfig.optionalValue(CreateSecretCommandConfig.valueFile);
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.create(
secrets: {name: valueToSet},
cloudCapsuleId: projectId,
);
} on Exception catch (e, s) {
throw FailureException.nested(e, s, 'Failed to create a new secret');
}
logger.success('Successfully created secret.');
}