use of bio.terra.cli.exception.SystemException in project terra-cli by DataBiosphere.
the class DataRepoService method getVersion.
/**
* Call the Data Repo "/configuration" endpoint to get the version of the server that is currently
* running.
*
* @return the Data Repo configuration object
*/
public RepositoryConfigurationModel getVersion() {
UnauthenticatedApi unauthenticatedApi = new UnauthenticatedApi(apiClient);
RepositoryConfigurationModel repositoryConfig = null;
try {
repositoryConfig = unauthenticatedApi.retrieveRepositoryConfig();
} catch (ApiException ex) {
throw new SystemException("Error getting Data Repo version", ex);
}
return repositoryConfig;
}
use of bio.terra.cli.exception.SystemException in project terra-cli by DataBiosphere.
the class GoogleNotebooks method stop.
public void stop(InstanceName instanceName) {
try {
Operation stopOperation = notebooks.instances().stop(instanceName).execute();
pollForSuccess(stopOperation, "Error stopping notebook instance: ");
} catch (InterruptedException | IOException e) {
checkFor409BadState(e);
throw new SystemException("Error stopping notebook instance", e);
}
}
use of bio.terra.cli.exception.SystemException in project terra-cli by DataBiosphere.
the class GoogleOauth method revokeToken.
/**
* Revoke token (https://developers.google.com/identity/protocols/oauth2/web-server#tokenrevoke).
*
* <p>Google Java OAuth library doesn't support revoking tokens
* (https://github.com/googleapis/google-oauth-java-client/issues/250), so make the call ourself.
*
* @param credential credentials object
*/
public static void revokeToken(Optional<GoogleCredentials> credential) {
if (credential.isPresent() && credential.get().getAccessToken() != null) {
String endpoint = "https://oauth2.googleapis.com/revoke";
Map<String, String> headers = ImmutableMap.of("Content-type", "application/x-www-form-urlencoded");
Map<String, String> params = ImmutableMap.of("token", credential.get().getAccessToken().getTokenValue());
try {
HttpUtils.sendHttpRequest(endpoint, "POST", headers, params);
} catch (IOException ioEx) {
throw new SystemException("Unable to revoke token", ioEx);
}
}
}
use of bio.terra.cli.exception.SystemException in project terra-cli by DataBiosphere.
the class WorkspaceManagerService method enumerateAllResources.
/**
* Call the Workspace Manager GET "/api/workspaces/v1/{workspaceId}/resources" endpoint, possibly
* multiple times, to get a list of all resources (controlled and referenced) in the workspace.
* Throw an exception if the number of resources in the workspace is greater than the specified
* limit.
*
* @param workspaceId the workspace to query
* @param limit the maximum number of resources to return
* @return a list of resources
* @throws SystemException if the number of resources in the workspace > the specified limit
*/
public List<ResourceDescription> enumerateAllResources(UUID workspaceId, int limit) {
return handleClientExceptions(() -> {
// poll the enumerate endpoint until no results are returned, or we hit the limit
List<ResourceDescription> allResources = new ArrayList<>();
int numResultsReturned = 0;
do {
int offset = allResources.size();
ResourceList result = HttpUtils.callWithRetries(() -> new ResourceApi(apiClient).enumerateResources(workspaceId, offset, MAX_RESOURCES_PER_ENUMERATE_REQUEST, null, null), WorkspaceManagerService::isRetryable);
// add all fetched resources to the running list
numResultsReturned = result.getResources().size();
logger.debug("Called enumerate endpoints, fetched {} resources", numResultsReturned);
allResources.addAll(result.getResources());
// if we have fetched more than the limit, then throw an exception
if (allResources.size() > limit) {
throw new SystemException("Total number of resources (" + allResources.size() + ") exceeds the CLI limit (" + limit + ")");
}
// if this fetch returned less than the maximum allowed per request, then that indicates
// there are no more
} while (numResultsReturned >= MAX_RESOURCES_PER_ENUMERATE_REQUEST);
logger.debug("Fetched total number of resources: {}", allResources.size());
return allResources;
}, "Error enumerating resources in the workspace.");
}
use of bio.terra.cli.exception.SystemException in project terra-cli by DataBiosphere.
the class User method doOauthLoginFlow.
/**
* Do the OAuth login flow. If there is an existing non-expired credential stored on disk, then we
* load that. If not, then we prompt the user for the requested user scopes.
*/
private void doOauthLoginFlow() {
try (InputStream inputStream = User.class.getClassLoader().getResourceAsStream(CLIENT_SECRET_FILENAME)) {
// log the user in and get their consent to the requested scopes
boolean launchBrowserAutomatically = Context.getConfig().getBrowserLaunchOption().equals(Config.BrowserLaunchOption.AUTO);
googleCredentials = GoogleOauth.doLoginAndConsent(USER_SCOPES, inputStream, Context.getContextDir().toFile(), launchBrowserAutomatically, LOGIN_LANDING_PAGE);
} catch (IOException | GeneralSecurityException ex) {
throw new SystemException("Error fetching user credentials.", ex);
}
}
Aggregations