Skip to content
This repository has been archived by the owner on Aug 24, 2023. It is now read-only.

Commit

Permalink
Moved azure.ParseOutputs to actions.ParseOutputs
Browse files Browse the repository at this point in the history
  • Loading branch information
StiviiK committed May 25, 2020
1 parent f35b0e7 commit 7525b42
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 33 deletions.
3 changes: 1 addition & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"os/signal"

"github.com/sirupsen/logrus"
"github.com/whiteducksoftware/azure-arm-action/pkg/azure"
"github.com/whiteducksoftware/azure-arm-action/pkg/github"
"github.com/whiteducksoftware/azure-arm-action/pkg/github/actions"
)
Expand Down Expand Up @@ -64,7 +63,7 @@ func main() {
}

// parse the template outputs
outputs, err := azure.ParseOutputs(resultDeployment.Properties.Outputs)
outputs, err := actions.ParseOutputs(resultDeployment.Properties.Outputs)
if err != nil {
logrus.Errorf("Failed to parse the template outputs: %s", err)
os.Exit(1)
Expand Down
31 changes: 0 additions & 31 deletions pkg/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/Azure/go-autorest/autorest"
"github.com/Azure/go-autorest/autorest/adal"
"github.com/Azure/go-autorest/autorest/azure"
"github.com/mitchellh/mapstructure"
)

// SDKAuth represents Azure Sp
Expand All @@ -29,12 +28,6 @@ type SDKAuth struct {
ARMEndpointURL string `json:"resourceManagerEndpointUrl"`
}

// Output represents a single output of an ARM template
type Output struct {
Type string `json:"type"`
Value string `json:"value"`
}

// GetSdkAuthFromString builds from the cmd flags a ServicePrincipal
func GetSdkAuthFromString(credentials string) (SDKAuth, error) {
var auth SDKAuth
Expand Down Expand Up @@ -167,27 +160,3 @@ func CreateDeployment(ctx context.Context, deployClient resources.DeploymentsCli

return future.Result(deployClient)
}

// ParseOutputs takes the raw outputs from the azure.DemploymentExtended object
// and converts it to a string Output map
func ParseOutputs(raw interface{}) (map[string]Output, error) {
if raw == nil {
return map[string]Output{}, nil
}

var outputs map[string]Output
decoder, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
Result: &outputs,
TagName: "json",
})
if err != nil {
return map[string]Output{}, err
}

err = decoder.Decode(raw)
if err != nil {
return map[string]Output{}, err
}

return outputs, nil
}
38 changes: 38 additions & 0 deletions pkg/github/actions/parse_outputs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
Copyright (c) 2020 white duck Gesellschaft für Softwareentwicklung mbH
This code is licensed under MIT license (see LICENSE for details)
*/
package actions

import "github.com/mitchellh/mapstructure"

// Output represents a single output of an ARM template
type Output struct {
Type string `json:"type"`
Value string `json:"value"`
}

// ParseOutputs takes the raw outputs from the azure.DemploymentExtended object
// and converts it to a string Output map
func ParseOutputs(raw interface{}) (map[string]Output, error) {
if raw == nil {
return map[string]Output{}, nil
}

var outputs map[string]Output
decoder, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
Result: &outputs,
TagName: "json",
})
if err != nil {
return map[string]Output{}, err
}

err = decoder.Decode(raw)
if err != nil {
return map[string]Output{}, err
}

return outputs, nil
}

0 comments on commit 7525b42

Please sign in to comment.