Skip to content

Commit

Permalink
adds update canary config operation (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpeach committed Jul 20, 2017
1 parent 126f30d commit f81a287
Showing 1 changed file with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public CanaryConfig loadCanaryConfig(@RequestParam(required = false) final Strin
}

@ApiOperation(value = "Write a canary config to object storage")
@RequestMapping(consumes = "application/context+json", method = RequestMethod.POST)
@RequestMapping(consumes = "application/json", method = RequestMethod.POST)
public String storeCanaryConfig(@RequestParam(required = false) final String accountName,
@RequestBody CanaryConfig canaryConfig) throws IOException {
String resolvedAccountName = CredentialsHelper.resolveAccountByNameOrType(accountName,
Expand Down Expand Up @@ -125,6 +125,38 @@ public String storeCanaryConfig(@RequestParam(required = false) final String acc

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 accountName,
@PathVariable String canaryConfigId,
@RequestBody CanaryConfig canaryConfig) throws IOException {
String resolvedAccountName = CredentialsHelper.resolveAccountByNameOrType(accountName,
AccountCredentials.Type.OBJECT_STORE,
accountCredentialsRepository);
StorageService storageService =
storageServiceRepository
.getOne(resolvedAccountName)
.orElseThrow(() -> new IllegalArgumentException("No storage service was configured; unable to write canary config to bucket."));

canaryConfig.setUpdatedTimestamp(System.currentTimeMillis());
canaryConfig.setUpdatedTimestampIso(Instant.ofEpochMilli(canaryConfig.getUpdatedTimestamp()).toString());

canaryConfig.getServices().forEach((serviceName, canaryServiceConfig) -> {
canaryServiceConfig.setName(serviceName);
});

canaryConfigId = canaryConfigId.toLowerCase();

try {
storageService.loadObject(resolvedAccountName, ObjectType.CANARY_CONFIG, canaryConfigId);
} catch (Exception e) {
throw new IllegalArgumentException("Canary config '" + canaryConfigId + "' does not exist.");
}

storageService.storeObject(resolvedAccountName, ObjectType.CANARY_CONFIG, canaryConfigId, canaryConfig);
return canaryConfigId;
}

@ApiOperation(value = "Delete a canary config")
@RequestMapping(value = "/{canaryConfigId:.+}", method = RequestMethod.DELETE)
Expand Down

0 comments on commit f81a287

Please sign in to comment.