Skip to content

Commit

Permalink
fix(bake/rosco): fix regression in snake casing of rosco specific bak…
Browse files Browse the repository at this point in the history
…e properties (#2926)
  • Loading branch information
cfieber committed May 20, 2019
1 parent 5fe370d commit dac2670
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ package com.netflix.spinnaker.orca.bakery.api

import com.fasterxml.jackson.annotation.JsonAnyGetter
import com.fasterxml.jackson.annotation.JsonAnySetter
import com.fasterxml.jackson.annotation.JsonIgnore
import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.databind.PropertyNamingStrategy
import static com.fasterxml.jackson.databind.PropertyNamingStrategy.*
import com.netflix.spinnaker.kork.artifacts.model.Artifact
import groovy.transform.CompileStatic
Expand Down Expand Up @@ -66,14 +66,19 @@ class BakeRequest {
@JsonInclude(JsonInclude.Include.NON_NULL)
Integer rootVolumeSize

@JsonAnySetter
@JsonIgnore
Map<String, Object> other = new HashMap<>()

@JsonAnyGetter
public Map<String, Object> other() {
return other
}

@JsonAnySetter
public void set(String name, Object value) {
other.put(namingStrategy.translate(name), value)
}

static enum CloudProviderType {
aws, azure, docker, gce, openstack, titus, oracle
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import retrofit.RequestInterceptor

import java.text.SimpleDateFormat
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.PropertyNamingStrategy.LowerCaseWithUnderscoresStrategy
import com.fasterxml.jackson.databind.PropertyNamingStrategy.SnakeCaseStrategy
import com.netflix.spinnaker.orca.bakery.api.BakeryService
import com.netflix.spinnaker.orca.config.OrcaConfiguration
import com.netflix.spinnaker.orca.retrofit.RetrofitConfiguration
Expand Down Expand Up @@ -63,20 +63,24 @@ class BakeryConfiguration {

@Bean
BakeryService bakery(Endpoint bakeryEndpoint) {
def objectMapper = new ObjectMapper()
.setPropertyNamingStrategy(new LowerCaseWithUnderscoresStrategy())
.setDateFormat(new SimpleDateFormat("YYYYMMDDHHmm"))
.setSerializationInclusion(NON_NULL)
.disable(FAIL_ON_UNKNOWN_PROPERTIES)

new RestAdapter.Builder()
.setEndpoint(bakeryEndpoint)
.setRequestInterceptor(spinnakerRequestInterceptor)
.setConverter(new JacksonConverter(objectMapper))
.setConverter(new JacksonConverter(bakeryConfiguredObjectMapper()))
.setClient(retrofitClient)
.setLogLevel(retrofitLogLevel)
.setLog(new RetrofitSlf4jLog(BakeryService))
.build()
.create(BakeryService)
}

static ObjectMapper bakeryConfiguredObjectMapper() {
def objectMapper = new ObjectMapper()
.setPropertyNamingStrategy(new SnakeCaseStrategy())
.setDateFormat(new SimpleDateFormat("YYYYMMDDHHmm"))
.setSerializationInclusion(NON_NULL)
.disable(FAIL_ON_UNKNOWN_PROPERTIES)

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.netflix.spinnaker.orca.bakery.api

import com.fasterxml.jackson.databind.SerializationFeature
import com.netflix.spinnaker.orca.bakery.config.BakeryConfiguration
import spock.lang.Specification


class BakeRequestSpec extends Specification {

def "it snakes the other"() {
given:
def json = '''\
{
"templateFileLocation": "C:/windows/system32",
"extendedAttributes": {
"a_snake_attribute": "hiss",
"aCamelAttribute": "humps"
}
}'''.stripIndent()
def mapper = BakeryConfiguration.bakeryConfiguredObjectMapper().enable(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS)
def bakeReq = mapper.readValue(json, BakeRequest)

when:
def output = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(bakeReq).trim()

then:
output == '''\
{
"extended_attributes" : {
"aCamelAttribute" : "humps",
"a_snake_attribute" : "hiss"
},
"template_file_location" : "C:/windows/system32"
}'''.stripIndent()
}

}

0 comments on commit dac2670

Please sign in to comment.