-
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.
Merge pull request #81 from jgramoll/cloudformation
Cloudformation
- Loading branch information
Showing
49 changed files
with
781 additions
and
179 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package client | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
// DeployCloudformationSource source type | ||
type DeployCloudformationSource int | ||
|
||
const ( | ||
// DeployCloudformationSourceUnknown default unknown | ||
DeployCloudformationSourceUnknown DeployCloudformationSource = iota | ||
// DeployCloudformationSourceText text | ||
DeployCloudformationSourceText | ||
// DeployCloudformationSourceArtifact artifact | ||
DeployCloudformationSourceArtifact | ||
) | ||
|
||
func (s DeployCloudformationSource) String() string { | ||
return [...]string{"unknown", "text", "artifact"}[s] | ||
} | ||
|
||
// ParseDeployCloudformationSource parse source | ||
func ParseDeployCloudformationSource(s string) (DeployCloudformationSource, error) { | ||
switch s { | ||
default: | ||
return DeployCloudformationSourceUnknown, fmt.Errorf("Unknown source %s", s) | ||
case "text": | ||
return DeployCloudformationSourceText, nil | ||
case "artifact": | ||
return DeployCloudformationSourceArtifact, nil | ||
} | ||
} | ||
|
||
// MarshalText source to text | ||
func (s DeployCloudformationSource) MarshalText() ([]byte, error) { | ||
return []byte(s.String()), nil | ||
} | ||
|
||
// UnmarshalText source from text | ||
func (s *DeployCloudformationSource) UnmarshalText(text []byte) error { | ||
parsedSource, err := ParseDeployCloudformationSource(string(text)) | ||
if err != nil { | ||
return err | ||
} | ||
*s = parsedSource | ||
return nil | ||
} |
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,65 @@ | ||
package client | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/mitchellh/mapstructure" | ||
) | ||
|
||
// DeployCloudformationStageType deploy manifest stage | ||
var DeployCloudformationStageType StageType = "deployCloudFormation" | ||
|
||
func init() { | ||
stageFactories[DeployCloudformationStageType] = parseDeployCloudformationStage | ||
} | ||
|
||
// DeployCloudformationStage deploy cloudforamtion stage | ||
type DeployCloudformationStage struct { | ||
BaseStage `mapstructure:",squash"` | ||
|
||
ActionOnReplacement string `json:"actionOnReplacement"` | ||
Capabilities []string `json:"capabilities"` | ||
ChangeSetName string `json:"changeSetName"` | ||
Credentials string `json:"credentials"` | ||
ExecuteChangeSet bool `json:"executeChangeSet"` | ||
IsChangeSet bool `json:"isChangeSet"` | ||
Parameters map[string]string `json:"parameters"` | ||
Regions []string `json:"regions"` | ||
RoleARN string `json:"roleARN"` | ||
Source DeployCloudformationSource `json:"source"` | ||
StackArtifact *StackArtifact `json:"stackArtifact"` | ||
StackName string `json:"stackName"` | ||
Tags map[string]string `json:"tags"` | ||
TemplateBody []string `json:"templateBody"` | ||
} | ||
|
||
// NewDeployCloudformationStage deploy cloudformation stage | ||
func NewDeployCloudformationStage() *DeployCloudformationStage { | ||
return &DeployCloudformationStage{ | ||
BaseStage: *newBaseStage(DeployCloudformationStageType), | ||
Source: DeployCloudformationSourceText, | ||
} | ||
} | ||
|
||
func parseDeployCloudformationStage(stageMap map[string]interface{}) (Stage, error) { | ||
stage := NewDeployCloudformationStage() | ||
if err := stage.parseBaseStage(stageMap); err != nil { | ||
return nil, err | ||
} | ||
|
||
sourceString, ok := stageMap["source"].(string) | ||
if !ok { | ||
return nil, fmt.Errorf("Could not parse cloudformation source %v", stageMap["source"]) | ||
} | ||
source, err := ParseDeployCloudformationSource(sourceString) | ||
if err != nil { | ||
return nil, err | ||
} | ||
stage.Source = source | ||
delete(stageMap, "source") | ||
|
||
if err := mapstructure.Decode(stageMap, stage); err != nil { | ||
return nil, err | ||
} | ||
return stage, nil | ||
} |
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,93 @@ | ||
package client | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/sergi/go-diff/diffmatchpatch" | ||
) | ||
|
||
var deployCloudformationStage DeployCloudformationStage | ||
|
||
func init() { | ||
deployCloudformationStage = *NewDeployCloudformationStage() | ||
deployCloudformationStage.Name = "New Deploy Cloudformation" | ||
} | ||
|
||
func TestDeployCloudformationStageGetName(t *testing.T) { | ||
name := "New Deploy Cloudformation" | ||
if deployCloudformationStage.GetName() != name { | ||
t.Fatalf("Deploy Cloudformation stage GetName() should be %s, not \"%s\"", name, deployCloudformationStage.GetName()) | ||
} | ||
} | ||
|
||
func TestDeployCloudformationStageGetType(t *testing.T) { | ||
if deployCloudformationStage.GetType() != DeployCloudformationStageType { | ||
t.Fatalf("Deploy Cloudformation stage GetType() should be %s, not \"%s\"", DeployCloudformationStageType, deployCloudformationStage.GetType()) | ||
} | ||
if deployCloudformationStage.Type != DeployCloudformationStageType { | ||
t.Fatalf("Deploy Cloudformation stage Type should be %s, not \"%s\"", DeployCloudformationStageType, deployCloudformationStage.Type) | ||
} | ||
} | ||
|
||
func TestDeployCloudformationStageSerialize(t *testing.T) { | ||
b, err := json.MarshalIndent(deployCloudformationStage, "", "\t") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
result := string(b) | ||
if result != deployCloudformationJSON { | ||
dmp := diffmatchpatch.New() | ||
diffs := dmp.DiffMain(deployCloudformationJSON, result, true) | ||
t.Fatalf("Deploy Cloudformation not as expected: %s", dmp.DiffPrettyText(diffs)) | ||
} | ||
} | ||
|
||
func TestDeployCloudformationStageDeserialize(t *testing.T) { | ||
var stageMap map[string]interface{} | ||
err := json.Unmarshal([]byte(deployCloudformationJSON), &stageMap) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
stageInterface, err := parseDeployCloudformationStage(stageMap) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
stage := stageInterface.(*DeployCloudformationStage) | ||
if stage.Source != DeployCloudformationSourceText { | ||
t.Fatalf("Should have source type text") | ||
} | ||
} | ||
|
||
var deployCloudformationJSON = `{ | ||
"name": "New Deploy Cloudformation", | ||
"refId": "", | ||
"type": "deployCloudFormation", | ||
"requisiteStageRefIds": [], | ||
"sendNotifications": false, | ||
"stageEnabled": null, | ||
"completeOtherBranchesThenFail": false, | ||
"continuePipeline": false, | ||
"failOnFailedExpressions": false, | ||
"failPipeline": true, | ||
"overrideTimeout": false, | ||
"restrictExecutionDuringTimeWindow": false, | ||
"restrictedExecutionWindow": null, | ||
"notifications": null, | ||
"expectedArtifacts": [], | ||
"requiredArtifactIds": [], | ||
"actionOnReplacement": "", | ||
"capabilities": null, | ||
"changeSetName": "", | ||
"credentials": "", | ||
"executeChangeSet": false, | ||
"isChangeSet": false, | ||
"parameters": null, | ||
"regions": null, | ||
"roleARN": "", | ||
"source": "text", | ||
"stackArtifact": null, | ||
"stackName": "", | ||
"tags": null, | ||
"templateBody": null | ||
}` |
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,11 @@ | ||
package client | ||
|
||
// StackArtifact stack artifact | ||
type StackArtifact struct { | ||
ArtifactAccount string `json:"artifactAccount"` | ||
ID string `json:"id"` | ||
Name string `json:"name"` | ||
Reference string `json:"reference"` | ||
Type string `json:"type"` | ||
Version string `json:"version"` | ||
} |
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
Oops, something went wrong.