Skip to content

Commit 877aa98

Browse files
authored
Merge branch 'master' into reconcile-delete-jobs
2 parents 1e41b4f + 3c14810 commit 877aa98

File tree

103 files changed

+3531
-5480
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+3531
-5480
lines changed

.releaserc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ plugins:
88
- { type: feat, release: patch }
99
- { type: ci, release: false }
1010
- { type: style, release: false }
11+
- { type: major, release: major }
1112
parserOpts:
1213
noteKeywords:
1314
- MAJOR RELEASE

README.md

Lines changed: 104 additions & 106 deletions
Large diffs are not rendered by default.

api/context/context.go

Lines changed: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
v1 "github.com/flanksource/canary-checker/api/v1"
1111
"github.com/flanksource/commons/logger"
12+
ctemplate "github.com/flanksource/commons/template"
1213
"github.com/flanksource/duty"
1314
"github.com/flanksource/duty/models"
1415
"github.com/flanksource/duty/types"
@@ -55,12 +56,90 @@ func (ctx *Context) GetEnvValueFromCache(env types.EnvVar) (string, error) {
5556
return duty.GetEnvValueFromCache(ctx.Kubernetes, env, ctx.Namespace)
5657
}
5758

59+
func getDomain(username string) string {
60+
parts := strings.Split(username, "@")
61+
if len(parts) == 2 {
62+
return parts[1]
63+
}
64+
return ""
65+
}
66+
67+
func (ctx *Context) GetConnection(conn v1.Connection) (*models.Connection, error) {
68+
var _conn *models.Connection
69+
var err error
70+
71+
if _conn, err = ctx.HydrateConnectionByURL(conn.Connection); err != nil {
72+
return nil, err
73+
}
74+
75+
if _conn == nil {
76+
_conn = &models.Connection{
77+
URL: conn.URL,
78+
}
79+
}
80+
81+
if conn.URL != "" {
82+
// override the url specified at the connection level
83+
_conn.URL = conn.URL
84+
}
85+
86+
if _conn.Username == "" || _conn.Password == "" {
87+
// no username specified at connection level, use the one from inline connection
88+
auth, err := ctx.GetAuthValues(conn.Authentication)
89+
if err != nil {
90+
return nil, err
91+
}
92+
_conn.Username = auth.Username.ValueStatic
93+
_conn.Password = auth.Password.ValueStatic
94+
}
95+
96+
data := map[string]interface{}{
97+
"name": ctx.Canary.Name,
98+
"namespace": ctx.Namespace,
99+
"username": _conn.Username,
100+
"password": _conn.Password,
101+
"domain": getDomain(_conn.Username),
102+
}
103+
templater := ctemplate.StructTemplater{
104+
Values: data,
105+
// access go values in template requires prefix everything with .
106+
// to support $(username) instead of $(.username) we add a function for each var
107+
ValueFunctions: true,
108+
DelimSets: []ctemplate.Delims{
109+
{Left: "{{", Right: "}}"},
110+
{Left: "$(", Right: ")"},
111+
},
112+
RequiredTag: "template",
113+
}
114+
if err := templater.Walk(_conn); err != nil {
115+
return nil, err
116+
}
117+
118+
return _conn, nil
119+
}
120+
121+
func (ctx Context) GetAuthValues(auth v1.Authentication) (v1.Authentication, error) {
122+
// in case nil we are sending empty string values for username and password
123+
if auth.IsEmpty() {
124+
return auth, nil
125+
}
126+
var err error
127+
128+
if auth.Username.ValueStatic, err = ctx.GetEnvValueFromCache(auth.Username); err != nil {
129+
return auth, err
130+
}
131+
if auth.Password.ValueStatic, err = ctx.GetEnvValueFromCache(auth.Password); err != nil {
132+
return auth, err
133+
}
134+
return auth, nil
135+
}
136+
58137
func (ctx *Context) HydrateConnectionByURL(connectionName string) (*models.Connection, error) {
59-
if !strings.HasPrefix(connectionName, "connection://") {
138+
if connectionName == "" {
60139
return nil, nil
61140
}
62141

63-
if connectionName == "" {
142+
if !strings.HasPrefix(connectionName, "connection://") {
64143
return nil, nil
65144
}
66145

0 commit comments

Comments
 (0)