Home / Class/ DockerComposeConnectionDetails Class — spring-boot Architecture

DockerComposeConnectionDetails Class — spring-boot Architecture

Architecture documentation for the DockerComposeConnectionDetails class in DockerComposeConnectionDetailsFactory.java from the spring-boot codebase.

Entity Profile

Relationship Graph

Source Code

core/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/DockerComposeConnectionDetailsFactory.java lines 123–250

	protected static class DockerComposeConnectionDetails implements ConnectionDetails, OriginProvider {

		private final @Nullable Origin origin;

		private volatile @Nullable SslBundle sslBundle;

		/**
		 * Create a new {@link DockerComposeConnectionDetails} instance.
		 * @param runningService the source {@link RunningService}
		 */
		protected DockerComposeConnectionDetails(RunningService runningService) {
			Assert.notNull(runningService, "'runningService' must not be null");
			this.origin = Origin.from(runningService);
		}

		@Override
		public @Nullable Origin getOrigin() {
			return this.origin;
		}

		protected @Nullable SslBundle getSslBundle(RunningService service) {
			if (this.sslBundle != null) {
				return this.sslBundle;
			}
			SslBundle jksSslBundle = getJksSslBundle(service);
			SslBundle pemSslBundle = getPemSslBundle(service);
			if (jksSslBundle == null && pemSslBundle == null) {
				return null;
			}
			if (jksSslBundle != null && pemSslBundle != null) {
				throw new IllegalStateException("Mutually exclusive JKS and PEM ssl bundles have been configured");
			}
			SslBundle sslBundle = (jksSslBundle != null) ? jksSslBundle : pemSslBundle;
			this.sslBundle = sslBundle;
			return sslBundle;
		}

		private @Nullable SslBundle getJksSslBundle(RunningService service) {
			JksSslStoreDetails keyStoreDetails = getJksSslStoreDetails(service, "keystore");
			JksSslStoreDetails trustStoreDetails = getJksSslStoreDetails(service, "truststore");
			if (keyStoreDetails == null && trustStoreDetails == null) {
				return null;
			}
			SslBundleKey key = SslBundleKey.of(service.labels().get("org.springframework.boot.sslbundle.jks.key.alias"),
					service.labels().get("org.springframework.boot.sslbundle.jks.key.password"));
			SslOptions options = createSslOptions(
					service.labels().get("org.springframework.boot.sslbundle.jks.options.ciphers"),
					service.labels().get("org.springframework.boot.sslbundle.jks.options.enabled-protocols"));
			String protocol = service.labels().get("org.springframework.boot.sslbundle.jks.protocol");
			Path workingDirectory = getWorkingDirectory(service);
			return SslBundle.of(
					new JksSslStoreBundle(keyStoreDetails, trustStoreDetails, getResourceLoader(workingDirectory)), key,
					options, protocol);
		}

		private ResourceLoader getResourceLoader(@Nullable Path workingDirectory) {
			ClassLoader classLoader = ApplicationResourceLoader.get().getClassLoader();
			return ApplicationResourceLoader.get(classLoader,
					SpringFactoriesLoader.forDefaultResourceLocation(classLoader), workingDirectory);
		}

		private @Nullable JksSslStoreDetails getJksSslStoreDetails(RunningService service, String storeType) {
			String type = service.labels().get("org.springframework.boot.sslbundle.jks.%s.type".formatted(storeType));
			String provider = service.labels()
				.get("org.springframework.boot.sslbundle.jks.%s.provider".formatted(storeType));
			String location = service.labels()
				.get("org.springframework.boot.sslbundle.jks.%s.location".formatted(storeType));
			String password = service.labels()
				.get("org.springframework.boot.sslbundle.jks.%s.password".formatted(storeType));
			if (location == null) {
				return null;
			}
			return new JksSslStoreDetails(type, provider, location, password);
		}

		private @Nullable Path getWorkingDirectory(RunningService runningService) {
			DockerComposeFile composeFile = runningService.composeFile();
			if (composeFile == null || CollectionUtils.isEmpty(composeFile.getFiles())) {
				return Path.of(".");
			}
			return composeFile.getFiles().get(0).toPath().getParent();
		}

		private SslOptions createSslOptions(@Nullable String ciphers, @Nullable String enabledProtocols) {
			Set<String> ciphersSet = null;
			if (StringUtils.hasLength(ciphers)) {
				ciphersSet = StringUtils.commaDelimitedListToSet(ciphers);
			}
			Set<String> enabledProtocolsSet = null;
			if (StringUtils.hasLength(enabledProtocols)) {
				enabledProtocolsSet = StringUtils.commaDelimitedListToSet(enabledProtocols);
			}
			return SslOptions.of(ciphersSet, enabledProtocolsSet);
		}

		private @Nullable SslBundle getPemSslBundle(RunningService service) {
			PemSslStoreDetails keyStoreDetails = getPemSslStoreDetails(service, "keystore");
			PemSslStoreDetails trustStoreDetails = getPemSslStoreDetails(service, "truststore");
			if (keyStoreDetails == null && trustStoreDetails == null) {
				return null;
			}
			SslBundleKey key = SslBundleKey.of(service.labels().get("org.springframework.boot.sslbundle.pem.key.alias"),
					service.labels().get("org.springframework.boot.sslbundle.pem.key.password"));
			SslOptions options = createSslOptions(
					service.labels().get("org.springframework.boot.sslbundle.pem.options.ciphers"),
					service.labels().get("org.springframework.boot.sslbundle.pem.options.enabled-protocols"));
			String protocol = service.labels().get("org.springframework.boot.sslbundle.pem.protocol");
			Path workingDirectory = getWorkingDirectory(service);
			ResourceLoader resourceLoader = getResourceLoader(workingDirectory);
			return SslBundle.of(new PemSslStoreBundle(PemSslStore.load(keyStoreDetails, resourceLoader),
					PemSslStore.load(trustStoreDetails, resourceLoader)), key, options, protocol);
		}

		private @Nullable PemSslStoreDetails getPemSslStoreDetails(RunningService service, String storeType) {
			String type = service.labels().get("org.springframework.boot.sslbundle.pem.%s.type".formatted(storeType));
			String certificate = service.labels()
				.get("org.springframework.boot.sslbundle.pem.%s.certificate".formatted(storeType));
			String privateKey = service.labels()
				.get("org.springframework.boot.sslbundle.pem.%s.private-key".formatted(storeType));
			String privateKeyPassword = service.labels()
				.get("org.springframework.boot.sslbundle.pem.%s.private-key-password".formatted(storeType));
			if (certificate == null && privateKey == null) {
				return null;
			}
			return new PemSslStoreDetails(type, certificate, privateKey, privateKeyPassword);
		}

	}

Domain

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free