Search in sources :

Example 1 with User

use of io.dockstore.webservice.core.User in project dockstore by dockstore.

the class AbstractWorkflowResource method syncEntities.

/**
 * Syncs entities based on GitHub app installation, optionally limiting to orgs in the GitHub organization <code>organization</code>.
 *
 * 1. Finds all repos that have the Dockstore GitHub app installed
 * 2. For existing entities, ensures that <code>user</code> is one of the entity's users
 *
 * @param user
 * @param gitHubToken
 */
private void syncEntities(User user, Token gitHubToken) {
    GitHubSourceCodeRepo gitHubSourceCodeRepo = (GitHubSourceCodeRepo) SourceCodeRepoFactory.createSourceCodeRepo(gitHubToken);
    // Get all GitHub repositories for the user
    final Map<String, String> workflowGitUrl2Name = gitHubSourceCodeRepo.getWorkflowGitUrl2RepositoryId();
    // Filter by organization if necessary
    final Collection<String> repositories = workflowGitUrl2Name.values();
    // Add user to any services they should have access to that already exist on Dockstore
    final List<Workflow> existingWorkflows = findDockstoreWorkflowsForGitHubRepos(repositories);
    existingWorkflows.stream().filter(workflow -> !workflow.getUsers().contains(user)).forEach(workflow -> workflow.getUsers().add(user));
// No longer adds stub services, though code could be useful
// final Set<String> existingWorkflowPaths = existingWorkflows.stream()
// .map(workflow -> workflow.getWorkflowPath()).collect(Collectors.toSet());
// 
// GitHubHelper.checkJWT(gitHubAppId, gitHubPrivateKeyFile);
// 
// GitHubHelper.reposToCreateEntitiesFor(repositories, organization, existingWorkflowPaths).stream()
// .forEach(repositoryName -> {
// final T entity = initializeEntity(repositoryName, gitHubSourceCodeRepo);
// entity.addUser(user);
// final long entityId = workflowDAO.create(entity);
// final Workflow createdEntity = workflowDAO.findById(entityId);
// final Workflow updatedEntity = gitHubSourceCodeRepo.getWorkflow(repositoryName, Optional.of(createdEntity));
// updateDBWorkflowWithSourceControlWorkflow(createdEntity, updatedEntity, user);
// });
}
Also used : WorkflowVersion(io.dockstore.webservice.core.WorkflowVersion) WorkflowDAO(io.dockstore.webservice.jdbi.WorkflowDAO) LoggerFactory(org.slf4j.LoggerFactory) CustomWebApplicationException(io.dockstore.webservice.CustomWebApplicationException) HttpStatus(org.apache.http.HttpStatus) DockstoreWebserviceConfiguration(io.dockstore.webservice.DockstoreWebserviceConfiguration) SourceFile(io.dockstore.webservice.core.SourceFile) STUB(io.dockstore.webservice.core.WorkflowMode.STUB) Transaction(org.hibernate.Transaction) SourceCodeRepoFactory(io.dockstore.webservice.helpers.SourceCodeRepoFactory) YamlWorkflow(io.dockstore.common.yaml.YamlWorkflow) Duration(java.time.Duration) Map(java.util.Map) TokenType(io.dockstore.webservice.core.TokenType) CacheConfigManager(io.dockstore.webservice.helpers.CacheConfigManager) User(io.dockstore.webservice.core.User) Path(java.nio.file.Path) WorkflowVersionDAO(io.dockstore.webservice.jdbi.WorkflowVersionDAO) SKIP_COMMIT_ID(io.dockstore.webservice.Constants.SKIP_COMMIT_ID) Service(io.dockstore.webservice.core.Service) GitHubHelper(io.dockstore.webservice.helpers.GitHubHelper) LAMBDA_FAILURE(io.dockstore.webservice.Constants.LAMBDA_FAILURE) Collection(java.util.Collection) YamlAuthor(io.dockstore.common.yaml.YamlAuthor) SessionFactory(org.hibernate.SessionFactory) FULL(io.dockstore.webservice.core.WorkflowMode.FULL) Set(java.util.Set) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) DOCKSTORE_YML_PATH(io.dockstore.webservice.Constants.DOCKSTORE_YML_PATH) Objects(java.util.Objects) List(java.util.List) BioWorkflow(io.dockstore.webservice.core.BioWorkflow) DOCKSTORE_YML(io.dockstore.webservice.core.WorkflowMode.DOCKSTORE_YML) Optional(java.util.Optional) GHRateLimit(org.kohsuke.github.GHRateLimit) LambdaEvent(io.dockstore.webservice.core.LambdaEvent) Validation(io.dockstore.webservice.core.Validation) WorkflowMode(io.dockstore.webservice.core.WorkflowMode) HashMap(java.util.HashMap) PublicStateManager(io.dockstore.webservice.helpers.PublicStateManager) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Author(io.dockstore.webservice.core.Author) OrcidAuthor(io.dockstore.webservice.core.OrcidAuthor) HttpClient(org.apache.http.client.HttpClient) FileFormatDAO(io.dockstore.webservice.jdbi.FileFormatDAO) Checksum(io.dockstore.webservice.core.Checksum) EventDAO(io.dockstore.webservice.jdbi.EventDAO) Api(io.swagger.annotations.Api) Token(io.dockstore.webservice.core.Token) Workflow(io.dockstore.webservice.core.Workflow) UserDAO(io.dockstore.webservice.jdbi.UserDAO) FileDAO(io.dockstore.webservice.jdbi.FileDAO) DockstoreYaml12(io.dockstore.common.yaml.DockstoreYaml12) DockstoreYamlHelper(io.dockstore.common.yaml.DockstoreYamlHelper) GitHelper(io.dockstore.webservice.helpers.GitHelper) FileFormatHelper(io.dockstore.webservice.helpers.FileFormatHelper) Logger(org.slf4j.Logger) DescriptorLanguageSubclass(io.dockstore.common.DescriptorLanguageSubclass) IOException(java.io.IOException) SourceCodeRepoInterface(io.dockstore.webservice.helpers.SourceCodeRepoInterface) StateManagerMode(io.dockstore.webservice.helpers.StateManagerMode) Version(io.dockstore.webservice.core.Version) LambdaEventDAO(io.dockstore.webservice.jdbi.LambdaEventDAO) GitHubSourceCodeRepo(io.dockstore.webservice.helpers.GitHubSourceCodeRepo) TokenDAO(io.dockstore.webservice.jdbi.TokenDAO) Comparator(java.util.Comparator) Service12(io.dockstore.common.yaml.Service12) YamlWorkflow(io.dockstore.common.yaml.YamlWorkflow) BioWorkflow(io.dockstore.webservice.core.BioWorkflow) Workflow(io.dockstore.webservice.core.Workflow) GitHubSourceCodeRepo(io.dockstore.webservice.helpers.GitHubSourceCodeRepo)

Example 2 with User

use of io.dockstore.webservice.core.User in project dockstore by dockstore.

the class AbstractWorkflowResource method githubWebhookDelete.

/**
 * Handle webhooks from GitHub apps after branch deletion (redirected from AWS Lambda)
 * - Delete version for corresponding service and workflow
 * @param repository Repository path (ex. dockstore/dockstore-ui2)
 * @param gitReference Git reference from GitHub (ex. refs/tags/1.0)
 * @param username Git user who triggered the event
 * @param installationId GitHub App installation ID
 * @return List of updated workflows
 */
protected List<Workflow> githubWebhookDelete(String repository, String gitReference, String username, String installationId) {
    // Retrieve name from gitReference
    Optional<String> gitReferenceName = GitHelper.parseGitHubReference(gitReference);
    if (gitReferenceName.isEmpty()) {
        String msg = "Reference " + gitReference + " is not of the valid form";
        LOG.error(msg);
        sessionFactory.getCurrentSession().clear();
        LambdaEvent lambdaEvent = createBasicEvent(repository, gitReference, username, LambdaEvent.LambdaEventType.DELETE);
        lambdaEvent.setMessage(msg);
        lambdaEvent.setSuccess(false);
        lambdaEventDAO.create(lambdaEvent);
        sessionFactory.getCurrentSession().getTransaction().commit();
        throw new CustomWebApplicationException(msg, LAMBDA_FAILURE);
    }
    // Find all workflows and services that are github apps and use the given repo
    List<Workflow> workflows = workflowDAO.findAllByPath("github.com/" + repository, false).stream().filter(workflow -> Objects.equals(workflow.getMode(), DOCKSTORE_YML)).collect(Collectors.toList());
    // When the git reference to delete is the default version, set it to the next latest version
    workflows.forEach(workflow -> {
        if (workflow.getActualDefaultVersion() != null && workflow.getActualDefaultVersion().getName().equals(gitReferenceName.get())) {
            Optional<WorkflowVersion> max = workflow.getWorkflowVersions().stream().filter(v -> !Objects.equals(v.getName(), gitReferenceName.get())).max(Comparator.comparingLong(ver -> ver.getDate().getTime()));
            workflow.setActualDefaultVersion(max.orElse(null));
        }
    });
    // Delete all non-frozen versions that have the same git reference name and then update the file formats of the entry.
    workflows.forEach(workflow -> {
        workflow.getWorkflowVersions().removeIf(workflowVersion -> Objects.equals(workflowVersion.getName(), gitReferenceName.get()) && !workflowVersion.isFrozen());
        FileFormatHelper.updateEntryLevelFileFormats(workflow);
    });
    LambdaEvent lambdaEvent = createBasicEvent(repository, gitReference, username, LambdaEvent.LambdaEventType.DELETE);
    lambdaEventDAO.create(lambdaEvent);
    return workflows;
}
Also used : WorkflowVersion(io.dockstore.webservice.core.WorkflowVersion) WorkflowDAO(io.dockstore.webservice.jdbi.WorkflowDAO) LoggerFactory(org.slf4j.LoggerFactory) CustomWebApplicationException(io.dockstore.webservice.CustomWebApplicationException) HttpStatus(org.apache.http.HttpStatus) DockstoreWebserviceConfiguration(io.dockstore.webservice.DockstoreWebserviceConfiguration) SourceFile(io.dockstore.webservice.core.SourceFile) STUB(io.dockstore.webservice.core.WorkflowMode.STUB) Transaction(org.hibernate.Transaction) SourceCodeRepoFactory(io.dockstore.webservice.helpers.SourceCodeRepoFactory) YamlWorkflow(io.dockstore.common.yaml.YamlWorkflow) Duration(java.time.Duration) Map(java.util.Map) TokenType(io.dockstore.webservice.core.TokenType) CacheConfigManager(io.dockstore.webservice.helpers.CacheConfigManager) User(io.dockstore.webservice.core.User) Path(java.nio.file.Path) WorkflowVersionDAO(io.dockstore.webservice.jdbi.WorkflowVersionDAO) SKIP_COMMIT_ID(io.dockstore.webservice.Constants.SKIP_COMMIT_ID) Service(io.dockstore.webservice.core.Service) GitHubHelper(io.dockstore.webservice.helpers.GitHubHelper) LAMBDA_FAILURE(io.dockstore.webservice.Constants.LAMBDA_FAILURE) Collection(java.util.Collection) YamlAuthor(io.dockstore.common.yaml.YamlAuthor) SessionFactory(org.hibernate.SessionFactory) FULL(io.dockstore.webservice.core.WorkflowMode.FULL) Set(java.util.Set) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) DOCKSTORE_YML_PATH(io.dockstore.webservice.Constants.DOCKSTORE_YML_PATH) Objects(java.util.Objects) List(java.util.List) BioWorkflow(io.dockstore.webservice.core.BioWorkflow) DOCKSTORE_YML(io.dockstore.webservice.core.WorkflowMode.DOCKSTORE_YML) Optional(java.util.Optional) GHRateLimit(org.kohsuke.github.GHRateLimit) LambdaEvent(io.dockstore.webservice.core.LambdaEvent) Validation(io.dockstore.webservice.core.Validation) WorkflowMode(io.dockstore.webservice.core.WorkflowMode) HashMap(java.util.HashMap) PublicStateManager(io.dockstore.webservice.helpers.PublicStateManager) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Author(io.dockstore.webservice.core.Author) OrcidAuthor(io.dockstore.webservice.core.OrcidAuthor) HttpClient(org.apache.http.client.HttpClient) FileFormatDAO(io.dockstore.webservice.jdbi.FileFormatDAO) Checksum(io.dockstore.webservice.core.Checksum) EventDAO(io.dockstore.webservice.jdbi.EventDAO) Api(io.swagger.annotations.Api) Token(io.dockstore.webservice.core.Token) Workflow(io.dockstore.webservice.core.Workflow) UserDAO(io.dockstore.webservice.jdbi.UserDAO) FileDAO(io.dockstore.webservice.jdbi.FileDAO) DockstoreYaml12(io.dockstore.common.yaml.DockstoreYaml12) DockstoreYamlHelper(io.dockstore.common.yaml.DockstoreYamlHelper) GitHelper(io.dockstore.webservice.helpers.GitHelper) FileFormatHelper(io.dockstore.webservice.helpers.FileFormatHelper) Logger(org.slf4j.Logger) DescriptorLanguageSubclass(io.dockstore.common.DescriptorLanguageSubclass) IOException(java.io.IOException) SourceCodeRepoInterface(io.dockstore.webservice.helpers.SourceCodeRepoInterface) StateManagerMode(io.dockstore.webservice.helpers.StateManagerMode) Version(io.dockstore.webservice.core.Version) LambdaEventDAO(io.dockstore.webservice.jdbi.LambdaEventDAO) GitHubSourceCodeRepo(io.dockstore.webservice.helpers.GitHubSourceCodeRepo) TokenDAO(io.dockstore.webservice.jdbi.TokenDAO) Comparator(java.util.Comparator) Service12(io.dockstore.common.yaml.Service12) YamlWorkflow(io.dockstore.common.yaml.YamlWorkflow) BioWorkflow(io.dockstore.webservice.core.BioWorkflow) Workflow(io.dockstore.webservice.core.Workflow) CustomWebApplicationException(io.dockstore.webservice.CustomWebApplicationException) LambdaEvent(io.dockstore.webservice.core.LambdaEvent) WorkflowVersion(io.dockstore.webservice.core.WorkflowVersion)

Example 3 with User

use of io.dockstore.webservice.core.User in project dockstore by dockstore.

the class CollectionResource method createCollection.

@POST
@Timed
@UnitOfWork
@Path("{organizationId}/collections")
@ApiOperation(value = "Create a collection in the given organization.", authorizations = { @Authorization(value = JWT_SECURITY_DEFINITION_NAME) }, response = Collection.class)
@Operation(operationId = "createCollection", summary = "Create a collection in the given organization.", description = "Create a collection in the given organization.", security = @SecurityRequirement(name = "bearer"))
public Collection createCollection(@ApiParam(hidden = true) @Parameter(hidden = true, name = "user") @Auth User user, @ApiParam(value = "Organization ID.", required = true) @Parameter(description = "Organization ID.", name = "organizationId", in = ParameterIn.PATH, required = true) @PathParam("organizationId") Long organizationId, @ApiParam(value = "Collection to register.", required = true) @Parameter(description = "Collection to register.", name = "collection", required = true) Collection collection) {
    // First check if the organization exists and that the user is an admin or maintainer
    boolean isUserAdminOrMaintainer = OrganizationResource.isUserAdminOrMaintainer(organizationId, user.getId(), organizationDAO);
    if (!isUserAdminOrMaintainer) {
        String msg = "Organization not found.";
        LOG.info(msg);
        throw new CustomWebApplicationException(msg, HttpStatus.SC_NOT_FOUND);
    }
    // Check if any other collections in the organization exist with that name
    Collection matchingCollection = collectionDAO.findByNameAndOrg(collection.getName(), organizationId);
    if (matchingCollection != null) {
        String msg = "A collection already exists with the name '" + collection.getName() + "' in the specified organization.";
        LOG.info(msg);
        throw new CustomWebApplicationException(msg, HttpStatus.SC_BAD_REQUEST);
    }
    // Get the organization
    Organization organization = organizationDAO.findById(organizationId);
    // Save the collection
    long id = collectionDAO.create(collection);
    organization.addCollection(collection);
    // Event for creation
    User foundUser = userDAO.findById(user.getId());
    Event createCollectionEvent = new Event.Builder().withOrganization(organization).withCollection(collection).withInitiatorUser(foundUser).withType(Event.EventType.CREATE_COLLECTION).build();
    eventDAO.create(createCollectionEvent);
    return collectionDAO.findById(id);
}
Also used : Organization(io.dockstore.webservice.core.Organization) OrganizationUser(io.dockstore.webservice.core.OrganizationUser) User(io.dockstore.webservice.core.User) Collection(io.dockstore.webservice.core.Collection) Event(io.dockstore.webservice.core.Event) CustomWebApplicationException(io.dockstore.webservice.CustomWebApplicationException) Path(javax.ws.rs.Path) UnitOfWork(io.dropwizard.hibernate.UnitOfWork) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiOperation(io.swagger.annotations.ApiOperation) Operation(io.swagger.v3.oas.annotations.Operation)

Example 4 with User

use of io.dockstore.webservice.core.User in project dockstore by dockstore.

the class CollectionResource method deleteEntryFromCollection.

@DELETE
@Timed
@UnitOfWork
@Path("{organizationId}/collections/{collectionId}/entry")
@ApiOperation(value = "Delete an entry from a collection.", authorizations = { @Authorization(value = JWT_SECURITY_DEFINITION_NAME) }, response = Collection.class)
@Operation(operationId = "deleteEntryFromCollection", summary = "Delete an entry to a collection.", description = "Delete an entry to a collection.", security = @SecurityRequirement(name = "bearer"))
public Collection deleteEntryFromCollection(@ApiParam(hidden = true) @Parameter(hidden = true, name = "user") @Auth User user, @ApiParam(value = "Organization ID.", required = true) @Parameter(description = "Organization ID.", name = "organizationId", in = ParameterIn.PATH, required = true) @PathParam("organizationId") Long organizationId, @ApiParam(value = "Collection ID.", required = true) @Parameter(description = "Collection ID.", name = "collectionId", in = ParameterIn.PATH, required = true) @PathParam("collectionId") Long collectionId, @ApiParam(value = "Entry ID", required = true) @Parameter(description = "Entry ID.", name = "entryId", in = ParameterIn.QUERY, required = true) @QueryParam("entryId") Long entryId, @ApiParam(value = "Version ID", required = false) @Parameter(description = "Version ID.", name = "versionId", in = ParameterIn.QUERY, required = false) @QueryParam("versionName") String versionName) {
    // Call common code to check if entry and collection exist and return them
    ImmutablePair<Entry, Collection> entryAndCollection = commonModifyCollection(organizationId, entryId, collectionId, user);
    Long versionId = null;
    if (versionName != null) {
        Set<Version> workflowVersions = entryAndCollection.getLeft().getWorkflowVersions();
        Optional<Version> first = workflowVersions.stream().filter(version -> version.getName().equals(versionName)).findFirst();
        if (first.isPresent()) {
            versionId = first.get().getId();
        } else {
            throw new CustomWebApplicationException("Version not found", HttpStatus.SC_NOT_FOUND);
        }
    }
    // Remove the entry from the organization,
    // This silently fails if the user somehow manages to give a non-existent entryId and versionId pair
    entryAndCollection.getRight().removeEntry(entryAndCollection.getLeft().getId(), versionId);
    // Event for deletion
    Organization organization = organizationDAO.findById(organizationId);
    Event.Builder eventBuild = new Event.Builder().withOrganization(organization).withCollection(entryAndCollection.getRight()).withInitiatorUser(user).withType(Event.EventType.REMOVE_FROM_COLLECTION);
    if (entryAndCollection.getLeft() instanceof BioWorkflow) {
        eventBuild = eventBuild.withBioWorkflow((BioWorkflow) entryAndCollection.getLeft());
    } else if (entryAndCollection.getLeft() instanceof Service) {
        eventBuild = eventBuild.withService((Service) entryAndCollection.getLeft());
    } else if (entryAndCollection.getLeft() instanceof Tool) {
        eventBuild = eventBuild.withTool((Tool) entryAndCollection.getLeft());
    }
    Event removeFromCollectionEvent = eventBuild.build();
    eventDAO.create(removeFromCollectionEvent);
    return collectionDAO.findById(collectionId);
}
Also used : Arrays(java.util.Arrays) Produces(javax.ws.rs.Produces) WorkflowDAO(io.dockstore.webservice.jdbi.WorkflowDAO) Path(javax.ws.rs.Path) LoggerFactory(org.slf4j.LoggerFactory) CustomWebApplicationException(io.dockstore.webservice.CustomWebApplicationException) ApiParam(io.swagger.annotations.ApiParam) HttpStatus(org.apache.http.HttpStatus) OrganizationUser(io.dockstore.webservice.core.OrganizationUser) ApiOperation(io.swagger.annotations.ApiOperation) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) CollectionEntry(io.dockstore.webservice.core.CollectionEntry) OPENAPI_JWT_SECURITY_DEFINITION_NAME(io.dockstore.webservice.resources.ResourceConstants.OPENAPI_JWT_SECURITY_DEFINITION_NAME) User(io.dockstore.webservice.core.User) DELETE(javax.ws.rs.DELETE) SecurityRequirement(io.swagger.v3.oas.annotations.security.SecurityRequirement) Schema(io.swagger.v3.oas.annotations.media.Schema) Service(io.dockstore.webservice.core.Service) Collection(io.dockstore.webservice.core.Collection) SessionFactory(org.hibernate.SessionFactory) Set(java.util.Set) Tool(io.dockstore.webservice.core.Tool) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) Parameter(io.swagger.v3.oas.annotations.Parameter) Timed(com.codahale.metrics.annotation.Timed) List(java.util.List) Event(io.dockstore.webservice.core.Event) CollectionDAO(io.dockstore.webservice.jdbi.CollectionDAO) UnitOfWork(io.dropwizard.hibernate.UnitOfWork) Tag(io.swagger.v3.oas.annotations.tags.Tag) BioWorkflow(io.dockstore.webservice.core.BioWorkflow) Optional(java.util.Optional) SecuritySchemeType(io.swagger.v3.oas.annotations.enums.SecuritySchemeType) PathParam(javax.ws.rs.PathParam) GET(javax.ws.rs.GET) Auth(io.dropwizard.auth.Auth) Session(org.hibernate.Session) JWT_SECURITY_DEFINITION_NAME(io.dockstore.webservice.Constants.JWT_SECURITY_DEFINITION_NAME) SecurityScheme(io.swagger.v3.oas.annotations.security.SecurityScheme) PublicStateManager(io.dockstore.webservice.helpers.PublicStateManager) ParameterIn(io.swagger.v3.oas.annotations.enums.ParameterIn) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Label(io.dockstore.webservice.core.Label) Content(io.swagger.v3.oas.annotations.media.Content) Operation(io.swagger.v3.oas.annotations.Operation) OrganizationDAO(io.dockstore.webservice.jdbi.OrganizationDAO) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse) EventDAO(io.dockstore.webservice.jdbi.EventDAO) Api(io.swagger.annotations.Api) UserDAO(io.dockstore.webservice.jdbi.UserDAO) SecuritySchemes(io.swagger.v3.oas.annotations.security.SecuritySchemes) ToolDAO(io.dockstore.webservice.jdbi.ToolDAO) POST(javax.ws.rs.POST) Logger(org.slf4j.Logger) VersionDAO(io.dockstore.webservice.jdbi.VersionDAO) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) Organization(io.dockstore.webservice.core.Organization) Version(io.dockstore.webservice.core.Version) Entry(io.dockstore.webservice.core.Entry) PUT(javax.ws.rs.PUT) Authorization(io.swagger.annotations.Authorization) Hibernate(org.hibernate.Hibernate) Organization(io.dockstore.webservice.core.Organization) Service(io.dockstore.webservice.core.Service) CustomWebApplicationException(io.dockstore.webservice.CustomWebApplicationException) BioWorkflow(io.dockstore.webservice.core.BioWorkflow) CollectionEntry(io.dockstore.webservice.core.CollectionEntry) Entry(io.dockstore.webservice.core.Entry) Version(io.dockstore.webservice.core.Version) Collection(io.dockstore.webservice.core.Collection) Event(io.dockstore.webservice.core.Event) Tool(io.dockstore.webservice.core.Tool) Path(javax.ws.rs.Path) UnitOfWork(io.dropwizard.hibernate.UnitOfWork) DELETE(javax.ws.rs.DELETE) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiOperation(io.swagger.annotations.ApiOperation) Operation(io.swagger.v3.oas.annotations.Operation)

Example 5 with User

use of io.dockstore.webservice.core.User in project dockstore by dockstore.

the class SamPermissionsImpl method getApiClient.

private ApiClient getApiClient(User user) {
    ApiClient apiClient = new ApiClient() {

        @Override
        protected void performAdditionalClientConfiguration(ClientConfig clientConfig) {
            // Calling ResourcesApi.addUserToPolicy invokes PUT without a body, which will fail
            // without this:
            clientConfig.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
        }
    };
    apiClient.setBasePath(config.getSamConfiguration().getBasepath());
    return googleAccessToken(user).map(credentials -> {
        apiClient.setAccessToken(credentials);
        return apiClient;
    }).orElseThrow(() -> new CustomWebApplicationException("Could not get Google access token. Try relinking your Google account.", HttpStatus.SC_UNAUTHORIZED));
}
Also used : Arrays(java.util.Arrays) URLDecoder(java.net.URLDecoder) ClientConfig(org.glassfish.jersey.client.ClientConfig) AccessPolicyResponseEntry(io.swagger.sam.client.model.AccessPolicyResponseEntry) LoggerFactory(org.slf4j.LoggerFactory) CustomWebApplicationException(io.dockstore.webservice.CustomWebApplicationException) AccessPolicyMembership(io.swagger.sam.client.model.AccessPolicyMembership) HttpStatus(org.apache.http.HttpStatus) HashMap(java.util.HashMap) DockstoreWebserviceConfiguration(io.dockstore.webservice.DockstoreWebserviceConfiguration) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) Map(java.util.Map) TokenType(io.dockstore.webservice.core.TokenType) User(io.dockstore.webservice.core.User) ApiClient(io.swagger.sam.client.ApiClient) Token(io.dockstore.webservice.core.Token) Workflow(io.dockstore.webservice.core.Workflow) ResourceAndAccessPolicy(io.swagger.sam.client.model.ResourceAndAccessPolicy) Logger(org.slf4j.Logger) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ErrorReport(io.swagger.sam.client.model.ErrorReport) ClientProperties(org.glassfish.jersey.client.ClientProperties) Collectors(java.util.stream.Collectors) GoogleHelper(io.dockstore.webservice.helpers.GoogleHelper) PermissionsInterface(io.dockstore.webservice.permissions.PermissionsInterface) Role(io.dockstore.webservice.permissions.Role) List(java.util.List) JSON(io.swagger.sam.client.JSON) ApiException(io.swagger.sam.client.ApiException) Optional(java.util.Optional) TokenDAO(io.dockstore.webservice.jdbi.TokenDAO) Permission(io.dockstore.webservice.permissions.Permission) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Collections(java.util.Collections) ResourcesApi(io.swagger.sam.client.api.ResourcesApi) CustomWebApplicationException(io.dockstore.webservice.CustomWebApplicationException) ApiClient(io.swagger.sam.client.ApiClient) ClientConfig(org.glassfish.jersey.client.ClientConfig)

Aggregations

User (io.dockstore.webservice.core.User)100 CustomWebApplicationException (io.dockstore.webservice.CustomWebApplicationException)57 UnitOfWork (io.dropwizard.hibernate.UnitOfWork)53 Timed (com.codahale.metrics.annotation.Timed)51 ApiOperation (io.swagger.annotations.ApiOperation)51 Operation (io.swagger.v3.oas.annotations.Operation)51 Path (javax.ws.rs.Path)50 Token (io.dockstore.webservice.core.Token)42 OrganizationUser (io.dockstore.webservice.core.OrganizationUser)35 List (java.util.List)33 GET (javax.ws.rs.GET)32 HttpStatus (org.apache.http.HttpStatus)32 Map (java.util.Map)31 Optional (java.util.Optional)30 Logger (org.slf4j.Logger)29 LoggerFactory (org.slf4j.LoggerFactory)29 ArrayList (java.util.ArrayList)27 POST (javax.ws.rs.POST)26 UserDAO (io.dockstore.webservice.jdbi.UserDAO)25 DockstoreWebserviceConfiguration (io.dockstore.webservice.DockstoreWebserviceConfiguration)24