Skip to content

Commit

Permalink
chore(configs): Do not return bare strings. (#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Duftler committed Nov 2, 2017
1 parent c5dbc97 commit a106361
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2017 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.kayenta.canary;

import lombok.Builder;
import lombok.Data;

import javax.validation.constraints.NotNull;

@Data
@Builder
public class CanaryConfigUpdateResponse {

@NotNull
protected String canaryConfigId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.netflix.kayenta.controllers;

import com.netflix.kayenta.canary.CanaryConfig;
import com.netflix.kayenta.canary.CanaryConfigUpdateResponse;
import com.netflix.kayenta.security.AccountCredentials;
import com.netflix.kayenta.security.AccountCredentialsRepository;
import com.netflix.kayenta.security.CredentialsHelper;
Expand All @@ -38,6 +39,7 @@
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.time.Instant;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.UUID;
Expand Down Expand Up @@ -73,8 +75,8 @@ public CanaryConfig loadCanaryConfig(@RequestParam(required = false) final Strin

@ApiOperation(value = "Write a canary config to object storage")
@RequestMapping(consumes = "application/json", method = RequestMethod.POST)
public String storeCanaryConfig(@RequestParam(required = false) final String configurationAccountName,
@RequestBody CanaryConfig canaryConfig) throws IOException {
public CanaryConfigUpdateResponse storeCanaryConfig(@RequestParam(required = false) final String configurationAccountName,
@RequestBody CanaryConfig canaryConfig) throws IOException {
String resolvedConfigurationAccountName = CredentialsHelper.resolveAccountByNameOrType(configurationAccountName,
AccountCredentials.Type.CONFIGURATION_STORE,
accountCredentialsRepository);
Expand Down Expand Up @@ -119,17 +121,17 @@ public String storeCanaryConfig(@RequestParam(required = false) final String con
} catch (IllegalArgumentException e) {
configurationService.storeObject(resolvedConfigurationAccountName, ObjectType.CANARY_CONFIG, canaryConfigId, canaryConfig, canaryConfig.getName() + ".json", false);

return canaryConfigId;
return CanaryConfigUpdateResponse.builder().canaryConfigId(canaryConfigId).build();
}

throw new IllegalArgumentException("Canary config '" + canaryConfigId + "' already exists.");
}

@ApiOperation(value = "Update a canary config")
@RequestMapping(value = "/{canaryConfigId:.+}", consumes = "application/json", method = RequestMethod.PUT)
public String updateCanaryConfig(@RequestParam(required = false) final String configurationAccountName,
@PathVariable String canaryConfigId,
@RequestBody CanaryConfig canaryConfig) throws IOException {
public CanaryConfigUpdateResponse updateCanaryConfig(@RequestParam(required = false) final String configurationAccountName,
@PathVariable String canaryConfigId,
@RequestBody CanaryConfig canaryConfig) throws IOException {
String resolvedConfigurationAccountName = CredentialsHelper.resolveAccountByNameOrType(configurationAccountName,
AccountCredentials.Type.CONFIGURATION_STORE,
accountCredentialsRepository);
Expand All @@ -153,7 +155,7 @@ public String updateCanaryConfig(@RequestParam(required = false) final String co

configurationService.storeObject(resolvedConfigurationAccountName, ObjectType.CANARY_CONFIG, canaryConfigId, canaryConfig, canaryConfig.getName() + ".json", true);

return canaryConfigId;
return CanaryConfigUpdateResponse.builder().canaryConfigId(canaryConfigId).build();
}

@ApiOperation(value = "Delete a canary config")
Expand Down

0 comments on commit a106361

Please sign in to comment.