use of bio.terra.cli.exception.UserActionableException in project terra-cli by DataBiosphere.
the class BqDataset method execute.
/**
* Update a BigQuery dataset in the workspace.
*/
@Override
protected void execute() {
workspaceOption.overrideIfSpecified();
// all update parameters are optional, but make sure at least one is specified
if (!resourceUpdateOptions.isDefined() && !bqDatasetLifetimeOptions.isDefined() && !bqDatasetNewIds.isDefined()) {
throw new UserActionableException("Specify at least one property to update.");
}
// get the resource and make sure it's the right type
bio.terra.cli.businessobject.resource.BqDataset resource = Context.requireWorkspace().getResource(resourceUpdateOptions.resourceNameOption.name).castToType(Resource.Type.BQ_DATASET);
if (resource.getStewardshipType().equals(StewardshipType.REFERENCED)) {
if (bqDatasetLifetimeOptions.isDefined()) {
throw new UserActionableException("Default lifetime can only be updated for controlled resources.");
}
UpdateReferencedBqDatasetParams.Builder updateParams = new UpdateReferencedBqDatasetParams.Builder().resourceParams(resourceUpdateOptions.populateMetadataFields().build()).datasetId(bqDatasetNewIds.getNewBqDatasetId()).projectId(bqDatasetNewIds.getNewGcpProjectId());
resource.updateReferenced(updateParams.build());
} else {
resource.updateControlled(new UpdateControlledBqDatasetParams.Builder().resourceFields(resourceUpdateOptions.populateMetadataFields().build()).defaultPartitionLifetimeSeconds(bqDatasetLifetimeOptions.getDefaultPartitionLifetimeSeconds()).defaultTableLifetimeSeconds(bqDatasetLifetimeOptions.getDefaultTableLifetimeSeconds()).build());
}
formatOption.printReturnValue(new UFBqDataset(resource), BqDataset::printText);
}
use of bio.terra.cli.exception.UserActionableException in project terra-cli by DataBiosphere.
the class BqTable method execute.
/**
* Update a BigQuery dataset in the workspace.
*/
@Override
protected void execute() {
workspaceOption.overrideIfSpecified();
// all update parameters are optional, but make sure at least one is specified
if (!resourceUpdateOptions.isDefined() && !bqDatasetNewIds.isDefined() && newBqTableId == null) {
throw new UserActionableException("Specify at least one property to update.");
}
// get the resource and make sure it's the right type
bio.terra.cli.businessobject.resource.BqTable resource = Context.requireWorkspace().getResource(resourceUpdateOptions.resourceNameOption.name).castToType(Resource.Type.BQ_TABLE);
UpdateReferencedBqTableParams.Builder bqTableParams = new UpdateReferencedBqTableParams.Builder().resourceParams(resourceUpdateOptions.populateMetadataFields().build()).tableId(newBqTableId).datasetId(bqDatasetNewIds.getNewBqDatasetId()).projectId(bqDatasetNewIds.getNewGcpProjectId());
resource.updateReferenced(bqTableParams.build());
formatOption.printReturnValue(new UFBqTable(resource), BqTable::printText);
}
use of bio.terra.cli.exception.UserActionableException in project terra-cli by DataBiosphere.
the class GcsBucket method execute.
/**
* Update a bucket in the workspace.
*/
@Override
protected void execute() {
workspaceOption.overrideIfSpecified();
// all update parameters are optional, but make sure at least one is specified
if (!resourceUpdateOptions.isDefined() && !storageClassOption.isDefined() && !lifecycleOptions.isDefined() && newBucketName.getNewBucketName() == null) {
throw new UserActionableException("Specify at least one property to update.");
}
// get the resource and make sure it's the right type
bio.terra.cli.businessobject.resource.GcsBucket resource = Context.requireWorkspace().getResource(resourceUpdateOptions.resourceNameOption.name).castToType(Resource.Type.GCS_BUCKET);
if (resource.getStewardshipType().equals(StewardshipType.REFERENCED)) {
// some options only apply to controlled resources
if (storageClassOption.isDefined() || lifecycleOptions.isDefined()) {
throw new UserActionableException("Storage and lifecycle options can only be updated for controlled resources.");
}
UpdateReferencedGcsBucketParams.Builder gcsBucketParams = new UpdateReferencedGcsBucketParams.Builder().resourceParams(resourceUpdateOptions.populateMetadataFields().build()).bucketName(newBucketName.getNewBucketName());
resource.updateReferenced(gcsBucketParams.build());
} else {
resource.updateControlled(new UpdateControlledGcsBucketParams.Builder().resourceFields(resourceUpdateOptions.populateMetadataFields().build()).defaultStorageClass(storageClassOption.storageClass).lifecycle(lifecycleOptions.buildLifecycleObject()).build());
}
formatOption.printReturnValue(new UFGcsBucket(resource), GcsBucket::printText);
}
use of bio.terra.cli.exception.UserActionableException in project terra-cli by DataBiosphere.
the class GcsObject method execute.
/**
* Update a bucket object in the workspace.
*/
@Override
protected void execute() {
workspaceOption.overrideIfSpecified();
// all update parameters are optional, but make sure at least one is specified
if (!resourceUpdateOptions.isDefined() && newObjectName == null && newBucketName.getNewBucketName() == null) {
throw new UserActionableException("Specify at least one property to update.");
}
// get the resource and make sure it's the right type
bio.terra.cli.businessobject.resource.GcsObject resource = Context.requireWorkspace().getResource(resourceUpdateOptions.resourceNameOption.name).castToType(Resource.Type.GCS_OBJECT);
UpdateResourceParams updateResourceParams = resourceUpdateOptions.populateMetadataFields().build();
UpdateReferencedGcsObjectParams gcsObjectParams = new UpdateReferencedGcsObjectParams.Builder().resourceFields(updateResourceParams).bucketName(newBucketName.getNewBucketName()).objectName(newObjectName).build();
resource.updateReferenced(gcsObjectParams);
formatOption.printReturnValue(new UFGcsObject(resource), GcsObject::printText);
}
use of bio.terra.cli.exception.UserActionableException in project terra-cli by DataBiosphere.
the class BreakGlass method execute.
/**
* Grant break-glass access to the workspace.
*/
@Override
protected void execute() {
workspaceOption.overrideIfSpecified();
// check that the SA key files exist and are valid
ServiceAccountCredentials userProjectsAdminCredentials;
ServiceAccountCredentials bigQueryCredentials;
try {
final List<String> SA_SCOPES = ImmutableList.of("https://www.googleapis.com/auth/cloud-platform");
userProjectsAdminCredentials = GoogleOauth.getServiceAccountCredential(Path.of(userProjectAdminSAKeyFile).toFile(), SA_SCOPES);
bigQueryCredentials = GoogleOauth.getServiceAccountCredential(Path.of(bigQuerySAKeyFile).toFile(), SA_SCOPES);
} catch (IOException ioEx) {
throw new UserActionableException("Error reading break-glass SA key files.", ioEx);
}
// require that the requester is a workspace owner
Workspace currentWorkspace = Context.requireWorkspace();
Optional<WorkspaceUser> granteeWorkspaceUser = WorkspaceUser.list(currentWorkspace).stream().filter(user -> user.getEmail().equalsIgnoreCase(granteeEmail)).findAny();
if (granteeWorkspaceUser.isEmpty() || !granteeWorkspaceUser.get().getRoles().contains(WorkspaceUser.Role.OWNER)) {
updateRequestsCatalogWithFailure(bigQueryCredentials, "Requestor is not a workspace owner.");
throw new UserActionableException("The break-glass requester must be an owner of the workspace.");
}
// grant the user's proxy group the Editor role on the workspace project
String granteeProxyGroupEmail = currentWorkspace.grantBreakGlass(granteeEmail, userProjectsAdminCredentials);
// update the central BigQuery dataset with details of this request
updateRequestsCatalogWithSuccess(bigQueryCredentials, granteeProxyGroupEmail);
OUT.println("Break-glass access successfully granted to: " + granteeEmail);
}
Aggregations