Search in sources :

Example 1 with ApiException

use of bio.terra.datarepo.client.ApiException in project terra-workspace-manager by DataBiosphere.

the class DataRepoService method snapshotReadable.

/**
 * Returns whether or not a given snapshot is readable for a given user. On the TDR side,
 * retrieveSnapshot requires that a user have read access to the snapshot's data.
 */
@Traced
public boolean snapshotReadable(String instanceName, String snapshotId, AuthenticatedUserRequest userRequest) {
    RepositoryApi repositoryApi = repositoryApi(instanceName, userRequest);
    try {
        repositoryApi.retrieveSnapshot(snapshotId);
        logger.info("Retrieved snapshotId {} on Data Repo instance {}", snapshotId, instanceName);
        return true;
    } catch (ApiException e) {
        // UNAUTHORIZED here instead of FORBIDDEN.
        if (e.getCode() == HttpStatus.NOT_FOUND.value() || e.getCode() == HttpStatus.UNAUTHORIZED.value()) {
            return false;
        } else {
            throw new DataRepoInternalServerErrorException("Data Repo returned the following error: " + e.getMessage(), e.getCause());
        }
    }
}
Also used : RepositoryApi(bio.terra.datarepo.api.RepositoryApi) DataRepoInternalServerErrorException(bio.terra.workspace.service.datarepo.exception.DataRepoInternalServerErrorException) ApiException(bio.terra.datarepo.client.ApiException) Traced(io.opencensus.contrib.spring.aop.Traced)

Example 2 with ApiException

use of bio.terra.datarepo.client.ApiException 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;
}
Also used : SystemException(bio.terra.cli.exception.SystemException) RepositoryConfigurationModel(bio.terra.datarepo.model.RepositoryConfigurationModel) UnauthenticatedApi(bio.terra.datarepo.api.UnauthenticatedApi) ApiException(bio.terra.datarepo.client.ApiException)

Aggregations

ApiException (bio.terra.datarepo.client.ApiException)2 SystemException (bio.terra.cli.exception.SystemException)1 RepositoryApi (bio.terra.datarepo.api.RepositoryApi)1 UnauthenticatedApi (bio.terra.datarepo.api.UnauthenticatedApi)1 RepositoryConfigurationModel (bio.terra.datarepo.model.RepositoryConfigurationModel)1 DataRepoInternalServerErrorException (bio.terra.workspace.service.datarepo.exception.DataRepoInternalServerErrorException)1 Traced (io.opencensus.contrib.spring.aop.Traced)1