-
Notifications
You must be signed in to change notification settings - Fork 28
/
metadata.go
126 lines (93 loc) · 2.65 KB
/
metadata.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// SPDX-License-Identifier: Apache-2.0
package main
import (
"net/url"
"github.com/go-vela/types"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
)
// helper function to setup the metadata from the CLI arguments.
func setupMetadata(c *cli.Context) (*types.Metadata, error) {
logrus.Debug("Creating metadata from CLI configuration")
m := new(types.Metadata)
database, err := metadataDatabase(c)
if err != nil {
return nil, err
}
m.Database = database
queue, err := metadataQueue(c)
if err != nil {
return nil, err
}
m.Queue = queue
source, err := metadataSource(c)
if err != nil {
return nil, err
}
m.Source = source
vela, err := metadataVela(c)
if err != nil {
return nil, err
}
m.Vela = vela
return m, nil
}
// helper function to capture the database metadata from the CLI arguments.
func metadataDatabase(c *cli.Context) (*types.Database, error) {
logrus.Trace("Creating database metadata from CLI configuration")
u, err := url.Parse(c.String("database.addr"))
if err != nil {
return nil, err
}
return &types.Database{
Driver: c.String("database.driver"),
Host: u.Host,
}, nil
}
// helper function to capture the queue metadata from the CLI arguments.
func metadataQueue(c *cli.Context) (*types.Queue, error) {
logrus.Trace("Creating queue metadata from CLI configuration")
u, err := url.Parse(c.String("queue.addr"))
if err != nil {
return nil, err
}
return &types.Queue{
Driver: c.String("queue.driver"),
Host: u.Host,
}, nil
}
// helper function to capture the source metadata from the CLI arguments.
func metadataSource(c *cli.Context) (*types.Source, error) {
logrus.Trace("Creating source metadata from CLI configuration")
u, err := url.Parse(c.String("scm.addr"))
if err != nil {
return nil, err
}
return &types.Source{
Driver: c.String("scm.driver"),
Host: u.Host,
}, nil
}
// helper function to capture the Vela metadata from the CLI arguments.
//
//nolint:unparam // ignore unparam for now
func metadataVela(c *cli.Context) (*types.Vela, error) {
logrus.Trace("Creating Vela metadata from CLI configuration")
vela := new(types.Vela)
if len(c.String("server-addr")) > 0 {
vela.Address = c.String("server-addr")
}
if len(c.String("webui-addr")) > 0 {
vela.WebAddress = c.String("webui-addr")
}
if len(c.String("webui-oauth-callback")) > 0 {
vela.WebOauthCallbackPath = c.String("webui-oauth-callback")
}
if c.Duration("access-token-duration").Seconds() > 0 {
vela.AccessTokenDuration = c.Duration("access-token-duration")
}
if c.Duration("refresh-token-duration").Seconds() > 0 {
vela.RefreshTokenDuration = c.Duration("refresh-token-duration")
}
return vela, nil
}