From 8bc6de7e890fdc97758d634cd6060a4c43897cd6 Mon Sep 17 00:00:00 2001 From: Ryan Brandt Date: Tue, 21 Jul 2015 11:42:04 -0600 Subject: [PATCH] Require all fields in an alarm update request Require all fields (state, lifecyclestate, and link) Change-Id: I7b548fd87143d2733464e0fc33195da5c4e93534 --- .../monasca/api/app/command/UpdateAlarmCommand.java | 5 +++-- monasca_api/v2/reference/alarms.py | 12 ++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/java/src/main/java/monasca/api/app/command/UpdateAlarmCommand.java b/java/src/main/java/monasca/api/app/command/UpdateAlarmCommand.java index 1e9cb98d6..f485bf127 100644 --- a/java/src/main/java/monasca/api/app/command/UpdateAlarmCommand.java +++ b/java/src/main/java/monasca/api/app/command/UpdateAlarmCommand.java @@ -13,7 +13,6 @@ */ package monasca.api.app.command; -import javax.annotation.Nullable; import javax.validation.constraints.NotNull; import monasca.common.model.alarm.AlarmState; @@ -22,12 +21,14 @@ public class UpdateAlarmCommand { @NotNull public AlarmState state; + @NotNull public String lifecycleState; + @NotNull public String link; public UpdateAlarmCommand() {} - public UpdateAlarmCommand(AlarmState state, @Nullable String lifecycleState, @Nullable String link) { + public UpdateAlarmCommand(AlarmState state, String lifecycleState, String link) { this.state = state; this.lifecycleState = lifecycleState; this.link = link; diff --git a/monasca_api/v2/reference/alarms.py b/monasca_api/v2/reference/alarms.py index 4d0b2835f..6d69d2b21 100644 --- a/monasca_api/v2/reference/alarms.py +++ b/monasca_api/v2/reference/alarms.py @@ -57,12 +57,12 @@ class Alarms(alarms_api_v2.AlarmsV2API, if 'state' not in alarm or not alarm['state']: raise falcon.HTTPBadRequest('Bad request', "Field 'state' is required") - - # Assume these fields are null if not provided - if 'lifecycle_state' not in alarm: - alarm['lifecycle_state'] = None - if 'link' not in alarm: - alarm['link'] = None + if 'lifecycle_state' not in alarm or not alarm['lifecycle_state']: + raise falcon.HTTPBadRequest('Bad Request', + "Field 'lifecycle_state' is required") + if 'link' not in alarm or not alarm['link']: + raise falcon.HTTPBadRequest('Bad Request', + "Field 'link' is required") self._alarm_update(tenant_id, alarm_id, alarm['state'], alarm['lifecycle_state'], alarm['link'])