Skip to content

Commit 5e7f259

Browse files
authored
Fix serialization of secret template (#10)
* Fixed issues where crud operations on secured variables would not work * [feature] Flyway initializer removed from spring autoconfigure * Fixed secret template serializer * Fixed secret template serializer
1 parent 72e52d8 commit 5e7f259

File tree

2 files changed

+11
-31
lines changed

2 files changed

+11
-31
lines changed

src/main/java/org/qubership/integration/platform/variables/management/service/SecretService.java

-4
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,6 @@ public String getSecretTemplate(String secretName) {
9898
throw new SecuredVariablesNotFoundException(SECRET_NOT_FOUND_ERROR_MESSAGE_FORMAT.formatted(secretName));
9999
}
100100

101-
if (foundSecret.getData() == null) {
102-
throw new SecuredVariablesNotFoundException("Secured variables not found");
103-
}
104-
105101
return yamlMapper.writeValueAsString(foundSecret);
106102
} catch (JsonProcessingException e) {
107103
throw new SecuredVariablesException("Failed to get secret helm chart", e);

src/main/java/org/qubership/integration/platform/variables/management/service/serializer/KubeSecretSerializer.java

+11-27
Original file line numberDiff line numberDiff line change
@@ -17,36 +17,30 @@
1717
package org.qubership.integration.platform.variables.management.service.serializer;
1818

1919
import com.fasterxml.jackson.core.JsonGenerator;
20-
import com.fasterxml.jackson.core.type.TypeReference;
21-
import com.fasterxml.jackson.databind.ObjectMapper;
2220
import com.fasterxml.jackson.databind.SerializerProvider;
2321
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
24-
import org.qubership.integration.platform.variables.management.rest.exception.SecuredVariablesException;
2522
import io.kubernetes.client.openapi.models.V1ObjectMeta;
2623
import io.kubernetes.client.openapi.models.V1Secret;
2724
import lombok.extern.slf4j.Slf4j;
2825
import org.apache.commons.collections4.MapUtils;
29-
import org.springframework.beans.factory.annotation.Autowired;
30-
import org.springframework.beans.factory.annotation.Qualifier;
3126
import org.springframework.stereotype.Component;
3227

3328
import java.io.IOException;
29+
import java.util.HashMap;
3430
import java.util.Map;
3531

3632
@Slf4j
3733
@Component
3834
public class KubeSecretSerializer extends StdSerializer<V1Secret> {
3935

40-
private final ObjectMapper objectMapper;
36+
private static final String TEST_VARIABLE_KEY = "test";
4137

42-
@Autowired
43-
public KubeSecretSerializer(@Qualifier("primaryObjectMapper") ObjectMapper objectMapper) {
44-
this(null, objectMapper);
38+
public KubeSecretSerializer() {
39+
this(null);
4540
}
4641

47-
public KubeSecretSerializer(Class<V1Secret> t, @Qualifier("primaryObjectMapper") ObjectMapper objectMapper) {
42+
public KubeSecretSerializer(Class<V1Secret> t) {
4843
super(t);
49-
this.objectMapper = objectMapper;
5044
}
5145

5246
@Override
@@ -75,33 +69,23 @@ public void serialize(V1Secret secret, JsonGenerator jsonGenerator, SerializerPr
7569
}
7670
jsonGenerator.writeEndObject();
7771
}
78-
if (secret.getData() != null) {
79-
writeSecuredVariablesData(jsonGenerator, secret.getData());
80-
}
72+
writeSecuredVariablesData(jsonGenerator, secret.getData());
8173

8274
jsonGenerator.writeEndObject();
8375
}
8476

8577
private void writeSecuredVariablesData(JsonGenerator jsonGenerator, Map<String, byte[]> data) throws IOException {
8678
if (MapUtils.isEmpty(data)) {
87-
return;
79+
data = new HashMap<>();
80+
data.put(TEST_VARIABLE_KEY, new byte[0]);
8881
}
8982

9083
jsonGenerator.writeFieldName(V1Secret.SERIALIZED_NAME_STRING_DATA);
9184
jsonGenerator.writeStartObject();
9285

93-
for (Map.Entry<String, byte[]> dataEntry : data.entrySet()) {
94-
String serializedVariables;
95-
try {
96-
Map<String, String> variables = objectMapper.readValue(new String(dataEntry.getValue()), new TypeReference<>() {});
97-
variables.replaceAll((key, value) -> composeHelmChartExpressionFromKey(key));
98-
serializedVariables = objectMapper.writeValueAsString(variables);
99-
} catch (IOException e) {
100-
log.error("Can't deserialize secured variables for tenant: {}", dataEntry.getKey(), e);
101-
throw new SecuredVariablesException("Can't deserialize secured variables for tenant: " + dataEntry.getKey(), e);
102-
}
103-
104-
jsonGenerator.writeString(serializedVariables);
86+
for (String variableKey : data.keySet()) {
87+
jsonGenerator.writeFieldName(variableKey);
88+
jsonGenerator.writeString(composeHelmChartExpressionFromKey(variableKey));
10589
}
10690
jsonGenerator.writeEndObject();
10791
}

0 commit comments

Comments
 (0)