Search in sources :

Example 11 with FileContentProvider

use of org.eclipse.che.api.workspace.server.devfile.FileContentProvider in project che-server by eclipse-che.

the class BitbucketServerAuthorizingFactoryParametersResolver method createFactory.

/**
 * Create factory object based on provided parameters
 *
 * @param factoryParameters map containing factory data parameters provided through URL
 * @throws BadRequestException when data are invalid
 */
@Override
public FactoryMetaDto createFactory(@NotNull final Map<String, String> factoryParameters) throws ApiException {
    // no need to check null value of url parameter as accept() method has performed the check
    final BitbucketUrl bitbucketUrl = bitbucketURLParser.parse(factoryParameters.get(URL_PARAMETER_NAME));
    final FileContentProvider fileContentProvider = new BitbucketServerAuthorizingFileContentProvider(bitbucketUrl, urlFetcher, gitCredentialManager, personalAccessTokenManager);
    // create factory from the following location if location exists, else create default factory
    return urlFactoryBuilder.createFactoryFromDevfile(bitbucketUrl, fileContentProvider, extractOverrideParams(factoryParameters)).orElseGet(() -> newDto(FactoryDto.class).withV(CURRENT_VERSION).withSource("repo")).acceptVisitor(new BitbucketFactoryVisitor(bitbucketUrl));
}
Also used : FileContentProvider(org.eclipse.che.api.workspace.server.devfile.FileContentProvider)

Example 12 with FileContentProvider

use of org.eclipse.che.api.workspace.server.devfile.FileContentProvider in project devspaces-images by redhat-developer.

the class BitbucketServerAuthorizingFactoryParametersResolver method createFactory.

/**
 * Create factory object based on provided parameters
 *
 * @param factoryParameters map containing factory data parameters provided through URL
 * @throws BadRequestException when data are invalid
 */
@Override
public FactoryMetaDto createFactory(@NotNull final Map<String, String> factoryParameters) throws ApiException {
    // no need to check null value of url parameter as accept() method has performed the check
    final BitbucketUrl bitbucketUrl = bitbucketURLParser.parse(factoryParameters.get(URL_PARAMETER_NAME));
    final FileContentProvider fileContentProvider = new BitbucketServerAuthorizingFileContentProvider(bitbucketUrl, urlFetcher, gitCredentialManager, personalAccessTokenManager);
    // create factory from the following location if location exists, else create default factory
    return urlFactoryBuilder.createFactoryFromDevfile(bitbucketUrl, fileContentProvider, extractOverrideParams(factoryParameters)).orElseGet(() -> newDto(FactoryDto.class).withV(CURRENT_VERSION).withSource("repo")).acceptVisitor(new BitbucketFactoryVisitor(bitbucketUrl));
}
Also used : FileContentProvider(org.eclipse.che.api.workspace.server.devfile.FileContentProvider)

Example 13 with FileContentProvider

use of org.eclipse.che.api.workspace.server.devfile.FileContentProvider in project devspaces-images by redhat-developer.

the class GithubAuthorizingFileContentProviderTest method shouldPreserveAbsolutePaths.

@Test
public void shouldPreserveAbsolutePaths() throws Exception {
    URLFetcher urlFetcher = Mockito.mock(URLFetcher.class);
    GithubUrl githubUrl = new GithubUrl().withUsername("eclipse").withRepository("che");
    FileContentProvider fileContentProvider = new GithubAuthorizingFileContentProvider(githubUrl, urlFetcher, gitCredentialManager, personalAccessTokenManager);
    String url = "https://raw.githubusercontent.com/foo/bar/devfile.yaml";
    fileContentProvider.fetchContent(url);
    verify(urlFetcher).fetch(eq(url));
}
Also used : FileContentProvider(org.eclipse.che.api.workspace.server.devfile.FileContentProvider) URLFetcher(org.eclipse.che.api.workspace.server.devfile.URLFetcher) Test(org.testng.annotations.Test)

Example 14 with FileContentProvider

use of org.eclipse.che.api.workspace.server.devfile.FileContentProvider in project devspaces-images by redhat-developer.

the class GithubAuthorizingFileContentProviderTest method shouldThrowNotFoundForPublicRepos.

@Test(expectedExceptions = FileNotFoundException.class)
public void shouldThrowNotFoundForPublicRepos() throws Exception {
    URLFetcher urlFetcher = Mockito.mock(URLFetcher.class);
    String url = "https://raw.githubusercontent.com/foo/bar/devfile.yaml";
    when(urlFetcher.fetch(eq(url))).thenThrow(FileNotFoundException.class);
    when(urlFetcher.fetch(eq("https://api.github.com/repos/eclipse/che"))).thenReturn("OK");
    GithubUrl githubUrl = new GithubUrl().withUsername("eclipse").withRepository("che");
    FileContentProvider fileContentProvider = new GithubAuthorizingFileContentProvider(githubUrl, urlFetcher, gitCredentialManager, personalAccessTokenManager);
    fileContentProvider.fetchContent(url);
}
Also used : FileContentProvider(org.eclipse.che.api.workspace.server.devfile.FileContentProvider) URLFetcher(org.eclipse.che.api.workspace.server.devfile.URLFetcher) Test(org.testng.annotations.Test)

Example 15 with FileContentProvider

use of org.eclipse.che.api.workspace.server.devfile.FileContentProvider in project devspaces-images by redhat-developer.

the class GitlabAuthorizingFileContentProviderTest method shouldPreserveAbsolutePaths.

@Test
public void shouldPreserveAbsolutePaths() throws Exception {
    URLFetcher urlFetcher = Mockito.mock(URLFetcher.class);
    GitlabUrl gitlabUrl = new GitlabUrl().withHostName("gitlab.net").withUsername("eclipse").withProject("che");
    FileContentProvider fileContentProvider = new GitlabAuthorizingFileContentProvider(gitlabUrl, urlFetcher, gitCredentialsManager, personalAccessTokenManager);
    String url = "https://gitlab.net/api/v4/projects/eclipse%2Fche/repository/files/devfile.yaml/raw";
    fileContentProvider.fetchContent(url);
    verify(urlFetcher).fetch(eq(url));
}
Also used : FileContentProvider(org.eclipse.che.api.workspace.server.devfile.FileContentProvider) URLFetcher(org.eclipse.che.api.workspace.server.devfile.URLFetcher) Test(org.testng.annotations.Test)

Aggregations

FileContentProvider (org.eclipse.che.api.workspace.server.devfile.FileContentProvider)38 Test (org.testng.annotations.Test)30 DevfileImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl)18 WorkspaceConfigImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl)14 URLFetcher (org.eclipse.che.api.workspace.server.devfile.URLFetcher)10 DevfileException (org.eclipse.che.api.workspace.server.devfile.exception.DevfileException)8 ComponentImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl)8 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)6 Inject (javax.inject.Inject)6 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)4 HashMap (java.util.HashMap)4 List (java.util.List)4 Named (javax.inject.Named)4 DevfileLocation (org.eclipse.che.api.factory.server.urlfactory.RemoteFactoryUrl.DevfileLocation)4 EDITOR_COMPONENT_TYPE (org.eclipse.che.api.workspace.server.devfile.Constants.EDITOR_COMPONENT_TYPE)4 ComponentFQNParser (org.eclipse.che.api.workspace.server.devfile.convert.component.ComponentFQNParser)4 ExtendedPluginFQN (org.eclipse.che.api.workspace.server.wsplugins.model.ExtendedPluginFQN)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 String.format (java.lang.String.format)3 ComponentToWorkspaceApplier (org.eclipse.che.api.workspace.server.devfile.convert.component.ComponentToWorkspaceApplier)3