diff --git a/gate-core/src/main/groovy/com/netflix/spinnaker/gate/model/manageddelivery/RawDeliveryConfig.java b/gate-core/src/main/groovy/com/netflix/spinnaker/gate/model/manageddelivery/RawDeliveryConfig.java new file mode 100644 index 0000000000..9f7a471f96 --- /dev/null +++ b/gate-core/src/main/groovy/com/netflix/spinnaker/gate/model/manageddelivery/RawDeliveryConfig.java @@ -0,0 +1,27 @@ +/* + * Copyright 2019 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.netflix.spinnaker.gate.model.manageddelivery; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.Data; +import lombok.NonNull; + +@Data +@JsonIgnoreProperties(ignoreUnknown = true) +public class RawDeliveryConfig { + @NonNull String content; +} diff --git a/gate-core/src/main/java/com/netflix/spinnaker/gate/services/internal/KeelService.java b/gate-core/src/main/java/com/netflix/spinnaker/gate/services/internal/KeelService.java index 37b76efa4f..e2121cf036 100644 --- a/gate-core/src/main/java/com/netflix/spinnaker/gate/services/internal/KeelService.java +++ b/gate-core/src/main/java/com/netflix/spinnaker/gate/services/internal/KeelService.java @@ -24,6 +24,7 @@ import com.netflix.spinnaker.gate.model.manageddelivery.EnvironmentArtifactVeto; import com.netflix.spinnaker.gate.model.manageddelivery.GraphQLRequest; import com.netflix.spinnaker.gate.model.manageddelivery.OverrideVerificationRequest; +import com.netflix.spinnaker.gate.model.manageddelivery.RawDeliveryConfig; import com.netflix.spinnaker.gate.model.manageddelivery.Resource; import com.netflix.spinnaker.gate.model.manageddelivery.RetryVerificationRequest; import com.netflix.spinnaker.kork.plugins.SpinnakerPluginDescriptor; @@ -79,9 +80,9 @@ List> getResourceEvents( @GET("/delivery-configs/{name}/artifacts") List> getManifestArtifacts(@Path("name") String name); - @POST("/delivery-configs") + @POST("/delivery-configs/upsertGate") @Headers("Accept: application/json") - DeliveryConfig upsertManifest(@Body DeliveryConfig manifest); + DeliveryConfig upsertManifest(@Body RawDeliveryConfig req); @DELETE("/delivery-configs/{name}") DeliveryConfig deleteManifest(@Path("name") String name); diff --git a/gate-web/src/main/groovy/com/netflix/spinnaker/gate/controllers/ManagedController.java b/gate-web/src/main/groovy/com/netflix/spinnaker/gate/controllers/ManagedController.java index bd43971857..ccf11e9ace 100644 --- a/gate-web/src/main/groovy/com/netflix/spinnaker/gate/controllers/ManagedController.java +++ b/gate-web/src/main/groovy/com/netflix/spinnaker/gate/controllers/ManagedController.java @@ -10,6 +10,7 @@ import com.netflix.spinnaker.gate.model.manageddelivery.EnvironmentArtifactVeto; import com.netflix.spinnaker.gate.model.manageddelivery.GraphQLRequest; import com.netflix.spinnaker.gate.model.manageddelivery.OverrideVerificationRequest; +import com.netflix.spinnaker.gate.model.manageddelivery.RawDeliveryConfig; import com.netflix.spinnaker.gate.model.manageddelivery.Resource; import com.netflix.spinnaker.gate.model.manageddelivery.RetryVerificationRequest; import com.netflix.spinnaker.gate.services.NotificationService; @@ -20,13 +21,17 @@ import io.github.resilience4j.retry.RetryRegistry; import io.swagger.annotations.ApiOperation; import java.io.IOException; +import java.io.InputStream; +import java.io.StringWriter; import java.nio.charset.StandardCharsets; import java.time.Duration; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; + import lombok.SneakyThrows; +import org.apache.commons.io.IOUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -194,16 +199,19 @@ List> getManifestArtifacts(@PathVariable("name") String name @SneakyThrows @ApiOperation( - value = "Create or update a delivery config manifest", - response = DeliveryConfig.class) + value = "Create or update a delivery config manifest", + response = DeliveryConfig.class) @PostMapping( - path = "/delivery-configs", - consumes = {APPLICATION_JSON_VALUE, APPLICATION_YAML_VALUE}, - produces = {APPLICATION_JSON_VALUE}) - DeliveryConfig upsertManifest(@RequestBody DeliveryConfig manifest) { + path = "/delivery-configs", + consumes = {APPLICATION_JSON_VALUE, APPLICATION_YAML_VALUE}, + produces = {APPLICATION_JSON_VALUE}) + DeliveryConfig upsertManifestRaw(InputStream body) { + StringWriter writer = new StringWriter(); + IOUtils.copy(body, writer, StandardCharsets.UTF_8); + RawDeliveryConfig config = new RawDeliveryConfig(writer.toString()); return retryRegistry - .retry("managed-write") - .executeCallable(() -> keelService.upsertManifest(manifest)); + .retry("managed-write") + .executeCallable(() -> keelService.upsertManifest(config)); } @ApiOperation(value = "Delete a delivery config manifest", response = DeliveryConfig.class)