-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
69 lines (54 loc) · 1.57 KB
/
config.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"fmt"
"github.com/docker/docker/api/types/registry"
"github.com/sethvargo/go-githubactions"
)
type Config struct {
username string
password string
serverAddress string
image string
action *githubactions.Action
}
func (c Config) String() string {
return fmt.Sprintf("Config{username: %s, password: #####, serverAddress: %s, image: %s}", c.username, c.serverAddress, c.image)
}
func (c *Config) GetAuthString() (string, error) {
c.action.Debugf("Getting auth string...")
defer c.action.Debugf("Got auth string")
authConfig := registry.AuthConfig{
Username: c.username,
Password: c.password,
ServerAddress: c.serverAddress,
}
authStr, err := registry.EncodeAuthConfig(authConfig)
if err != nil {
return "", err
}
return authStr, nil
}
func NewFromInputs(action *githubactions.Action) (*Config, error) {
action.Debugf("Getting inputs...")
defer action.Debugf("Got inputs")
username := getInputDefault(action, "username", "")
password := getInputDefault(action, "password", "")
serverAddress := getInputDefault(action, "server_address", "")
image := getInputDefault(action, "image", "")
c := Config{
username: username,
password: password,
serverAddress: serverAddress,
image: image,
action: action,
}
return &c, nil
}
func getInputDefault(action *githubactions.Action, key, fallback string) string {
action.Debugf("Getting input %s...", key)
defer action.Debugf("Got input %s", key)
if value := action.GetInput(key); value != "" {
return value
}
return fallback
}