-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
54 lines (42 loc) · 1.02 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"context"
"fmt"
"os"
"path/filepath"
"github.com/Carlsberg/configuration-fetch-action/aws"
"github.com/crqra/go-action/pkg/action"
)
func main() {
if err := action.Execute(&AppConfigFetchAction{}); err != nil {
action.SetFailed(err, map[string]string{})
}
}
type AppConfigFetchAction struct {
AppName string `action:"app-name"`
ProfileName string `action:"profile-name"`
Environment string `action:"env"`
Region string `action:"region"`
}
func (a *AppConfigFetchAction) Run() error {
config, err := aws.GetConfig(context.Background(), a.AppName, a.ProfileName, a.Environment, a.Region)
if err != nil {
return err
}
filename := fmt.Sprintf("%v-%v-%v-%v.json", a.Region, a.AppName, a.Environment, a.ProfileName)
f, err := os.Create(filename)
if err != nil {
return err
}
defer f.Close()
_, err = f.WriteString(config)
if err != nil {
return err
}
absPath, err := filepath.Abs(filename)
if err != nil {
return err
}
action.SetOutput("path", absPath)
return err
}