Search in sources :

Example 1 with Subject

use of io.fabric8.kubernetes.api.model.rbac.Subject in project fabric8 by jboss-fuse.

the class MavenProxySnapshotResolutionTest method snapshotIsAvailableInRemoteRepositoryInNewerVersionUpdateAlways.

@Test
public void snapshotIsAvailableInRemoteRepositoryInNewerVersionUpdateAlways() throws IOException, InvalidMavenArtifactRequest {
    File differentLocalRepository = initFileRepository("dlr");
    File remoteRepository = initFileRepository("rr");
    MavenResolver resolver = new ResolverBuilder().withRemoteRepositories(Collections.singletonList(remoteRepository)).withUpdatePolicy(RepositoryPolicy.UPDATE_POLICY_ALWAYS).build();
    MavenDownloadProxyServlet servlet = new MavenDownloadProxyServlet(resolver, runtime, null, 1, 0);
    servlet.start();
    mvnDeploy(differentLocalRepository, remoteRepository, "io.fabric8.test", "universalis-api", "0.1.0-SNAPSHOT", at("11:00"), "a");
    // first resolution
    servlet.download("io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/maven-metadata.xml");
    servlet.download("io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/universalis-api-20170101.110000-1.jar");
    mvnDeploy(differentLocalRepository, remoteRepository, "io.fabric8.test", "universalis-api", "0.1.0-SNAPSHOT", at("12:00"), "b");
    // second resolution, subject to update policy
    File file = servlet.download("io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/maven-metadata.xml");
    Metadata metadata = readMetadata(file);
    assertThat("Policy forces fetching changed metadata", metadata.getVersioning().getSnapshotVersions().get(0).getVersion(), is("0.1.0-20170101.120000-2"));
    assertTrue(new File(localRepository, "io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/universalis-api-0.1.0-20170101.110000-1.jar").isFile());
    assertFalse(new File(localRepository, "io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/universalis-api-0.1.0-20170101.120000-2.jar").isFile());
    assertTrue(new File(remoteRepository, "io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/universalis-api-0.1.0-20170101.110000-1.jar").isFile());
    assertTrue(new File(remoteRepository, "io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/universalis-api-0.1.0-20170101.120000-2.jar").isFile());
}
Also used : MavenResolver(io.fabric8.maven.MavenResolver) Metadata(org.apache.maven.artifact.repository.metadata.Metadata) File(java.io.File) Test(org.junit.Test)

Example 2 with Subject

use of io.fabric8.kubernetes.api.model.rbac.Subject in project fabric8 by jboss-fuse.

the class MavenProxySnapshotResolutionTest method snapshotIsAvailableInRemoteRepositoryInNewerVersion.

@Test
public void snapshotIsAvailableInRemoteRepositoryInNewerVersion() throws IOException, InvalidMavenArtifactRequest {
    File differentLocalRepository = initFileRepository("dlr");
    File remoteRepository = initFileRepository("rr");
    MavenResolver resolver = new ResolverBuilder().withRemoteRepositories(Collections.singletonList(remoteRepository)).withUpdatePolicy(RepositoryPolicy.UPDATE_POLICY_DAILY).build();
    MavenDownloadProxyServlet servlet = new MavenDownloadProxyServlet(resolver, runtime, null, 1, 0);
    servlet.start();
    mvnDeploy(differentLocalRepository, remoteRepository, "io.fabric8.test", "universalis-api", "0.1.0-SNAPSHOT", at("11:00"), "a");
    // first resolution
    servlet.download("io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/maven-metadata.xml");
    servlet.download("io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/universalis-api-20170101.110000-1.jar");
    mvnDeploy(differentLocalRepository, remoteRepository, "io.fabric8.test", "universalis-api", "0.1.0-SNAPSHOT", at("12:00"), "b");
    // second resolution, subject to update policy
    File file = servlet.download("io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/maven-metadata.xml");
    Metadata metadata = readMetadata(file);
    assertThat("Policy prevents from fetching changed metadata", metadata.getVersioning().getSnapshotVersions().get(0).getVersion(), is("0.1.0-20170101.110000-1"));
    assertTrue(new File(localRepository, "io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/universalis-api-0.1.0-20170101.110000-1.jar").isFile());
    assertFalse(new File(localRepository, "io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/universalis-api-0.1.0-20170101.120000-2.jar").isFile());
    assertTrue(new File(remoteRepository, "io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/universalis-api-0.1.0-20170101.120000-2.jar").isFile());
}
Also used : MavenResolver(io.fabric8.maven.MavenResolver) Metadata(org.apache.maven.artifact.repository.metadata.Metadata) File(java.io.File) Test(org.junit.Test)

Example 3 with Subject

use of io.fabric8.kubernetes.api.model.rbac.Subject in project syndesis-qe by syndesisio.

the class Jaeger method processResources.

private void processResources() {
    for (String jaegerResource : JAEGER_RESOURCES) {
        // version 1.20.0 ==> repo v1.20.0
        jaegerResource = String.format(jaegerResource, "v" + TestConfiguration.jaegerVersion());
        log.info("Processing " + jaegerResource);
        try (InputStream is = new URL(jaegerResource).openStream()) {
            List<HasMetadata> resources = OpenShiftUtils.getInstance().load(is).get();
            // Change the namespace in the resources to the current
            for (HasMetadata resource : resources) {
                if (resource instanceof ClusterRoleBinding) {
                    for (Subject subject : ((ClusterRoleBinding) resource).getSubjects()) {
                        subject.setNamespace(TestConfiguration.openShiftNamespace());
                    }
                }
                resource.getMetadata().setNamespace(TestConfiguration.openShiftNamespace());
                processedResources.add(resource);
                // change docker image to quay
                if (resource instanceof Deployment) {
                    ((Deployment) resource).getSpec().getTemplate().getSpec().getContainers().get(0).setImage("quay.io/jaegertracing/jaeger-operator:" + TestConfiguration.jaegerVersion());
                }
            }
        } catch (IOException e) {
            fail("Unable to process Jaeger resource " + jaegerResource, e);
        }
    }
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) InputStream(java.io.InputStream) ClusterRoleBinding(io.fabric8.kubernetes.api.model.rbac.ClusterRoleBinding) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) IOException(java.io.IOException) URL(java.net.URL) Subject(io.fabric8.kubernetes.api.model.rbac.Subject)

Example 4 with Subject

use of io.fabric8.kubernetes.api.model.rbac.Subject in project strimzi by strimzi.

the class Ca method generateSignedCert.

/**
 * Generates a certificate signed by this CA
 *
 * @param commonName The CN of the certificate to be generated.
 * @param organization The O of the certificate to be generated. May be null.
 * @return The CertAndKey
 * @throws IOException If the cert could not be generated.
 */
public CertAndKey generateSignedCert(String commonName, String organization) throws IOException {
    File csrFile = File.createTempFile("tls", "csr");
    File keyFile = File.createTempFile("tls", "key");
    File certFile = File.createTempFile("tls", "cert");
    File keyStoreFile = File.createTempFile("tls", "p12");
    Subject.Builder subject = new Subject.Builder();
    if (organization != null) {
        subject.withOrganizationName(organization);
    }
    subject.withCommonName(commonName);
    CertAndKey result = generateSignedCert(subject.build(), csrFile, keyFile, certFile, keyStoreFile);
    delete(reconciliation, csrFile);
    delete(reconciliation, keyFile);
    delete(reconciliation, certFile);
    delete(reconciliation, keyStoreFile);
    return result;
}
Also used : CertAndKey(io.strimzi.certs.CertAndKey) DateTimeFormatterBuilder(java.time.format.DateTimeFormatterBuilder) SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) File(java.io.File) Subject(io.strimzi.certs.Subject)

Example 5 with Subject

use of io.fabric8.kubernetes.api.model.rbac.Subject in project strimzi by strimzi.

the class Ca method getSubjectAltNames.

/**
 * Extracts the alternate subject names out of existing certificate
 *
 * @param certificate Existing X509 certificate as a byte array
 * @return
 */
protected List<String> getSubjectAltNames(byte[] certificate) {
    List<String> subjectAltNames = null;
    try {
        X509Certificate cert = x509Certificate(certificate);
        Collection<List<?>> altNames = cert.getSubjectAlternativeNames();
        subjectAltNames = altNames.stream().filter(name -> name.get(1) instanceof String).map(item -> (String) item.get(1)).collect(Collectors.toList());
    } catch (CertificateException | RuntimeException e) {
        // TODO: We should mock the certificates properly so that this doesn't fail in tests (not now => long term :-o)
        LOGGER.debugCr(reconciliation, "Failed to parse existing certificate", e);
    }
    return subjectAltNames;
}
Also used : X509Certificate(java.security.cert.X509Certificate) HOUR_OF_DAY(java.time.temporal.ChronoField.HOUR_OF_DAY) SECOND_OF_MINUTE(java.time.temporal.ChronoField.SECOND_OF_MINUTE) CertificateFactory(java.security.cert.CertificateFactory) Date(java.util.Date) Annotations(io.strimzi.operator.common.Annotations) KeyStoreException(java.security.KeyStoreException) SignStyle(java.time.format.SignStyle) ByteArrayInputStream(java.io.ByteArrayInputStream) IsoChronology(java.time.chrono.IsoChronology) Map(java.util.Map) Collection(java.util.Collection) Set(java.util.Set) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) ZoneId(java.time.ZoneId) Subject(io.strimzi.certs.Subject) Base64(java.util.Base64) List(java.util.List) Certificate(java.security.cert.Certificate) NANO_OF_SECOND(java.time.temporal.ChronoField.NANO_OF_SECOND) PasswordGenerator(io.strimzi.operator.common.PasswordGenerator) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Secret(io.fabric8.kubernetes.api.model.Secret) Optional(java.util.Optional) DateTimeFormatterBuilder(java.time.format.DateTimeFormatterBuilder) CertManager(io.strimzi.certs.CertManager) HashMap(java.util.HashMap) OwnerReference(io.fabric8.kubernetes.api.model.OwnerReference) CertAndKey(io.strimzi.certs.CertAndKey) Function(java.util.function.Function) ArrayList(java.util.ArrayList) YEAR(java.time.temporal.ChronoField.YEAR) Collections.singletonMap(java.util.Collections.singletonMap) CertificateExpirationPolicy(io.strimzi.api.kafka.model.CertificateExpirationPolicy) SecretCertProvider(io.strimzi.certs.SecretCertProvider) ReconciliationLogger(io.strimzi.operator.common.ReconciliationLogger) MONTH_OF_YEAR(java.time.temporal.ChronoField.MONTH_OF_YEAR) Collections.emptyMap(java.util.Collections.emptyMap) Iterator(java.util.Iterator) Files(java.nio.file.Files) MINUTE_OF_HOUR(java.time.temporal.ChronoField.MINUTE_OF_HOUR) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) DAY_OF_MONTH(java.time.temporal.ChronoField.DAY_OF_MONTH) File(java.io.File) Reconciliation(io.strimzi.operator.common.Reconciliation) Util(io.strimzi.operator.common.Util) DateTimeFormatter(java.time.format.DateTimeFormatter) SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) List(java.util.List) ArrayList(java.util.ArrayList) CertificateException(java.security.cert.CertificateException) X509Certificate(java.security.cert.X509Certificate)

Aggregations

Subject (io.fabric8.kubernetes.api.model.rbac.Subject)19 RoleRef (io.fabric8.kubernetes.api.model.rbac.RoleRef)18 RoleRefBuilder (io.fabric8.kubernetes.api.model.rbac.RoleRefBuilder)18 SubjectBuilder (io.fabric8.kubernetes.api.model.rbac.SubjectBuilder)18 SecretBuilder (io.fabric8.kubernetes.api.model.SecretBuilder)14 File (java.io.File)14 CertAndKey (io.strimzi.certs.CertAndKey)12 Subject (io.strimzi.certs.Subject)12 X509Certificate (java.security.cert.X509Certificate)12 Map (java.util.Map)12 IOException (java.io.IOException)11 Secret (io.fabric8.kubernetes.api.model.Secret)10 CertificateExpirationPolicy (io.strimzi.api.kafka.model.CertificateExpirationPolicy)10 CertManager (io.strimzi.certs.CertManager)10 PasswordGenerator (io.strimzi.operator.common.PasswordGenerator)10 Reconciliation (io.strimzi.operator.common.Reconciliation)10 Base64 (java.util.Base64)10 Function (java.util.function.Function)10 RoleBindingBuilder (io.fabric8.kubernetes.api.model.rbac.RoleBindingBuilder)6 ParallelSuite (io.strimzi.test.annotations.ParallelSuite)6