-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
574 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...anager/client/src/main/java/io/fabric8/certmanager/client/V1APIGroupExtensionAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* Copyright (C) 2015 Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.fabric8.certmanager.client; | ||
|
||
import io.fabric8.kubernetes.client.APIGroupExtensionAdapter; | ||
import io.fabric8.kubernetes.client.Client; | ||
import okhttp3.OkHttpClient; | ||
|
||
public class V1APIGroupExtensionAdapter extends APIGroupExtensionAdapter<V1APIGroupClient> { | ||
@Override | ||
protected String getAPIGroupName() { | ||
return "v1"; | ||
} | ||
|
||
@Override | ||
public Class<V1APIGroupClient> getExtensionType() { | ||
return V1APIGroupClient.class; | ||
} | ||
|
||
@Override | ||
protected V1APIGroupClient newInstance(Client client) { | ||
return new V1APIGroupClient(client.adapt(OkHttpClient.class), client.getConfiguration()); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
.../client/src/main/java/io/fabric8/certmanager/client/V1alpha2APIGroupExtensionAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* Copyright (C) 2015 Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.fabric8.certmanager.client; | ||
|
||
import io.fabric8.kubernetes.client.APIGroupExtensionAdapter; | ||
import io.fabric8.kubernetes.client.Client; | ||
import okhttp3.OkHttpClient; | ||
|
||
public class V1alpha2APIGroupExtensionAdapter extends APIGroupExtensionAdapter<V1alpha2APIGroupClient> { | ||
@Override | ||
protected String getAPIGroupName() { | ||
return "v1alpha2"; | ||
} | ||
|
||
@Override | ||
public Class<V1alpha2APIGroupClient> getExtensionType() { | ||
return V1alpha2APIGroupClient.class; | ||
} | ||
|
||
@Override | ||
protected V1alpha2APIGroupClient newInstance(Client client) { | ||
return new V1alpha2APIGroupClient(client.adapt(OkHttpClient.class), client.getConfiguration()); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
.../client/src/main/java/io/fabric8/certmanager/client/V1alpha3APIGroupExtensionAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* Copyright (C) 2015 Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.fabric8.certmanager.client; | ||
|
||
import io.fabric8.kubernetes.client.APIGroupExtensionAdapter; | ||
import io.fabric8.kubernetes.client.Client; | ||
import okhttp3.OkHttpClient; | ||
|
||
public class V1alpha3APIGroupExtensionAdapter extends APIGroupExtensionAdapter<V1alpha3APIGroupClient> { | ||
@Override | ||
protected String getAPIGroupName() { | ||
return "v1alpha3"; | ||
} | ||
|
||
@Override | ||
public Class<V1alpha3APIGroupClient> getExtensionType() { | ||
return V1alpha3APIGroupClient.class; | ||
} | ||
|
||
@Override | ||
protected V1alpha3APIGroupClient newInstance(Client client) { | ||
return new V1alpha3APIGroupClient(client.adapt(OkHttpClient.class), client.getConfiguration()); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...r/client/src/main/java/io/fabric8/certmanager/client/V1beta1APIGroupExtensionAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* Copyright (C) 2015 Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.fabric8.certmanager.client; | ||
|
||
import io.fabric8.kubernetes.client.APIGroupExtensionAdapter; | ||
import io.fabric8.kubernetes.client.Client; | ||
import okhttp3.OkHttpClient; | ||
|
||
public class V1beta1APIGroupExtensionAdapter extends APIGroupExtensionAdapter<V1beta1APIGroupClient> { | ||
@Override | ||
protected String getAPIGroupName() { | ||
return "v1beta1"; | ||
} | ||
|
||
@Override | ||
public Class<V1beta1APIGroupClient> getExtensionType() { | ||
return V1beta1APIGroupClient.class; | ||
} | ||
|
||
@Override | ||
protected V1beta1APIGroupClient newInstance(Client client) { | ||
return new V1beta1APIGroupClient(client.adapt(OkHttpClient.class), client.getConfiguration()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...ons/certmanager/examples/src/main/java/io/fabric8/certmanager/examples/ClientFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** | ||
* Copyright (C) 2015 Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.fabric8.certmanager.examples; | ||
|
||
import io.fabric8.certmanager.client.CertManagerClient; | ||
import io.fabric8.certmanager.client.DefaultCertManagerClient; | ||
import io.fabric8.kubernetes.client.ConfigBuilder; | ||
|
||
public class ClientFactory { | ||
|
||
public static CertManagerClient newClient(String[] args) { | ||
ConfigBuilder config = new ConfigBuilder(); | ||
for (int i = 0; i < args.length - 1; i++) { | ||
|
||
String key = args[i]; | ||
String value = args[i + 1]; | ||
|
||
if (key.equals("--api-server")) { | ||
config = config.withMasterUrl(value); | ||
} | ||
|
||
if (key.equals("--token")) { | ||
config = config.withOauthToken(value); | ||
} | ||
|
||
if (key.equals("--username")) { | ||
config = config.withUsername(value); | ||
} | ||
|
||
if (key.equals("--password")) { | ||
config = config.withPassword(value); | ||
} | ||
if (key.equals("--namespace")) { | ||
config = config.withNamespace(value); | ||
} | ||
} | ||
return new DefaultCertManagerClient(config.build()); | ||
} | ||
|
||
public static String getOptions(String args[], String name, String defaultValue) { | ||
for (int i = 0; i < args.length - 1; i++) { | ||
String key = args[i]; | ||
String value = args[i + 1]; | ||
if (key.equals(name)) { | ||
return value; | ||
} | ||
} | ||
return defaultValue; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
...rtmanager/tests/src/test/java/io/fabric8/certmanager/test/crud/V1CertificateCrudTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/** | ||
* Copyright (C) 2015 Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.fabric8.certmanager.test.crud; | ||
|
||
import io.fabric8.certmanager.api.model.v1.Certificate; | ||
import io.fabric8.certmanager.api.model.v1.CertificateBuilder; | ||
import io.fabric8.certmanager.api.model.v1.CertificateList; | ||
import io.fabric8.certmanager.client.CertManagerClient; | ||
import io.fabric8.certmanager.server.mock.CertManagerServer; | ||
import org.junit.Rule; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.migrationsupport.rules.EnableRuleMigrationSupport; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.util.Arrays; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
@EnableRuleMigrationSupport | ||
class V1CertificateCrudTest { | ||
|
||
@Rule | ||
public CertManagerServer server = new CertManagerServer(true, true); | ||
|
||
@Test | ||
void shouldReturnEmptyList() { | ||
CertManagerClient client = server.get(); | ||
CertificateList certificateList = client.v1().certificates().inNamespace("ns1").list(); | ||
assertNotNull(certificateList); | ||
assertTrue(certificateList.getItems().isEmpty()); | ||
} | ||
|
||
@Test | ||
void shouldListAndGetCertificate() { | ||
CertManagerClient client = server.get(); | ||
Certificate certificate2 = new CertificateBuilder().withNewMetadata().withName("cert2").endMetadata().build(); | ||
client.v1().certificates().inNamespace("ns2").create(certificate2); | ||
CertificateList certificateList = client.v1().certificates().inNamespace("ns2").list(); | ||
assertNotNull(certificateList); | ||
assertEquals(1, certificateList.getItems().size()); | ||
} | ||
|
||
@Test | ||
void shouldDeleteACertificate() { | ||
CertManagerClient client = server.get(); | ||
Certificate certificate3 = new CertificateBuilder().withNewMetadata().withName("cert3").endMetadata().build(); | ||
client.v1().certificates().inNamespace("ns3").create(certificate3); | ||
Boolean deleted = client.v1().certificates().inNamespace("ns3").withName("cert3").delete(); | ||
assertTrue(deleted); | ||
} | ||
|
||
@Test | ||
void shouldLoadCertificate() { | ||
CertManagerClient client = server.get(); | ||
String certificateDefinition = String.join("\n", Arrays.asList( | ||
"apiVersion: cert-manager.io/v1beta1", | ||
"kind: Certificate", | ||
"metadata:", | ||
" name: ca-issuer", | ||
"spec:", | ||
" isCA: true", | ||
" secretName: ca-key-pair", | ||
" commonName: my-csi-app", | ||
" issuerRef:", | ||
" name: selfsigned-issuer", | ||
" kind: Issuer", | ||
" group: cert-manager.io" | ||
)); | ||
io.fabric8.certmanager.api.model.v1beta1.Certificate certificate = client.v1beta1().certificates().inNamespace("ns4").load(new ByteArrayInputStream(certificateDefinition.getBytes())).createOrReplace(); | ||
assertEquals("ca-issuer", certificate.getMetadata().getName()); | ||
assertEquals("ca-key-pair", certificate.getSpec().getSecretName()); | ||
assertEquals("my-csi-app", certificate.getSpec().getCommonName()); | ||
} | ||
|
||
} |
Oops, something went wrong.