|
19 | 19 | import javax.net.ssl.SSLContext;
|
20 | 20 | import oracle.kubernetes.operator.logging.LoggingFacade;
|
21 | 21 | import oracle.kubernetes.operator.logging.LoggingFactory;
|
| 22 | +import oracle.kubernetes.operator.logging.MessageKeys; |
22 | 23 | import oracle.kubernetes.operator.work.Container;
|
23 | 24 | import oracle.kubernetes.operator.work.ContainerResolver;
|
24 | 25 | import org.apache.commons.codec.binary.Base64;
|
@@ -66,18 +67,27 @@ public class RestServer {
|
66 | 67 | }; // ONLY support TLSv1.2 (by default, we would get TLSv1 and TLSv1.1 too)
|
67 | 68 |
|
68 | 69 | public static synchronized void create(RestConfig restConfig) {
|
69 |
| - if (INSTANCE == null) { |
70 |
| - INSTANCE = new RestServer(restConfig); |
| 70 | + LOGGER.entering(); |
| 71 | + try { |
| 72 | + if (INSTANCE == null) { |
| 73 | + INSTANCE = new RestServer(restConfig); |
| 74 | + return; |
| 75 | + } |
| 76 | + |
| 77 | + throw new IllegalStateException(); |
| 78 | + } finally { |
| 79 | + LOGGER.exiting(); |
71 | 80 | }
|
72 |
| - // throw new IllegalStateException(); |
73 | 81 | }
|
74 | 82 |
|
75 | 83 | public static synchronized RestServer getInstance() {
|
76 | 84 | return INSTANCE;
|
77 | 85 | }
|
78 | 86 |
|
79 | 87 | public static void destroy() {
|
| 88 | + LOGGER.entering(); |
80 | 89 | INSTANCE = null;
|
| 90 | + LOGGER.exiting(); |
81 | 91 | }
|
82 | 92 |
|
83 | 93 | /**
|
@@ -185,16 +195,27 @@ public void stop() {
|
185 | 195 | LOGGER.exiting();
|
186 | 196 | }
|
187 | 197 |
|
188 |
| - public String getInternalCertificate() { |
| 198 | + /** |
| 199 | + * Gets the internal https port's certificate as a base64 encoded PEM. |
| 200 | + * |
| 201 | + * @return base64 encoded PEM containing the certificate, or null if unable to read the |
| 202 | + * certificate data. |
| 203 | + */ |
| 204 | + public String getInternalCertificateAsBase64PEM() { |
| 205 | + LOGGER.entering(); |
| 206 | + String internalCert = null; |
189 | 207 | try {
|
190 |
| - return readCertFromDataOrFile( |
191 |
| - this.config.getOperatorInternalCertificateData(), |
192 |
| - this.config.getOperatorInternalCertificateFile()); |
| 208 | + internalCert = |
| 209 | + Base64.encodeBase64String( |
| 210 | + readFromDataOrFile( |
| 211 | + this.config.getOperatorInternalCertificateData(), |
| 212 | + this.config.getOperatorInternalCertificateFile())); |
193 | 213 | } catch (IOException e) {
|
194 |
| - LOGGER.warning("Unable to read internal certificate data", e); |
| 214 | + LOGGER.warning(MessageKeys.EXCEPTION, e); |
195 | 215 | }
|
196 | 216 |
|
197 |
| - return null; |
| 217 | + LOGGER.exiting(internalCert); |
| 218 | + return internalCert; |
198 | 219 | }
|
199 | 220 |
|
200 | 221 | private HttpServer createExternalHttpsServer(Container container) throws Exception {
|
@@ -350,13 +371,6 @@ private KeyManager[] createKeyManagers(
|
350 | 371 | return result;
|
351 | 372 | }
|
352 | 373 |
|
353 |
| - private static String readCertFromDataOrFile(String data, String file) throws IOException { |
354 |
| - if (data != null && data.length() > 0) { |
355 |
| - return data; |
356 |
| - } |
357 |
| - return new String(Files.readAllBytes(new File(file).toPath())); |
358 |
| - } |
359 |
| - |
360 | 374 | private static byte[] readFromDataOrFile(String data, String file) throws IOException {
|
361 | 375 | if (data != null && data.length() > 0) {
|
362 | 376 | return Base64.decodeBase64(data);
|
|
0 commit comments