-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add notifications to manual judgement (#55)
* add notifications to manual judgement * fix manual judgement serializing in snakecase
- Loading branch information
Showing
36 changed files
with
643 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package provider | ||
|
||
import ( | ||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/jgramoll/terraform-provider-spinnaker/client" | ||
) | ||
|
||
type defaultNotification struct { | ||
ID string `mapstructure:"-"` | ||
Address string `mapstructure:"address"` | ||
Message *[]*message `mapstructure:"message"` | ||
Type string `mapstructure:"type"` | ||
When *[]*when `mapstructure:"when"` | ||
} | ||
|
||
func newDefaultNotification() *defaultNotification { | ||
return &defaultNotification{} | ||
} | ||
|
||
func (n *defaultNotification) toClientNotification(level client.NotificationLevel) (*client.Notification, error) { | ||
message, err := toClientMessage(level, n.Message) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &client.Notification{ | ||
ID: n.ID, | ||
Address: n.Address, | ||
Level: level, | ||
Type: n.Type, | ||
When: *toClientWhen(level, (*n.When)[0]), | ||
Message: message, | ||
}, nil | ||
} | ||
|
||
func (n *defaultNotification) fromClientNotification(cn *client.Notification) notification { | ||
return &defaultNotification{ | ||
ID: cn.ID, | ||
Address: cn.Address, | ||
Message: &[]*message{fromClientMessage(cn.Message)}, | ||
Type: cn.Type, | ||
When: &[]*when{fromClientWhen(cn)}, | ||
} | ||
} | ||
|
||
func (n *defaultNotification) setNotificationResourceData(d *schema.ResourceData) error { | ||
err := d.Set("address", n.Address) | ||
if err != nil { | ||
return err | ||
} | ||
err = d.Set("message", n.Message) | ||
if err != nil { | ||
return err | ||
} | ||
err = d.Set("type", n.Type) | ||
if err != nil { | ||
return err | ||
} | ||
return d.Set("when", n.When) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package provider | ||
|
||
import ( | ||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/jgramoll/terraform-provider-spinnaker/client" | ||
) | ||
|
||
type manualJudgementNotification struct { | ||
ID string `mapstructure:"-"` | ||
Address string `mapstructure:"address"` | ||
Type string `mapstructure:"type"` | ||
|
||
Message *[]*manualJudgementNotificationMessage `mapstructure:"message"` | ||
When *[]*manualJudgementNotificationWhen `mapstructure:"when"` | ||
} | ||
|
||
func newManualJudgementNotification() *manualJudgementNotification { | ||
return &manualJudgementNotification{} | ||
} | ||
|
||
func newManualJudgementNotificationInterface() notification { | ||
return newManualJudgementNotification() | ||
} | ||
|
||
func (n *manualJudgementNotification) toClientNotification(level client.NotificationLevel) (*client.Notification, error) { | ||
message, err := toClientManualJudgementNotificationMessage(level, n.Message) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &client.Notification{ | ||
ID: n.ID, | ||
Address: n.Address, | ||
Level: level, | ||
Type: n.Type, | ||
When: *toClientManualJudgementNotificationWhen(level, (*n.When)[0]), | ||
Message: message, | ||
}, nil | ||
} | ||
|
||
func (n *manualJudgementNotification) fromClientNotification(cn *client.Notification) notification { | ||
return &manualJudgementNotification{ | ||
ID: cn.ID, | ||
Address: cn.Address, | ||
Message: &[]*manualJudgementNotificationMessage{fromClientManualJudgementNotificationMessage(cn.Message)}, | ||
Type: cn.Type, | ||
When: &[]*manualJudgementNotificationWhen{fromClientManualJudgementNotificationWhen(cn)}, | ||
} | ||
} | ||
|
||
func (n *manualJudgementNotification) setNotificationResourceData(d *schema.ResourceData) error { | ||
err := d.Set("address", n.Address) | ||
if err != nil { | ||
return err | ||
} | ||
err = d.Set("message", n.Message) | ||
if err != nil { | ||
return err | ||
} | ||
err = d.Set("type", n.Type) | ||
if err != nil { | ||
return err | ||
} | ||
return d.Set("when", n.When) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package provider | ||
|
||
import ( | ||
"github.com/jgramoll/terraform-provider-spinnaker/client" | ||
) | ||
|
||
type manualJudgementNotificationMessage struct { | ||
ManualJudgmentContinue string `mapstructure:"manual_judgment_continue"` | ||
ManualJudgmentStop string `mapstructure:"manual_judgment_stop"` | ||
} | ||
|
||
func toClientManualJudgementNotificationMessage(level client.NotificationLevel, m *[]*manualJudgementNotificationMessage) (client.Message, error) { | ||
if m == nil || len(*m) == 0 { | ||
return nil, nil | ||
} | ||
message := (*m)[0] | ||
if message == nil { | ||
return nil, nil | ||
} | ||
|
||
newMessage, err := client.NewMessage(level) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if message.ManualJudgmentContinue != "" { | ||
newMessage.SetManualJudgmentContinueText(message.ManualJudgmentContinue) | ||
} | ||
if message.ManualJudgmentStop != "" { | ||
newMessage.SetManualJudgmentStopText(message.ManualJudgmentStop) | ||
} | ||
return newMessage, nil | ||
} | ||
|
||
func fromClientManualJudgementNotificationMessage(cm client.Message) *manualJudgementNotificationMessage { | ||
if cm == nil { | ||
return nil | ||
} | ||
|
||
newMessage := manualJudgementNotificationMessage{} | ||
if cm.ManualJudgmentContinueText() != "" { | ||
newMessage.ManualJudgmentContinue = cm.ManualJudgmentContinueText() | ||
} | ||
if cm.ManualJudgmentStopText() != "" { | ||
newMessage.ManualJudgmentStop = cm.ManualJudgmentStopText() | ||
} | ||
return &newMessage | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package provider | ||
|
||
import ( | ||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
func manualJudementNotificationResource() *schema.Resource { | ||
return &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"address": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Description: "Address of the notification (slack channel, email, etc)", | ||
Required: true, | ||
}, | ||
"message": { | ||
Type: schema.TypeList, | ||
Description: "Custom messages", | ||
Optional: true, | ||
MaxItems: 1, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"manual_judgment_continue": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"manual_judgment_stop": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"type": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Description: "Type of notification (slack, email, etc)", | ||
Required: true, | ||
}, | ||
"when": &schema.Schema{ | ||
Type: schema.TypeList, | ||
Description: "When to send notification (started, completed, failed)", | ||
Required: true, | ||
MaxItems: 1, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"manual_judgment": &schema.Schema{ | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
}, | ||
"manual_judgment_continue": &schema.Schema{ | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
}, | ||
"manual_judgment_stop": &schema.Schema{ | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} |
Oops, something went wrong.