configstore: use augmented types for vars/secrets dynamic values
This commit is contained in:
parent
da2ac0ab38
commit
984efb539e
@ -156,48 +156,48 @@ func (c *Client) DeleteProject(ctx context.Context, projectRef string) (*http.Re
|
||||
return c.getResponse(ctx, "DELETE", fmt.Sprintf("/projects/%s", url.PathEscape(projectRef)), nil, jsonContent, nil)
|
||||
}
|
||||
|
||||
func (c *Client) GetProjectGroupSecrets(ctx context.Context, projectGroupRef string, tree bool) ([]*types.Secret, *http.Response, error) {
|
||||
func (c *Client) GetProjectGroupSecrets(ctx context.Context, projectGroupRef string, tree bool) ([]*Secret, *http.Response, error) {
|
||||
q := url.Values{}
|
||||
if tree {
|
||||
q.Add("tree", "")
|
||||
}
|
||||
|
||||
secrets := []*types.Secret{}
|
||||
secrets := []*Secret{}
|
||||
resp, err := c.getParsedResponse(ctx, "GET", fmt.Sprintf("/projectgroups/%s/secrets", url.PathEscape(projectGroupRef)), q, jsonContent, nil, &secrets)
|
||||
return secrets, resp, err
|
||||
}
|
||||
|
||||
func (c *Client) GetProjectSecrets(ctx context.Context, projectRef string, tree bool) ([]*types.Secret, *http.Response, error) {
|
||||
func (c *Client) GetProjectSecrets(ctx context.Context, projectRef string, tree bool) ([]*Secret, *http.Response, error) {
|
||||
q := url.Values{}
|
||||
if tree {
|
||||
q.Add("tree", "")
|
||||
}
|
||||
|
||||
secrets := []*types.Secret{}
|
||||
secrets := []*Secret{}
|
||||
resp, err := c.getParsedResponse(ctx, "GET", fmt.Sprintf("/projects/%s/secrets", url.PathEscape(projectRef)), q, jsonContent, nil, &secrets)
|
||||
return secrets, resp, err
|
||||
}
|
||||
|
||||
func (c *Client) CreateProjectGroupSecret(ctx context.Context, projectGroupRef string, secret *types.Secret) (*types.Secret, *http.Response, error) {
|
||||
func (c *Client) CreateProjectGroupSecret(ctx context.Context, projectGroupRef string, secret *types.Secret) (*Secret, *http.Response, error) {
|
||||
pj, err := json.Marshal(secret)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
secret = new(types.Secret)
|
||||
resp, err := c.getParsedResponse(ctx, "POST", fmt.Sprintf("/projectgroups/%s/secrets", url.PathEscape(projectGroupRef)), nil, jsonContent, bytes.NewReader(pj), secret)
|
||||
return secret, resp, err
|
||||
resSecret := new(Secret)
|
||||
resp, err := c.getParsedResponse(ctx, "POST", fmt.Sprintf("/projectgroups/%s/secrets", url.PathEscape(projectGroupRef)), nil, jsonContent, bytes.NewReader(pj), resSecret)
|
||||
return resSecret, resp, err
|
||||
}
|
||||
|
||||
func (c *Client) CreateProjectSecret(ctx context.Context, projectRef string, secret *types.Secret) (*types.Secret, *http.Response, error) {
|
||||
func (c *Client) CreateProjectSecret(ctx context.Context, projectRef string, secret *types.Secret) (*Secret, *http.Response, error) {
|
||||
pj, err := json.Marshal(secret)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
secret = new(types.Secret)
|
||||
resp, err := c.getParsedResponse(ctx, "POST", fmt.Sprintf("/projects/%s/secrets", url.PathEscape(projectRef)), nil, jsonContent, bytes.NewReader(pj), secret)
|
||||
return secret, resp, err
|
||||
resSecret := new(Secret)
|
||||
resp, err := c.getParsedResponse(ctx, "POST", fmt.Sprintf("/projects/%s/secrets", url.PathEscape(projectRef)), nil, jsonContent, bytes.NewReader(pj), resSecret)
|
||||
return resSecret, resp, err
|
||||
}
|
||||
|
||||
func (c *Client) DeleteProjectGroupSecret(ctx context.Context, projectGroupRef, secretName string) (*http.Response, error) {
|
||||
@ -208,48 +208,48 @@ func (c *Client) DeleteProjectSecret(ctx context.Context, projectRef, secretName
|
||||
return c.getResponse(ctx, "DELETE", fmt.Sprintf("/projects/%s/secrets/%s", url.PathEscape(projectRef), secretName), nil, jsonContent, nil)
|
||||
}
|
||||
|
||||
func (c *Client) GetProjectGroupVariables(ctx context.Context, projectGroupRef string, tree bool) ([]*types.Variable, *http.Response, error) {
|
||||
func (c *Client) GetProjectGroupVariables(ctx context.Context, projectGroupRef string, tree bool) ([]*Variable, *http.Response, error) {
|
||||
q := url.Values{}
|
||||
if tree {
|
||||
q.Add("tree", "")
|
||||
}
|
||||
|
||||
variables := []*types.Variable{}
|
||||
variables := []*Variable{}
|
||||
resp, err := c.getParsedResponse(ctx, "GET", fmt.Sprintf("/projectgroups/%s/variables", url.PathEscape(projectGroupRef)), q, jsonContent, nil, &variables)
|
||||
return variables, resp, err
|
||||
}
|
||||
|
||||
func (c *Client) GetProjectVariables(ctx context.Context, projectRef string, tree bool) ([]*types.Variable, *http.Response, error) {
|
||||
func (c *Client) GetProjectVariables(ctx context.Context, projectRef string, tree bool) ([]*Variable, *http.Response, error) {
|
||||
q := url.Values{}
|
||||
if tree {
|
||||
q.Add("tree", "")
|
||||
}
|
||||
|
||||
variables := []*types.Variable{}
|
||||
variables := []*Variable{}
|
||||
resp, err := c.getParsedResponse(ctx, "GET", fmt.Sprintf("/projects/%s/variables", url.PathEscape(projectRef)), q, jsonContent, nil, &variables)
|
||||
return variables, resp, err
|
||||
}
|
||||
|
||||
func (c *Client) CreateProjectGroupVariable(ctx context.Context, projectGroupRef string, variable *types.Variable) (*types.Variable, *http.Response, error) {
|
||||
func (c *Client) CreateProjectGroupVariable(ctx context.Context, projectGroupRef string, variable *types.Variable) (*Variable, *http.Response, error) {
|
||||
pj, err := json.Marshal(variable)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
variable = new(types.Variable)
|
||||
resp, err := c.getParsedResponse(ctx, "POST", fmt.Sprintf("/projectgroups/%s/variables", url.PathEscape(projectGroupRef)), nil, jsonContent, bytes.NewReader(pj), variable)
|
||||
return variable, resp, err
|
||||
resVariable := new(Variable)
|
||||
resp, err := c.getParsedResponse(ctx, "POST", fmt.Sprintf("/projectgroups/%s/variables", url.PathEscape(projectGroupRef)), nil, jsonContent, bytes.NewReader(pj), resVariable)
|
||||
return resVariable, resp, err
|
||||
}
|
||||
|
||||
func (c *Client) CreateProjectVariable(ctx context.Context, projectRef string, variable *types.Variable) (*types.Variable, *http.Response, error) {
|
||||
func (c *Client) CreateProjectVariable(ctx context.Context, projectRef string, variable *types.Variable) (*Variable, *http.Response, error) {
|
||||
pj, err := json.Marshal(variable)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
variable = new(types.Variable)
|
||||
resp, err := c.getParsedResponse(ctx, "POST", fmt.Sprintf("/projects/%s/variables", url.PathEscape(projectRef)), nil, jsonContent, bytes.NewReader(pj), variable)
|
||||
return variable, resp, err
|
||||
resVariable := new(Variable)
|
||||
resp, err := c.getParsedResponse(ctx, "POST", fmt.Sprintf("/projects/%s/variables", url.PathEscape(projectRef)), nil, jsonContent, bytes.NewReader(pj), resVariable)
|
||||
return resVariable, resp, err
|
||||
}
|
||||
|
||||
func (c *Client) DeleteProjectGroupVariable(ctx context.Context, projectGroupRef, variableName string) (*http.Response, error) {
|
||||
|
@ -29,6 +29,14 @@ import (
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// Secret augments types.Secret with dynamic data
|
||||
type Secret struct {
|
||||
*types.Secret
|
||||
|
||||
// dynamic data
|
||||
ParentPath string
|
||||
}
|
||||
|
||||
type SecretHandler struct {
|
||||
log *zap.SugaredLogger
|
||||
readDB *readdb.ReadDB
|
||||
@ -95,13 +103,27 @@ func (h *SecretsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
} else {
|
||||
secrets, err = h.readDB.GetSecrets(tx, parentID)
|
||||
}
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
h.log.Errorf("err: %+v", err)
|
||||
httpError(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
resSecrets := make([]*Secret, len(secrets))
|
||||
for i, s := range secrets {
|
||||
resSecrets[i] = &Secret{Secret: s}
|
||||
}
|
||||
|
||||
err = h.readDB.Do(func(tx *db.Tx) error {
|
||||
// populate parent path
|
||||
for _, s := range secrets {
|
||||
for _, s := range resSecrets {
|
||||
pp, err := h.readDB.GetParentPath(tx, s.Parent.Type, s.Parent.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
s.Parent.Path = pp
|
||||
s.ParentPath = pp
|
||||
}
|
||||
return err
|
||||
})
|
||||
@ -111,7 +133,7 @@ func (h *SecretsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := httpResponse(w, http.StatusOK, secrets); err != nil {
|
||||
if err := httpResponse(w, http.StatusOK, resSecrets); err != nil {
|
||||
h.log.Errorf("err: %+v", err)
|
||||
}
|
||||
}
|
||||
|
@ -28,6 +28,14 @@ import (
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// Variable augments types.Variable with dynamic data
|
||||
type Variable struct {
|
||||
*types.Variable
|
||||
|
||||
// dynamic data
|
||||
ParentPath string
|
||||
}
|
||||
|
||||
type VariablesHandler struct {
|
||||
log *zap.SugaredLogger
|
||||
readDB *readdb.ReadDB
|
||||
@ -59,13 +67,26 @@ func (h *VariablesHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
} else {
|
||||
variables, err = h.readDB.GetVariables(tx, parentID)
|
||||
}
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
h.log.Errorf("err: %+v", err)
|
||||
httpError(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
resVariables := make([]*Variable, len(variables))
|
||||
for i, v := range variables {
|
||||
resVariables[i] = &Variable{Variable: v}
|
||||
}
|
||||
err = h.readDB.Do(func(tx *db.Tx) error {
|
||||
// populate parent path
|
||||
for _, v := range variables {
|
||||
for _, v := range resVariables {
|
||||
pp, err := h.readDB.GetParentPath(tx, v.Parent.Type, v.Parent.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
v.Parent.Path = pp
|
||||
v.ParentPath = pp
|
||||
}
|
||||
return err
|
||||
})
|
||||
@ -75,7 +96,7 @@ func (h *VariablesHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := httpResponse(w, http.StatusOK, variables); err != nil {
|
||||
if err := httpResponse(w, http.StatusOK, resVariables); err != nil {
|
||||
h.log.Errorf("err: %+v", err)
|
||||
}
|
||||
}
|
||||
@ -108,8 +129,6 @@ func (h *CreateVariableHandler) ServeHTTP(w http.ResponseWriter, r *http.Request
|
||||
variable.Parent.Type = parentType
|
||||
variable.Parent.ID = parentRef
|
||||
|
||||
h.log.Infof("variable: %s", util.Dump(variable))
|
||||
|
||||
variable, err = h.ch.CreateVariable(ctx, variable)
|
||||
if httpError(w, err) {
|
||||
h.log.Errorf("err: %+v", err)
|
||||
|
@ -33,11 +33,11 @@ type SecretResponse struct {
|
||||
ParentPath string `json:"parent_path"`
|
||||
}
|
||||
|
||||
func createSecretResponse(s *types.Secret) *SecretResponse {
|
||||
func createSecretResponse(s *csapi.Secret) *SecretResponse {
|
||||
return &SecretResponse{
|
||||
ID: s.ID,
|
||||
Name: s.Name,
|
||||
ParentPath: s.Parent.Path,
|
||||
ParentPath: s.ParentPath,
|
||||
}
|
||||
}
|
||||
|
||||
@ -61,7 +61,7 @@ func (h *SecretHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
var cssecrets []*types.Secret
|
||||
var cssecrets []*csapi.Secret
|
||||
var resp *http.Response
|
||||
switch parentType {
|
||||
case types.ConfigTypeProjectGroup:
|
||||
@ -132,21 +132,22 @@ func (h *CreateSecretHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
|
||||
}
|
||||
|
||||
var resp *http.Response
|
||||
var rs *csapi.Secret
|
||||
switch parentType {
|
||||
case types.ConfigTypeProjectGroup:
|
||||
h.log.Infof("creating project group secret")
|
||||
s, resp, err = h.configstoreClient.CreateProjectGroupSecret(ctx, parentRef, s)
|
||||
rs, resp, err = h.configstoreClient.CreateProjectGroupSecret(ctx, parentRef, s)
|
||||
case types.ConfigTypeProject:
|
||||
h.log.Infof("creating project secret")
|
||||
s, resp, err = h.configstoreClient.CreateProjectSecret(ctx, parentRef, s)
|
||||
rs, resp, err = h.configstoreClient.CreateProjectSecret(ctx, parentRef, s)
|
||||
}
|
||||
if httpErrorFromRemote(w, resp, err) {
|
||||
h.log.Errorf("err: %+v", err)
|
||||
return
|
||||
}
|
||||
h.log.Infof("secret %s created, ID: %s", s.Name, s.ID)
|
||||
h.log.Infof("secret %s created, ID: %s", rs.Name, rs.ID)
|
||||
|
||||
res := createSecretResponse(s)
|
||||
res := createSecretResponse(rs)
|
||||
if err := httpResponse(w, http.StatusOK, res); err != nil {
|
||||
h.log.Errorf("err: %+v", err)
|
||||
}
|
||||
|
@ -43,12 +43,12 @@ type VariableResponse struct {
|
||||
ParentPath string `json:"parent_path"`
|
||||
}
|
||||
|
||||
func createVariableResponse(v *types.Variable, secrets []*types.Secret) *VariableResponse {
|
||||
func createVariableResponse(v *csapi.Variable, secrets []*csapi.Secret) *VariableResponse {
|
||||
nv := &VariableResponse{
|
||||
ID: v.ID,
|
||||
Name: v.Name,
|
||||
Values: make([]VariableValue, len(v.Values)),
|
||||
ParentPath: v.Parent.Path,
|
||||
ParentPath: v.ParentPath,
|
||||
}
|
||||
|
||||
for i, varvalue := range v.Values {
|
||||
@ -58,9 +58,9 @@ func createVariableResponse(v *types.Variable, secrets []*types.Secret) *Variabl
|
||||
When: varvalue.When,
|
||||
}
|
||||
// get matching secret for var value
|
||||
secret := common.GetVarValueMatchingSecret(varvalue, v.Parent.Path, secrets)
|
||||
secret := common.GetVarValueMatchingSecret(varvalue, v.ParentPath, secrets)
|
||||
if secret != nil {
|
||||
nv.Values[i].MatchingSecretParentPath = secret.Parent.Path
|
||||
nv.Values[i].MatchingSecretParentPath = secret.ParentPath
|
||||
}
|
||||
}
|
||||
|
||||
@ -88,8 +88,8 @@ func (h *VariableHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
var csvars []*types.Variable
|
||||
var cssecrets []*types.Secret
|
||||
var csvars []*csapi.Variable
|
||||
var cssecrets []*csapi.Secret
|
||||
|
||||
switch parentType {
|
||||
case types.ConfigTypeProjectGroup:
|
||||
@ -184,7 +184,8 @@ func (h *CreateVariableHandler) ServeHTTP(w http.ResponseWriter, r *http.Request
|
||||
Values: req.Values,
|
||||
}
|
||||
|
||||
var cssecrets []*types.Secret
|
||||
var cssecrets []*csapi.Secret
|
||||
var rv *csapi.Variable
|
||||
|
||||
switch parentType {
|
||||
case types.ConfigTypeProjectGroup:
|
||||
@ -197,7 +198,7 @@ func (h *CreateVariableHandler) ServeHTTP(w http.ResponseWriter, r *http.Request
|
||||
}
|
||||
|
||||
h.log.Infof("creating project group variable")
|
||||
v, resp, err = h.configstoreClient.CreateProjectGroupVariable(ctx, parentRef, v)
|
||||
rv, resp, err = h.configstoreClient.CreateProjectGroupVariable(ctx, parentRef, v)
|
||||
if httpErrorFromRemote(w, resp, err) {
|
||||
h.log.Errorf("err: %+v", err)
|
||||
return
|
||||
@ -212,15 +213,15 @@ func (h *CreateVariableHandler) ServeHTTP(w http.ResponseWriter, r *http.Request
|
||||
}
|
||||
|
||||
h.log.Infof("creating project variable")
|
||||
v, resp, err = h.configstoreClient.CreateProjectVariable(ctx, parentRef, v)
|
||||
rv, resp, err = h.configstoreClient.CreateProjectVariable(ctx, parentRef, v)
|
||||
if httpErrorFromRemote(w, resp, err) {
|
||||
h.log.Errorf("err: %+v", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
h.log.Infof("variable %s created, ID: %s", v.Name, v.ID)
|
||||
h.log.Infof("variable %s created, ID: %s", rv.Name, rv.ID)
|
||||
|
||||
res := createVariableResponse(v, cssecrets)
|
||||
res := createVariableResponse(rv, cssecrets)
|
||||
if err := httpResponse(w, http.StatusCreated, res); err != nil {
|
||||
h.log.Errorf("err: %+v", err)
|
||||
}
|
||||
|
@ -15,20 +15,20 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
csapi "github.com/sorintlab/agola/internal/services/configstore/api"
|
||||
"github.com/sorintlab/agola/internal/services/types"
|
||||
"github.com/sorintlab/agola/internal/util"
|
||||
)
|
||||
|
||||
func FilterOverridenVariables(variables []*types.Variable) []*types.Variable {
|
||||
variablesMap := map[string]*types.Variable{}
|
||||
func FilterOverridenVariables(variables []*csapi.Variable) []*csapi.Variable {
|
||||
variablesMap := map[string]*csapi.Variable{}
|
||||
for _, v := range variables {
|
||||
if _, ok := variablesMap[v.Name]; !ok {
|
||||
variablesMap[v.Name] = v
|
||||
}
|
||||
}
|
||||
|
||||
filteredVariables := make([]*types.Variable, len(variablesMap))
|
||||
filteredVariables := make([]*csapi.Variable, len(variablesMap))
|
||||
i := 0
|
||||
// keep the original order
|
||||
for _, v := range variables {
|
||||
@ -43,15 +43,15 @@ func FilterOverridenVariables(variables []*types.Variable) []*types.Variable {
|
||||
return filteredVariables
|
||||
}
|
||||
|
||||
func GetVarValueMatchingSecret(varval types.VariableValue, varParentPath string, secrets []*types.Secret) *types.Secret {
|
||||
func GetVarValueMatchingSecret(varval types.VariableValue, varParentPath string, secrets []*csapi.Secret) *csapi.Secret {
|
||||
// get the secret value referenced by the variable, it must be a secret at the same level or a lower level
|
||||
var secret *types.Secret
|
||||
var secret *csapi.Secret
|
||||
for _, s := range secrets {
|
||||
// we assume the root path will be the same
|
||||
if s.Name != varval.SecretName {
|
||||
continue
|
||||
}
|
||||
if strings.Contains(varParentPath, s.Parent.Path) {
|
||||
if util.IsSameOrParentPath(s.ParentPath, varParentPath) {
|
||||
secret = s
|
||||
break
|
||||
}
|
||||
|
@ -18,86 +18,87 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
csapi "github.com/sorintlab/agola/internal/services/configstore/api"
|
||||
"github.com/sorintlab/agola/internal/services/types"
|
||||
)
|
||||
|
||||
func TestFilterOverridenVariables(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
variables []*types.Variable
|
||||
out []*types.Variable
|
||||
variables []*csapi.Variable
|
||||
out []*csapi.Variable
|
||||
}{
|
||||
{
|
||||
name: "test empty variables",
|
||||
variables: []*types.Variable{},
|
||||
out: []*types.Variable{},
|
||||
variables: []*csapi.Variable{},
|
||||
out: []*csapi.Variable{},
|
||||
},
|
||||
{
|
||||
name: "test variable overrides",
|
||||
variables: []*types.Variable{
|
||||
variables: []*csapi.Variable{
|
||||
// variables must be in depth (from leaves to root) order as returned by the
|
||||
// configstore apis
|
||||
&types.Variable{
|
||||
Name: "var04",
|
||||
Parent: types.Parent{
|
||||
Path: "org/org01/projectgroup02/projectgroup03/project02",
|
||||
&csapi.Variable{
|
||||
Variable: &types.Variable{
|
||||
Name: "var04",
|
||||
},
|
||||
ParentPath: "org/org01/projectgroup02/projectgroup03/project02",
|
||||
},
|
||||
&types.Variable{
|
||||
Name: "var03",
|
||||
Parent: types.Parent{
|
||||
Path: "org/org01/projectgroup01/project01",
|
||||
&csapi.Variable{
|
||||
Variable: &types.Variable{
|
||||
Name: "var03",
|
||||
},
|
||||
ParentPath: "org/org01/projectgroup01/project01",
|
||||
},
|
||||
&types.Variable{
|
||||
Name: "var02",
|
||||
Parent: types.Parent{
|
||||
Path: "org/org01/projectgroup01/project01",
|
||||
&csapi.Variable{
|
||||
Variable: &types.Variable{
|
||||
Name: "var02",
|
||||
},
|
||||
ParentPath: "org/org01/projectgroup01/project01",
|
||||
},
|
||||
&types.Variable{
|
||||
Name: "var02",
|
||||
Parent: types.Parent{
|
||||
Path: "org/org01/projectgroup01",
|
||||
&csapi.Variable{
|
||||
Variable: &types.Variable{
|
||||
Name: "var02",
|
||||
},
|
||||
ParentPath: "org/org01/projectgroup01",
|
||||
},
|
||||
&types.Variable{
|
||||
Name: "var01",
|
||||
Parent: types.Parent{
|
||||
Path: "org/org01/projectgroup01",
|
||||
&csapi.Variable{
|
||||
Variable: &types.Variable{
|
||||
Name: "var01",
|
||||
},
|
||||
ParentPath: "org/org01/projectgroup01",
|
||||
},
|
||||
&types.Variable{
|
||||
Name: "var01",
|
||||
Parent: types.Parent{
|
||||
Path: "org/org01",
|
||||
&csapi.Variable{
|
||||
Variable: &types.Variable{
|
||||
Name: "var01",
|
||||
},
|
||||
ParentPath: "org/org01",
|
||||
},
|
||||
},
|
||||
out: []*types.Variable{
|
||||
&types.Variable{
|
||||
Name: "var04",
|
||||
Parent: types.Parent{
|
||||
Path: "org/org01/projectgroup02/projectgroup03/project02",
|
||||
out: []*csapi.Variable{
|
||||
&csapi.Variable{
|
||||
Variable: &types.Variable{
|
||||
Name: "var04",
|
||||
},
|
||||
ParentPath: "org/org01/projectgroup02/projectgroup03/project02",
|
||||
},
|
||||
&types.Variable{
|
||||
Name: "var03",
|
||||
Parent: types.Parent{
|
||||
Path: "org/org01/projectgroup01/project01",
|
||||
&csapi.Variable{
|
||||
Variable: &types.Variable{
|
||||
Name: "var03",
|
||||
},
|
||||
ParentPath: "org/org01/projectgroup01/project01",
|
||||
},
|
||||
&types.Variable{
|
||||
Name: "var02",
|
||||
Parent: types.Parent{
|
||||
Path: "org/org01/projectgroup01/project01",
|
||||
&csapi.Variable{
|
||||
Variable: &types.Variable{
|
||||
Name: "var02",
|
||||
},
|
||||
ParentPath: "org/org01/projectgroup01/project01",
|
||||
},
|
||||
&types.Variable{
|
||||
Name: "var01",
|
||||
Parent: types.Parent{
|
||||
Path: "org/org01/projectgroup01",
|
||||
&csapi.Variable{
|
||||
Variable: &types.Variable{
|
||||
Name: "var01",
|
||||
},
|
||||
ParentPath: "org/org01/projectgroup01",
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -119,8 +120,8 @@ func TestGetVarValueMatchingSecret(t *testing.T) {
|
||||
name string
|
||||
varValue types.VariableValue
|
||||
varParentPath string
|
||||
secrets []*types.Secret
|
||||
out *types.Secret
|
||||
secrets []*csapi.Secret
|
||||
out *csapi.Secret
|
||||
}{
|
||||
{
|
||||
name: "test empty secrets",
|
||||
@ -129,7 +130,7 @@ func TestGetVarValueMatchingSecret(t *testing.T) {
|
||||
SecretVar: "secretvar01",
|
||||
},
|
||||
varParentPath: "org/org01/projectgroup01/project01",
|
||||
secrets: []*types.Secret{},
|
||||
secrets: []*csapi.Secret{},
|
||||
out: nil,
|
||||
},
|
||||
{
|
||||
@ -139,12 +140,12 @@ func TestGetVarValueMatchingSecret(t *testing.T) {
|
||||
SecretVar: "secretvar01",
|
||||
},
|
||||
varParentPath: "org/org01/projectgroup01/projectgroup02",
|
||||
secrets: []*types.Secret{
|
||||
&types.Secret{
|
||||
Name: "secret02",
|
||||
Parent: types.Parent{
|
||||
Path: "org/org01/projectgroup01/projectgroup02",
|
||||
secrets: []*csapi.Secret{
|
||||
&csapi.Secret{
|
||||
Secret: &types.Secret{
|
||||
Name: "secret02",
|
||||
},
|
||||
ParentPath: "org/org01/projectgroup01/projectgroup02",
|
||||
},
|
||||
},
|
||||
out: nil,
|
||||
@ -156,12 +157,12 @@ func TestGetVarValueMatchingSecret(t *testing.T) {
|
||||
SecretVar: "secretvar01",
|
||||
},
|
||||
varParentPath: "org/org01/projectgroup01/projectgroup02",
|
||||
secrets: []*types.Secret{
|
||||
&types.Secret{
|
||||
Name: "secret02",
|
||||
Parent: types.Parent{
|
||||
Path: "org/org01/projectgroup01/projectgroup03",
|
||||
secrets: []*csapi.Secret{
|
||||
&csapi.Secret{
|
||||
Secret: &types.Secret{
|
||||
Name: "secret02",
|
||||
},
|
||||
ParentPath: "org/org01/projectgroup01/projectgroup03",
|
||||
},
|
||||
},
|
||||
out: nil,
|
||||
@ -173,12 +174,12 @@ func TestGetVarValueMatchingSecret(t *testing.T) {
|
||||
SecretVar: "secretvar01",
|
||||
},
|
||||
varParentPath: "org/org01/projectgroup01/projectgroup02",
|
||||
secrets: []*types.Secret{
|
||||
&types.Secret{
|
||||
Name: "secret01",
|
||||
Parent: types.Parent{
|
||||
Path: "org/org01/projectgroup01/projectgroup02/project01",
|
||||
secrets: []*csapi.Secret{
|
||||
&csapi.Secret{
|
||||
Secret: &types.Secret{
|
||||
Name: "secret01",
|
||||
},
|
||||
ParentPath: "org/org01/projectgroup01/projectgroup02/project01",
|
||||
},
|
||||
},
|
||||
out: nil,
|
||||
@ -190,25 +191,25 @@ func TestGetVarValueMatchingSecret(t *testing.T) {
|
||||
SecretVar: "secretvar01",
|
||||
},
|
||||
varParentPath: "org/org01/projectgroup01/projectgroup02",
|
||||
secrets: []*types.Secret{
|
||||
&types.Secret{
|
||||
Name: "secret01",
|
||||
Parent: types.Parent{
|
||||
Path: "org/org01/projectgroup01/projectgroup02/project01",
|
||||
secrets: []*csapi.Secret{
|
||||
&csapi.Secret{
|
||||
Secret: &types.Secret{
|
||||
Name: "secret01",
|
||||
},
|
||||
ParentPath: "org/org01/projectgroup01/projectgroup02/project01",
|
||||
},
|
||||
&types.Secret{
|
||||
Name: "secret01",
|
||||
Parent: types.Parent{
|
||||
Path: "org/org01/projectgroup01/projectgroup02",
|
||||
&csapi.Secret{
|
||||
Secret: &types.Secret{
|
||||
Name: "secret01",
|
||||
},
|
||||
ParentPath: "org/org01/projectgroup01/projectgroup02",
|
||||
},
|
||||
},
|
||||
out: &types.Secret{
|
||||
Name: "secret01",
|
||||
Parent: types.Parent{
|
||||
Path: "org/org01/projectgroup01/projectgroup02",
|
||||
out: &csapi.Secret{
|
||||
Secret: &types.Secret{
|
||||
Name: "secret01",
|
||||
},
|
||||
ParentPath: "org/org01/projectgroup01/projectgroup02",
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -218,19 +219,19 @@ func TestGetVarValueMatchingSecret(t *testing.T) {
|
||||
SecretVar: "secretvar01",
|
||||
},
|
||||
varParentPath: "org/org01/projectgroup01/projectgroup02",
|
||||
secrets: []*types.Secret{
|
||||
&types.Secret{
|
||||
Name: "secret01",
|
||||
Parent: types.Parent{
|
||||
Path: "org/org01/projectgroup01",
|
||||
secrets: []*csapi.Secret{
|
||||
&csapi.Secret{
|
||||
Secret: &types.Secret{
|
||||
Name: "secret01",
|
||||
},
|
||||
ParentPath: "org/org01/projectgroup01",
|
||||
},
|
||||
},
|
||||
out: &types.Secret{
|
||||
Name: "secret01",
|
||||
Parent: types.Parent{
|
||||
Path: "org/org01/projectgroup01",
|
||||
out: &csapi.Secret{
|
||||
Secret: &types.Secret{
|
||||
Name: "secret01",
|
||||
},
|
||||
ParentPath: "org/org01/projectgroup01",
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -240,33 +241,33 @@ func TestGetVarValueMatchingSecret(t *testing.T) {
|
||||
SecretVar: "secretvar01",
|
||||
},
|
||||
varParentPath: "org/org01/projectgroup01/projectgroup02",
|
||||
secrets: []*types.Secret{
|
||||
secrets: []*csapi.Secret{
|
||||
// secrets must be in depth (from leaves to root) order as returned by the
|
||||
// configstore apis
|
||||
&types.Secret{
|
||||
Name: "secret01",
|
||||
Parent: types.Parent{
|
||||
Path: "org/org01/projectgroup01/projectgroup02/project01",
|
||||
&csapi.Secret{
|
||||
Secret: &types.Secret{
|
||||
Name: "secret01",
|
||||
},
|
||||
ParentPath: "org/org01/projectgroup01/projectgroup02/project01",
|
||||
},
|
||||
&types.Secret{
|
||||
Name: "secret01",
|
||||
Parent: types.Parent{
|
||||
Path: "org/org01/projectgroup01/projectgroup02",
|
||||
&csapi.Secret{
|
||||
Secret: &types.Secret{
|
||||
Name: "secret01",
|
||||
},
|
||||
ParentPath: "org/org01/projectgroup01/projectgroup02",
|
||||
},
|
||||
&types.Secret{
|
||||
Name: "secret01",
|
||||
Parent: types.Parent{
|
||||
Path: "org/org01/projectgroup01",
|
||||
&csapi.Secret{
|
||||
Secret: &types.Secret{
|
||||
Name: "secret01",
|
||||
},
|
||||
ParentPath: "org/org01/projectgroup01",
|
||||
},
|
||||
},
|
||||
out: &types.Secret{
|
||||
Name: "secret01",
|
||||
Parent: types.Parent{
|
||||
Path: "org/org01/projectgroup01/projectgroup02",
|
||||
out: &csapi.Secret{
|
||||
Secret: &types.Secret{
|
||||
Name: "secret01",
|
||||
},
|
||||
ParentPath: "org/org01/projectgroup01/projectgroup02",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -217,7 +217,7 @@ func (h *webhooksHandler) handleWebhook(r *http.Request) (int, string, error) {
|
||||
continue
|
||||
}
|
||||
// get the secret value referenced by the variable, it must be a secret at the same level or a lower level
|
||||
secret := common.GetVarValueMatchingSecret(varval, pvar.Parent.Path, secrets)
|
||||
secret := common.GetVarValueMatchingSecret(varval, pvar.ParentPath, secrets)
|
||||
h.log.Infof("secret: %v", util.Dump(secret))
|
||||
if secret != nil {
|
||||
varValue, ok := secret.Data[varval.SecretVar]
|
||||
|
@ -36,9 +36,6 @@ const (
|
||||
type Parent struct {
|
||||
Type ConfigType `json:"type,omitempty"`
|
||||
ID string `json:"id,omitempty"`
|
||||
|
||||
// fields the is only used in api response and shoukd be empty when saved in the store
|
||||
Path string `json:"path,omitempty"`
|
||||
}
|
||||
|
||||
type User struct {
|
||||
|
Loading…
Reference in New Issue
Block a user