Search in sources :

Example 91 with Repository

use of io.fabric8.agent.model.Repository in project fabric8 by jboss-fuse.

the class AetherBasedResolver method addSubDirs.

private void addSubDirs(List<RemoteRepository> list, File parentDir) {
    if (!parentDir.isDirectory()) {
        LOG.debug("Repository marked with @multi does not resolve to a directory: " + parentDir);
        return;
    }
    for (File repo : parentDir.listFiles()) {
        if (repo.isDirectory()) {
            try {
                String repoURI = repo.toURI().toString() + "@id=" + repo.getName();
                LOG.debug("Adding repo from inside multi dir: " + repoURI);
                addRepo(list, new MavenRepositoryURL(repoURI));
            } catch (MalformedURLException e) {
                LOG.error("Error resolving repo url of a multi repo " + repo.toURI());
            }
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) MavenRepositoryURL(io.fabric8.maven.util.MavenRepositoryURL) File(java.io.File) JarFile(java.util.jar.JarFile)

Example 92 with Repository

use of io.fabric8.agent.model.Repository in project fabric8 by jboss-fuse.

the class OpenShiftPomDeployer method updateRepositories.

/**
 * Ensure that the given maven repositories are added to the pom.xml
 */
protected void updateRepositories(Element repositories, List<MavenRepositoryURL> repos) throws XPathExpressionException {
    for (MavenRepositoryURL repo : repos) {
        String url = repo.getURL().toString();
        String id = repo.getId();
        if (Strings.isNotBlank(url)) {
            Element repository = recreateChild(repositories, "repository[url='" + url + "']", "repository", 2);
            if (Strings.isNotBlank(id)) {
                createAndAppendChild(repository, "id", 3, id);
            }
            createAndAppendChild(repository, "url", 3, url);
            addRepositoryFlag(repository, "releases", repo.isReleasesEnabled());
            addRepositoryFlag(repository, "snapshots", repo.isSnapshotsEnabled());
        }
    }
}
Also used : Element(org.w3c.dom.Element) MavenRepositoryURL(io.fabric8.maven.util.MavenRepositoryURL)

Example 93 with Repository

use of io.fabric8.agent.model.Repository in project fabric8-maven-plugin by fabric8io.

the class ImportMojo method findOrCreateGitSecret.

private Secret findOrCreateGitSecret(KubernetesClient kubernetes, String secretName, String repositoryHost) {
    String secretNamespace = getSecretNamespace();
    ensureNamespaceExists(kubernetes, secretNamespace);
    Secret gogsSecret = kubernetes.secrets().inNamespace(secretNamespace).withName(secretName).get();
    if (gogsSecret == null) {
        // lets create a new secret!
        Map<String, String> labels = new HashMap<>();
        labels.put("provider", "fabric8");
        labels.put("repository", repositoryHost);
        labels.put("scm", "git");
        gogsSecret = new SecretBuilder().withNewMetadata().withName(secretName).withLabels(labels).endMetadata().withData(new HashMap<String, String>()).build();
    }
    return gogsSecret;
}
Also used : Secret(io.fabric8.kubernetes.api.model.Secret) SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) HashMap(java.util.HashMap)

Example 94 with Repository

use of io.fabric8.agent.model.Repository in project halyard by spinnaker.

the class BakeDebianServiceProvider method getInstallCommand.

@Override
public String getInstallCommand(DeploymentDetails deploymentDetails, GenerateService.ResolvedConfiguration resolvedConfiguration, Map<String, String> installCommands, String startupCommand) {
    Map<String, Object> bindings = new HashMap<>();
    List<SpinnakerService.Type> serviceTypes = new ArrayList<>(installCommands.keySet()).stream().map(SpinnakerService.Type::fromCanonicalName).collect(Collectors.toList());
    List<String> upstartNames = getPrioritizedBakeableServices(serviceTypes).stream().filter(i -> resolvedConfiguration.getServiceSettings(i.getService()).getEnabled()).map(i -> ((BakeDebianService) i).getUpstartServiceName()).filter(Objects::nonNull).collect(Collectors.toList());
    List<String> systemdServiceConfigs = upstartNames.stream().map(n -> n + ".service").collect(Collectors.toList());
    List<String> serviceInstalls = serviceTypes.stream().map(t -> installCommands.get(t.getCanonicalName())).collect(Collectors.toList());
    TemplatedResource resource = new StringReplaceJarResource("/debian/init.sh");
    bindings.put("services", Strings.join(upstartNames, " "));
    bindings.put("systemd-service-configs", Strings.join(systemdServiceConfigs, " "));
    String upstartInit = resource.setBindings(bindings).toString();
    BillOfMaterials.ArtifactSources artifactSources = artifactService.getArtifactSources(deploymentDetails.getDeploymentName());
    resource = new StringReplaceJarResource("/debian/pre-bake.sh");
    bindings = new HashMap<>();
    bindings.put("debian-repository", artifactSourcesConfig.mergeWithBomSources(artifactSources).getDebianRepository());
    bindings.put("install-commands", String.join("\n", serviceInstalls));
    bindings.put("upstart-init", upstartInit);
    bindings.put("startup-file", Paths.get(startupScriptPath, "startup.sh").toString());
    bindings.put("startup-command", startupCommand);
    return resource.setBindings(bindings).toString();
}
Also used : DeploymentDetails(com.netflix.spinnaker.halyard.deploy.deployment.v1.DeploymentDetails) ArtifactSourcesConfig(com.netflix.spinnaker.halyard.config.config.v1.ArtifactSourcesConfig) Autowired(org.springframework.beans.factory.annotation.Autowired) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) HashMap(java.util.HashMap) ArtifactService(com.netflix.spinnaker.halyard.deploy.services.v1.ArtifactService) GenerateService(com.netflix.spinnaker.halyard.deploy.services.v1.GenerateService) SpinnakerRuntimeSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings) BakeServiceProvider(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.bake.BakeServiceProvider) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Objects(java.util.Objects) Component(org.springframework.stereotype.Component) List(java.util.List) Paths(java.nio.file.Paths) StringReplaceJarResource(com.netflix.spinnaker.halyard.core.resource.v1.StringReplaceJarResource) Map(java.util.Map) Problem(com.netflix.spinnaker.halyard.core.problem.v1.Problem) RemoteAction(com.netflix.spinnaker.halyard.core.RemoteAction) BillOfMaterials(com.netflix.spinnaker.halyard.core.registry.v1.BillOfMaterials) SpinnakerService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerService) Strings(io.fabric8.utils.Strings) TemplatedResource(com.netflix.spinnaker.halyard.core.resource.v1.TemplatedResource) HashMap(java.util.HashMap) TemplatedResource(com.netflix.spinnaker.halyard.core.resource.v1.TemplatedResource) SpinnakerService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerService) BillOfMaterials(com.netflix.spinnaker.halyard.core.registry.v1.BillOfMaterials) StringReplaceJarResource(com.netflix.spinnaker.halyard.core.resource.v1.StringReplaceJarResource)

Example 95 with Repository

use of io.fabric8.agent.model.Repository in project fabric8 by fabric8io.

the class DevOpsConnector method createGerritRepo.

protected void createGerritRepo(String repoName, String gerritUser, String gerritPwd, String gerritGitInitialCommit, String gerritGitRepoDescription) throws Exception {
    // lets add defaults if not env vars
    if (Strings.isNullOrBlank(gerritUser)) {
        gerritUser = "admin";
    }
    if (Strings.isNullOrBlank(gerritPwd)) {
        gerritPwd = "secret";
    }
    log.info("A Gerrit git repo will be created for this name : " + repoName);
    String gerritAddress = KubernetesHelper.getServiceURL(kubernetes, ServiceNames.GERRIT, namespace, "http", true);
    log.info("Found gerrit address: " + gerritAddress + " for namespace: " + namespace + " on Kubernetes address: " + kubernetes.getMasterUrl());
    if (Strings.isNullOrBlank(gerritAddress)) {
        throw new Exception("No address for service " + ServiceNames.GERRIT + " in namespace: " + namespace + " on Kubernetes address: " + kubernetes.getMasterUrl());
    }
    CloseableHttpClient httpclient = HttpClients.createDefault();
    CloseableHttpClient httpclientPost = HttpClients.createDefault();
    String GERRIT_URL = gerritAddress + "/a/projects/" + repoName;
    HttpGet httpget = new HttpGet(GERRIT_URL);
    System.out.println("Requesting : " + httpget.getURI());
    try {
        // Initial request without credentials returns "HTTP/1.1 401 Unauthorized"
        HttpResponse response = httpclient.execute(httpget);
        System.out.println(response.getStatusLine());
        if (response.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {
            // Get current current "WWW-Authenticate" header from response
            // WWW-Authenticate:Digest realm="My Test Realm", qop="auth",
            // nonce="cdcf6cbe6ee17ae0790ed399935997e8", opaque="ae40d7c8ca6a35af15460d352be5e71c"
            Header authHeader = response.getFirstHeader(AUTH.WWW_AUTH);
            System.out.println("authHeader = " + authHeader);
            DigestScheme digestScheme = new DigestScheme();
            // Parse realm, nonce sent by server.
            digestScheme.processChallenge(authHeader);
            UsernamePasswordCredentials creds = new UsernamePasswordCredentials(gerritUser, gerritPwd);
            httpget.addHeader(digestScheme.authenticate(creds, httpget, null));
            HttpPost httpPost = new HttpPost(GERRIT_URL);
            httpPost.addHeader(digestScheme.authenticate(creds, httpPost, null));
            httpPost.addHeader("Content-Type", "application/json");
            CreateRepositoryDTO createRepoDTO = new CreateRepositoryDTO();
            createRepoDTO.setDescription(gerritGitRepoDescription);
            createRepoDTO.setName(repoName);
            createRepoDTO.setCreate_empty_commit(Boolean.valueOf(gerritGitInitialCommit));
            ObjectMapper mapper = new ObjectMapper();
            String json = mapper.writeValueAsString(createRepoDTO);
            HttpEntity entity = new StringEntity(json);
            httpPost.setEntity(entity);
            ResponseHandler<String> responseHandler = new BasicResponseHandler();
            String responseBody = httpclientPost.execute(httpPost, responseHandler);
            System.out.println("responseBody : " + responseBody);
        }
    } catch (MalformedChallengeException e) {
        e.printStackTrace();
    } catch (AuthenticationException e) {
        e.printStackTrace();
    } catch (ConnectException e) {
        System.out.println("Gerrit Server is not responding");
    } catch (HttpResponseException e) {
        System.out.println("Response from Gerrit Server : " + e.getMessage());
        throw new Exception("Repository " + repoName + " already exists !");
    } finally {
        httpclient.close();
        httpclientPost.close();
    }
}
Also used : DigestScheme(org.apache.http.impl.auth.DigestScheme) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpPost(org.apache.http.client.methods.HttpPost) HttpEntity(org.apache.http.HttpEntity) AuthenticationException(org.apache.http.auth.AuthenticationException) HttpGet(org.apache.http.client.methods.HttpGet) BasicResponseHandler(org.apache.http.impl.client.BasicResponseHandler) HttpResponse(org.apache.http.HttpResponse) MalformedChallengeException(org.apache.http.auth.MalformedChallengeException) HttpResponseException(org.apache.http.client.HttpResponseException) SAXException(org.xml.sax.SAXException) WebApplicationException(javax.ws.rs.WebApplicationException) AuthenticationException(org.apache.http.auth.AuthenticationException) ConnectException(java.net.ConnectException) MalformedChallengeException(org.apache.http.auth.MalformedChallengeException) HttpResponseException(org.apache.http.client.HttpResponseException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) StringEntity(org.apache.http.entity.StringEntity) Header(org.apache.http.Header) CreateRepositoryDTO(io.fabric8.gerrit.CreateRepositoryDTO) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ConnectException(java.net.ConnectException)

Aggregations

File (java.io.File)49 Test (org.junit.Test)32 Git (org.eclipse.jgit.api.Git)30 GitPatchRepository (io.fabric8.patch.management.impl.GitPatchRepository)27 IOException (java.io.IOException)24 GitPatchManagementServiceImpl (io.fabric8.patch.management.impl.GitPatchManagementServiceImpl)20 HashMap (java.util.HashMap)15 ObjectId (org.eclipse.jgit.lib.ObjectId)13 MalformedURLException (java.net.MalformedURLException)11 Map (java.util.Map)11 ArrayList (java.util.ArrayList)10 PatchException (io.fabric8.patch.management.PatchException)9 RevCommit (org.eclipse.jgit.revwalk.RevCommit)8 Bundle (org.osgi.framework.Bundle)8 Version (org.osgi.framework.Version)8 MavenResolver (io.fabric8.maven.MavenResolver)7 HashSet (java.util.HashSet)7 Repository (io.fabric8.agent.model.Repository)6 BundleContext (org.osgi.framework.BundleContext)6 Feature (io.fabric8.agent.model.Feature)5