Search in sources :

Example 1 with GitLabUserContext

use of org.finos.legend.sdlc.server.gitlab.auth.GitLabUserContext in project legend-sdlc by finos.

the class IntegrationTestGitLabEntityApis method setUpEntityApi.

/**
 * Authenticates with OAuth2 and instantiate the test resource.
 */
private static void setUpEntityApi() {
    GitLabUserContext gitLabMemberUserContext = prepareGitLabMemberUserContext();
    GitLabUserContext gitLabOwnerUserContext = prepareGitLabOwnerUserContext();
    GitLabConfiguration gitLabConfig = GitLabConfiguration.newGitLabConfiguration(null, null, null, null, null);
    ProjectStructureConfiguration projectStructureConfig = ProjectStructureConfiguration.emptyConfiguration();
    GitLabProjectApi gitLabProjectApi = new GitLabProjectApi(gitLabConfig, gitLabOwnerUserContext, projectStructureConfig, null, null, backgroundTaskProcessor, null);
    GitLabRevisionApi gitLabRevisionApi = new GitLabRevisionApi(gitLabMemberUserContext, backgroundTaskProcessor);
    GitLabWorkspaceApi gitLabWorkspaceApi = new GitLabWorkspaceApi(gitLabMemberUserContext, gitLabRevisionApi, backgroundTaskProcessor);
    GitLabEntityApi gitLabEntityApi = new GitLabEntityApi(gitLabMemberUserContext, backgroundTaskProcessor);
    GitLabReviewApi gitLabCommitterReviewApi = new GitLabReviewApi(gitLabMemberUserContext);
    GitLabReviewApi gitLabApproverReviewApi = new GitLabReviewApi(gitLabOwnerUserContext);
    gitLabEntityApiTestResource = new GitLabEntityApiTestResource(gitLabProjectApi, gitLabWorkspaceApi, gitLabEntityApi, gitLabCommitterReviewApi, gitLabApproverReviewApi, gitLabMemberUserContext);
}
Also used : GitLabWorkspaceApi(org.finos.legend.sdlc.server.gitlab.api.GitLabWorkspaceApi) GitLabConfiguration(org.finos.legend.sdlc.server.gitlab.GitLabConfiguration) GitLabRevisionApi(org.finos.legend.sdlc.server.gitlab.api.GitLabRevisionApi) GitLabProjectApi(org.finos.legend.sdlc.server.gitlab.api.GitLabProjectApi) GitLabUserContext(org.finos.legend.sdlc.server.gitlab.auth.GitLabUserContext) GitLabEntityApiTestResource(org.finos.legend.sdlc.server.gitlab.api.GitLabEntityApiTestResource) GitLabEntityApi(org.finos.legend.sdlc.server.gitlab.api.GitLabEntityApi) ProjectStructureConfiguration(org.finos.legend.sdlc.server.project.config.ProjectStructureConfiguration) GitLabReviewApi(org.finos.legend.sdlc.server.gitlab.api.GitLabReviewApi)

Example 2 with GitLabUserContext

use of org.finos.legend.sdlc.server.gitlab.auth.GitLabUserContext in project legend-sdlc by finos.

the class IntegrationTestGitLabProjectConfigurationApis method setUpProjectConfigurationApi.

/**
 * Authenticates with OAuth2 and instantiate the test resource.
 */
private static void setUpProjectConfigurationApi() {
    GitLabUserContext gitLabMemberUserContext = prepareGitLabMemberUserContext();
    GitLabUserContext gitLabOwnerUserContext = prepareGitLabOwnerUserContext();
    GitLabConfiguration gitLabConfig = GitLabConfiguration.newGitLabConfiguration(null, null, null, null, null);
    ProjectStructureConfiguration projectStructureConfig = ProjectStructureConfiguration.emptyConfiguration();
    GitLabProjectApi gitLabProjectApi = new GitLabProjectApi(gitLabConfig, gitLabOwnerUserContext, projectStructureConfig, null, null, backgroundTaskProcessor, null);
    GitLabRevisionApi gitLabRevisionApi = new GitLabRevisionApi(gitLabMemberUserContext, backgroundTaskProcessor);
    GitLabWorkspaceApi gitLabWorkspaceApi = new GitLabWorkspaceApi(gitLabMemberUserContext, gitLabRevisionApi, backgroundTaskProcessor);
    GitLabProjectConfigurationApi gitLabProjectConfigurationApi = new GitLabProjectConfigurationApi(gitLabMemberUserContext, projectStructureConfig, projectStructureConfig.getProjectStructureExtensionProvider(), backgroundTaskProcessor, null);
    gitLabProjectConfigurationApiTestResource = new GitLabProjectConfigurationApiTestResource(gitLabWorkspaceApi, gitLabProjectApi, gitLabProjectConfigurationApi);
}
Also used : GitLabWorkspaceApi(org.finos.legend.sdlc.server.gitlab.api.GitLabWorkspaceApi) GitLabConfiguration(org.finos.legend.sdlc.server.gitlab.GitLabConfiguration) GitLabRevisionApi(org.finos.legend.sdlc.server.gitlab.api.GitLabRevisionApi) GitLabProjectConfigurationApiTestResource(org.finos.legend.sdlc.server.gitlab.api.GitLabProjectConfigurationApiTestResource) GitLabProjectApi(org.finos.legend.sdlc.server.gitlab.api.GitLabProjectApi) GitLabUserContext(org.finos.legend.sdlc.server.gitlab.auth.GitLabUserContext) GitLabProjectConfigurationApi(org.finos.legend.sdlc.server.gitlab.api.GitLabProjectConfigurationApi) ProjectStructureConfiguration(org.finos.legend.sdlc.server.project.config.ProjectStructureConfiguration)

Example 3 with GitLabUserContext

use of org.finos.legend.sdlc.server.gitlab.auth.GitLabUserContext in project legend-sdlc by finos.

the class TestGitLabServerProjectApis method setUpProjectApi.

/**
 * Authenticates with OAuth2 and instantiate the test SDLC GitLabProjectApi.
 *
 * @throws LegendSDLCServerException if cannot authenticates to GitLab.
 */
private static void setUpProjectApi() throws LegendSDLCServerException {
    GitLabConfiguration gitLabConfig = GitLabConfiguration.newGitLabConfiguration(null, null, null, null, GitLabConfiguration.NewProjectVisibility.PRIVATE);
    ProjectStructureConfiguration projectStructureConfig = ProjectStructureConfiguration.emptyConfiguration();
    GitLabUserContext gitLabUserContext = prepareGitLabOwnerUserContext();
    GitLabProjectApi gitLabProjectApi = new GitLabProjectApi(gitLabConfig, gitLabUserContext, projectStructureConfig, null, gitLabConfig, backgroundTaskProcessor, null);
    gitLabProjectApiTestResource = new GitLabProjectApiTestResource(gitLabProjectApi);
}
Also used : GitLabConfiguration(org.finos.legend.sdlc.server.gitlab.GitLabConfiguration) GitLabProjectApi(org.finos.legend.sdlc.server.gitlab.api.GitLabProjectApi) GitLabUserContext(org.finos.legend.sdlc.server.gitlab.auth.GitLabUserContext) GitLabProjectApiTestResource(org.finos.legend.sdlc.server.gitlab.api.GitLabProjectApiTestResource) ProjectStructureConfiguration(org.finos.legend.sdlc.server.project.config.ProjectStructureConfiguration)

Example 4 with GitLabUserContext

use of org.finos.legend.sdlc.server.gitlab.auth.GitLabUserContext in project legend-sdlc by finos.

the class GitLabApiTestSetupUtil method prepareGitLabUserContextHelper.

/**
 * Authenticates to GitLab and creates a test GitLabUserContext.
 *
 * @param username   the name of user for whom we create this context.
 * @param password   the password of user for whom we create this context.
 * @param hostUrl    the url of the test host.
 * @param hostScheme the scheme of the test host.
 * @param hostHost   the test host.
 * @param hostPort   the port (if necessary) of the test host.
 */
public static GitLabUserContext prepareGitLabUserContextHelper(String username, String password, String hostUrl, String hostScheme, String hostHost, Integer hostPort) throws LegendSDLCServerException {
    GitLabMode gitLabMode = GitLabMode.PROD;
    TestHttpServletRequest httpServletRequest = new TestHttpServletRequest();
    TestGitLabSession session = new TestGitLabSession(username);
    GitLabApi oauthGitLabApi;
    Version version;
    try {
        oauthGitLabApi = GitLabApi.oauth2Login(hostUrl, username, password, null, null, true);
        Assert.assertNotNull(oauthGitLabApi);
        version = oauthGitLabApi.getVersion();
    } catch (GitLabApiException e) {
        StringBuilder builder = new StringBuilder("Error instantiating GitLabApi via OAuth2; response status: ").append(e.getHttpStatus());
        StringTools.appendThrowableMessageIfPresent(builder, e, "; error message: ");
        if (e.hasValidationErrors()) {
            builder.append("; validation error(s): ").append(e.getValidationErrors());
        }
        throw new LegendSDLCServerException(builder.toString(), e);
    }
    String oauthToken = oauthGitLabApi.getAuthToken();
    LOGGER.info("Retrieved access token: {}", oauthToken);
    Assert.assertNotNull(version);
    GitLabServerInfo gitLabServerInfo = GitLabServerInfo.newServerInfo(hostScheme, hostHost, hostPort);
    GitLabAppInfo gitLabAppInfo = GitLabAppInfo.newAppInfo(gitLabServerInfo, null, null, null);
    GitLabModeInfo gitLabModeInfo = GitLabModeInfo.newModeInfo(gitLabMode, gitLabAppInfo);
    session.setGitLabToken(gitLabMode, oauthToken, TokenType.OAUTH2_ACCESS);
    session.setModeInfo(gitLabModeInfo);
    LegendSDLCWebFilter.setSessionAttributeOnServletRequest(httpServletRequest, session);
    GitLabAuthorizerManager authorizerManager = GitLabAuthorizerManager.newManager(Collections.emptyList());
    return new GitLabUserContext(httpServletRequest, null, authorizerManager);
}
Also used : GitLabServerInfo(org.finos.legend.sdlc.server.gitlab.GitLabServerInfo) GitLabApi(org.gitlab4j.api.GitLabApi) GitLabModeInfo(org.finos.legend.sdlc.server.gitlab.mode.GitLabModeInfo) GitLabAuthorizerManager(org.finos.legend.sdlc.server.gitlab.auth.GitLabAuthorizerManager) GitLabApiException(org.gitlab4j.api.GitLabApiException) TestGitLabSession(org.finos.legend.sdlc.server.gitlab.auth.TestGitLabSession) GitLabAppInfo(org.finos.legend.sdlc.server.gitlab.GitLabAppInfo) LegendSDLCServerException(org.finos.legend.sdlc.server.error.LegendSDLCServerException) Version(org.gitlab4j.api.models.Version) GitLabUserContext(org.finos.legend.sdlc.server.gitlab.auth.GitLabUserContext) GitLabMode(org.finos.legend.sdlc.server.gitlab.mode.GitLabMode)

Example 5 with GitLabUserContext

use of org.finos.legend.sdlc.server.gitlab.auth.GitLabUserContext in project legend-sdlc by finos.

the class IntegrationTestGitLabComparisonApis method setUpComparisonApi.

/**
 * Authenticates with OAuth2 and instantiate the test resource.
 */
private static void setUpComparisonApi() {
    GitLabUserContext gitLabMemberUserContext = prepareGitLabMemberUserContext();
    GitLabUserContext gitLabOwnerUserContext = prepareGitLabOwnerUserContext();
    GitLabConfiguration gitLabConfig = GitLabConfiguration.newGitLabConfiguration(null, null, null, null, null);
    ProjectStructureConfiguration projectStructureConfig = ProjectStructureConfiguration.emptyConfiguration();
    GitLabProjectApi gitLabProjectApi = new GitLabProjectApi(gitLabConfig, gitLabOwnerUserContext, projectStructureConfig, null, null, backgroundTaskProcessor, null);
    GitLabRevisionApi gitLabRevisionApi = new GitLabRevisionApi(gitLabMemberUserContext, backgroundTaskProcessor);
    GitLabWorkspaceApi gitLabWorkspaceApi = new GitLabWorkspaceApi(gitLabMemberUserContext, gitLabRevisionApi, backgroundTaskProcessor);
    GitLabEntityApi gitLabEntityApi = new GitLabEntityApi(gitLabMemberUserContext, backgroundTaskProcessor);
    GitLabComparisonApi gitLabComparisonApi = new GitLabComparisonApi(gitLabMemberUserContext, gitLabRevisionApi, backgroundTaskProcessor);
    gitLabComparisonApiTestResource = new GitLabComparisonApiTestResource(gitLabWorkspaceApi, gitLabProjectApi, gitLabEntityApi, gitLabRevisionApi, gitLabComparisonApi);
}
Also used : GitLabWorkspaceApi(org.finos.legend.sdlc.server.gitlab.api.GitLabWorkspaceApi) GitLabConfiguration(org.finos.legend.sdlc.server.gitlab.GitLabConfiguration) GitLabRevisionApi(org.finos.legend.sdlc.server.gitlab.api.GitLabRevisionApi) GitLabProjectApi(org.finos.legend.sdlc.server.gitlab.api.GitLabProjectApi) GitLabUserContext(org.finos.legend.sdlc.server.gitlab.auth.GitLabUserContext) GitLabEntityApi(org.finos.legend.sdlc.server.gitlab.api.GitLabEntityApi) GitLabComparisonApiTestResource(org.finos.legend.sdlc.server.gitlab.api.GitLabComparisonApiTestResource) ProjectStructureConfiguration(org.finos.legend.sdlc.server.project.config.ProjectStructureConfiguration) GitLabComparisonApi(org.finos.legend.sdlc.server.gitlab.api.GitLabComparisonApi)

Aggregations

GitLabUserContext (org.finos.legend.sdlc.server.gitlab.auth.GitLabUserContext)13 GitLabConfiguration (org.finos.legend.sdlc.server.gitlab.GitLabConfiguration)12 GitLabProjectApi (org.finos.legend.sdlc.server.gitlab.api.GitLabProjectApi)12 ProjectStructureConfiguration (org.finos.legend.sdlc.server.project.config.ProjectStructureConfiguration)12 GitLabRevisionApi (org.finos.legend.sdlc.server.gitlab.api.GitLabRevisionApi)10 GitLabWorkspaceApi (org.finos.legend.sdlc.server.gitlab.api.GitLabWorkspaceApi)10 GitLabEntityApi (org.finos.legend.sdlc.server.gitlab.api.GitLabEntityApi)8 GitLabReviewApi (org.finos.legend.sdlc.server.gitlab.api.GitLabReviewApi)4 GitLabComparisonApi (org.finos.legend.sdlc.server.gitlab.api.GitLabComparisonApi)2 GitLabComparisonApiTestResource (org.finos.legend.sdlc.server.gitlab.api.GitLabComparisonApiTestResource)2 GitLabEntityApiTestResource (org.finos.legend.sdlc.server.gitlab.api.GitLabEntityApiTestResource)2 GitLabProjectApiTestResource (org.finos.legend.sdlc.server.gitlab.api.GitLabProjectApiTestResource)2 GitLabProjectConfigurationApi (org.finos.legend.sdlc.server.gitlab.api.GitLabProjectConfigurationApi)2 GitLabProjectConfigurationApiTestResource (org.finos.legend.sdlc.server.gitlab.api.GitLabProjectConfigurationApiTestResource)2 GitLabRevisionApiTestResource (org.finos.legend.sdlc.server.gitlab.api.GitLabRevisionApiTestResource)2 GitLabWorkspaceApiTestResource (org.finos.legend.sdlc.server.gitlab.api.GitLabWorkspaceApiTestResource)2 LegendSDLCServerException (org.finos.legend.sdlc.server.error.LegendSDLCServerException)1 GitLabAppInfo (org.finos.legend.sdlc.server.gitlab.GitLabAppInfo)1 GitLabServerInfo (org.finos.legend.sdlc.server.gitlab.GitLabServerInfo)1 GitLabAuthorizerManager (org.finos.legend.sdlc.server.gitlab.auth.GitLabAuthorizerManager)1