From e6c2bf0d0f9bfffc58a4efb9b71877fa254efcda Mon Sep 17 00:00:00 2001 From: Lev Berman Date: Wed, 6 Apr 2016 11:44:41 +0300 Subject: [PATCH] Implement the backup update-server-policy command --- init.go | 23 +++++++++++++++++++++++ models/backup/serverpolicy.go | 22 ++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/init.go b/init.go index 00120bf..8a4f39e 100644 --- a/init.go +++ b/init.go @@ -3353,6 +3353,29 @@ func init() { }, }, }) + registerCommandBase(&backup.UpdateServerPolicy{}, &backup.ServerPolicy{}, commands.CommandExcInfo{ + Verb: "PATCH", + Url: "https://api-va1.backup.ctl.io/clc-backup-api/api/accountPolicies/{AccountPolicyId}/serverPolicies/{ServerPolicyId}", + Resource: "backup", + Command: "update-server-policy", + Help: help.Command{ + Brief: []string{"Updates the given backup policy of the given server"}, + Arguments: []help.Argument{ + { + "--account-policy-id", + []string{"Required. The ID of the account policy the server policy is bound to"}, + }, + { + "--server-policy-id", + []string{"Required. The ID of the server policy to update"}, + }, + { + "--status", + []string{"Required. A new status value. 'ACTIVE' or 'INACTIVE'"}, + }, + }, + }, + }) } func registerCommandBase(inputModel interface{}, outputModel interface{}, info commands.CommandExcInfo) { diff --git a/models/backup/serverpolicy.go b/models/backup/serverpolicy.go index 2a6643f..8859931 100644 --- a/models/backup/serverpolicy.go +++ b/models/backup/serverpolicy.go @@ -71,6 +71,28 @@ func (g *GetStoredData) Validate() error { return nil } +type UpdateServerPolicy struct { + AccountPolicyId string `URIParam:"yes" valid:"required"` + ServerPolicyId string `URIParam:"yes" valid:"required"` + Operations []UpdateServerPolicyOperation `argument:"ignore" json:"operations"` + Status string `json:"-" oneOf:"ACTIVE,INACTIVE" valid:"required"` +} + +func (u *UpdateServerPolicy) Validate() error { + u.Operations = append(u.Operations, UpdateServerPolicyOperation{ + Op: "replace", + Path: "/status", + Value: u.Status, + }) + return nil +} + +type UpdateServerPolicyOperation struct { + Op string `json:"op"` + Path string `json:"path"` + Value string `json:"value"` +} + type GetRestoreDetails struct { AccountPolicyId string `URIParam:"yes" valid:"required"` ServerPolicyId string `URIParam:"yes" valid:"required"`