use of bio.terra.cli.businessobject.Workspace 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);
}
use of bio.terra.cli.businessobject.Workspace in project terra-cli by DataBiosphere.
the class Update method execute.
/**
* Update the mutable properties of an existing workspace.
*/
@Override
protected void execute() {
workspaceOption.overrideIfSpecified();
Workspace updatedWorkspace = Context.requireWorkspace().update(argGroup.displayName, argGroup.description);
formatOption.printReturnValue(new UFWorkspace(updatedWorkspace), this::printText);
}
use of bio.terra.cli.businessobject.Workspace in project terra-cli by DataBiosphere.
the class Clone method execute.
@Override
protected void execute() {
workspaceOption.overrideIfSpecified();
Workspace sourceWorkspace = Context.requireWorkspace();
ClonedWorkspace clonedWorkspace = sourceWorkspace.clone(workspaceNameAndDescription.displayName, workspaceNameAndDescription.description);
Workspace destinationWorkspaceHydrated = Workspace.get(clonedWorkspace.getDestinationWorkspaceId());
// Get a list of UFClonedResource objects based on the resources returned in the ClonedWorkspace
java.util.List<UFClonedResource> ufClonedResources = clonedWorkspace.getResources().stream().map(r -> buildUfClonedResource(sourceWorkspace, destinationWorkspaceHydrated, r)).collect(Collectors.toList());
// print results
formatOption.printReturnValue(new UFClonedWorkspace(new UFWorkspace(sourceWorkspace), new UFWorkspace(destinationWorkspaceHydrated), ufClonedResources), this::printText);
}
use of bio.terra.cli.businessobject.Workspace in project terra-cli by DataBiosphere.
the class Create method execute.
/**
* Create a new workspace.
*/
@Override
protected void execute() {
Workspace workspace = Workspace.create(workspaceNameAndDescription.displayName, workspaceNameAndDescription.description);
formatOption.printReturnValue(new UFWorkspace(workspace), this::printText);
}
use of bio.terra.cli.businessobject.Workspace in project terra-cli by DataBiosphere.
the class Delete method execute.
/**
* Delete an existing workspace.
*/
@Override
protected void execute() {
workspaceOption.overrideIfSpecified();
Workspace workspaceToDelete = Context.requireWorkspace();
// print details about the workspace before showing the delete prompt
new UFWorkspace(workspaceToDelete).print();
deletePromptOption.confirmOrThrow();
workspaceToDelete.delete();
OUT.println("Workspace successfully deleted.");
}
Aggregations