Search in sources :

Example 1 with Workspace

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);
}
Also used : Context(bio.terra.cli.businessobject.Context) BigQueryError(com.google.cloud.bigquery.BigQueryError) Workspace(bio.terra.cli.businessobject.Workspace) WorkspaceUser(bio.terra.cli.businessobject.WorkspaceUser) Date(java.util.Date) TableId(com.google.cloud.bigquery.TableId) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) BigQuery(com.google.cloud.bigquery.BigQuery) BigQueryOptions(com.google.cloud.bigquery.BigQueryOptions) DateTime(com.google.api.client.util.DateTime) BaseCommand(bio.terra.cli.command.shared.BaseCommand) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) Command(picocli.CommandLine.Command) Path(java.nio.file.Path) CommandLine(picocli.CommandLine) Logger(org.slf4j.Logger) UserActionableException(bio.terra.cli.exception.UserActionableException) InsertAllRequest(com.google.cloud.bigquery.InsertAllRequest) IOException(java.io.IOException) UUID(java.util.UUID) List(java.util.List) GoogleOauth(bio.terra.cli.service.GoogleOauth) WorkspaceOverride(bio.terra.cli.command.shared.options.WorkspaceOverride) InsertAllResponse(com.google.cloud.bigquery.InsertAllResponse) Optional(java.util.Optional) ServiceAccountCredentials(com.google.auth.oauth2.ServiceAccountCredentials) SystemException(bio.terra.cli.exception.SystemException) UserActionableException(bio.terra.cli.exception.UserActionableException) ServiceAccountCredentials(com.google.auth.oauth2.ServiceAccountCredentials) IOException(java.io.IOException) WorkspaceUser(bio.terra.cli.businessobject.WorkspaceUser) Workspace(bio.terra.cli.businessobject.Workspace) WorkspaceOverride(bio.terra.cli.command.shared.options.WorkspaceOverride)

Example 2 with Workspace

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);
}
Also used : UFWorkspace(bio.terra.cli.serialization.userfacing.UFWorkspace) Workspace(bio.terra.cli.businessobject.Workspace) UFWorkspace(bio.terra.cli.serialization.userfacing.UFWorkspace) WorkspaceOverride(bio.terra.cli.command.shared.options.WorkspaceOverride)

Example 3 with Workspace

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);
}
Also used : UFClonedResource(bio.terra.cli.serialization.userfacing.UFClonedResource) Context(bio.terra.cli.businessobject.Context) ResourceCloneDetails(bio.terra.workspace.model.ResourceCloneDetails) Workspace(bio.terra.cli.businessobject.Workspace) Format(bio.terra.cli.command.shared.options.Format) CloneResourceResult(bio.terra.workspace.model.CloneResourceResult) Resource(bio.terra.cli.businessobject.Resource) Collectors(java.util.stream.Collectors) BaseCommand(bio.terra.cli.command.shared.BaseCommand) WorkspaceNameAndDescription(bio.terra.cli.command.shared.options.WorkspaceNameAndDescription) WorkspaceOverride(bio.terra.cli.command.shared.options.WorkspaceOverride) UFClonedResource(bio.terra.cli.serialization.userfacing.UFClonedResource) UFClonedWorkspace(bio.terra.cli.serialization.userfacing.UFClonedWorkspace) UFWorkspace(bio.terra.cli.serialization.userfacing.UFWorkspace) Optional(java.util.Optional) Command(picocli.CommandLine.Command) ClonedWorkspace(bio.terra.workspace.model.ClonedWorkspace) CommandLine(picocli.CommandLine) UFClonedWorkspace(bio.terra.cli.serialization.userfacing.UFClonedWorkspace) ClonedWorkspace(bio.terra.workspace.model.ClonedWorkspace) UFWorkspace(bio.terra.cli.serialization.userfacing.UFWorkspace) UFClonedWorkspace(bio.terra.cli.serialization.userfacing.UFClonedWorkspace) Workspace(bio.terra.cli.businessobject.Workspace) UFClonedWorkspace(bio.terra.cli.serialization.userfacing.UFClonedWorkspace) UFWorkspace(bio.terra.cli.serialization.userfacing.UFWorkspace) ClonedWorkspace(bio.terra.workspace.model.ClonedWorkspace) WorkspaceOverride(bio.terra.cli.command.shared.options.WorkspaceOverride)

Example 4 with Workspace

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);
}
Also used : UFWorkspace(bio.terra.cli.serialization.userfacing.UFWorkspace) Workspace(bio.terra.cli.businessobject.Workspace) UFWorkspace(bio.terra.cli.serialization.userfacing.UFWorkspace)

Example 5 with Workspace

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.");
}
Also used : UFWorkspace(bio.terra.cli.serialization.userfacing.UFWorkspace) Workspace(bio.terra.cli.businessobject.Workspace) UFWorkspace(bio.terra.cli.serialization.userfacing.UFWorkspace) WorkspaceOverride(bio.terra.cli.command.shared.options.WorkspaceOverride)

Aggregations

Workspace (bio.terra.cli.businessobject.Workspace)7 UFWorkspace (bio.terra.cli.serialization.userfacing.UFWorkspace)5 WorkspaceOverride (bio.terra.cli.command.shared.options.WorkspaceOverride)4 Context (bio.terra.cli.businessobject.Context)2 Resource (bio.terra.cli.businessobject.Resource)2 BaseCommand (bio.terra.cli.command.shared.BaseCommand)2 UserActionableException (bio.terra.cli.exception.UserActionableException)2 Optional (java.util.Optional)2 CommandLine (picocli.CommandLine)2 Command (picocli.CommandLine.Command)2 WorkspaceUser (bio.terra.cli.businessobject.WorkspaceUser)1 GcpNotebook (bio.terra.cli.businessobject.resource.GcpNotebook)1 Format (bio.terra.cli.command.shared.options.Format)1 WorkspaceNameAndDescription (bio.terra.cli.command.shared.options.WorkspaceNameAndDescription)1 SystemException (bio.terra.cli.exception.SystemException)1 UFClonedResource (bio.terra.cli.serialization.userfacing.UFClonedResource)1 UFClonedWorkspace (bio.terra.cli.serialization.userfacing.UFClonedWorkspace)1 GoogleOauth (bio.terra.cli.service.GoogleOauth)1 CloneResourceResult (bio.terra.workspace.model.CloneResourceResult)1 ClonedWorkspace (bio.terra.workspace.model.ClonedWorkspace)1