|
| 1 | +/* |
| 2 | + * Copyright 2012-2020 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.springframework.boot.buildpack.platform.docker.configuration; |
| 18 | + |
| 19 | +import com.fasterxml.jackson.core.JsonProcessingException; |
| 20 | + |
| 21 | +import org.springframework.boot.buildpack.platform.json.SharedObjectMapper; |
| 22 | +import org.springframework.util.Base64Utils; |
| 23 | + |
| 24 | +/** |
| 25 | + * {@link DockerRegistryAuthentication} that uses creates a Base64 encoded auth header |
| 26 | + * value based on the JSON created from the instance. |
| 27 | + * |
| 28 | + * @author Scott Frederick |
| 29 | + */ |
| 30 | +class JsonEncodedDockerRegistryAuthentication implements DockerRegistryAuthentication { |
| 31 | + |
| 32 | + @Override |
| 33 | + public String createAuthHeader() { |
| 34 | + try { |
| 35 | + return Base64Utils.encodeToUrlSafeString(SharedObjectMapper.get().writeValueAsBytes(this)); |
| 36 | + } |
| 37 | + catch (JsonProcessingException ex) { |
| 38 | + throw new IllegalStateException("Error creating Docker registry authentication header", ex); |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | +} |
0 commit comments