cmd: fix variable create/update
In c1ff28ef9f
we exported various types. Unfortunately the types used by cmd
variable create/update are the wrong types and marshalling fails. Fix it using
the right type. In future this internal types should be exported.
This commit is contained in:
parent
afcd05244f
commit
53dad95cd0
|
@ -19,6 +19,8 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
config "agola.io/agola/internal/config"
|
||||||
|
cstypes "agola.io/agola/services/configstore/types"
|
||||||
gwapitypes "agola.io/agola/services/gateway/api/types"
|
gwapitypes "agola.io/agola/services/gateway/api/types"
|
||||||
gwclient "agola.io/agola/services/gateway/client"
|
gwclient "agola.io/agola/services/gateway/client"
|
||||||
|
|
||||||
|
@ -91,7 +93,7 @@ type VariableValue struct {
|
||||||
SecretName string `json:"secret_name,omitempty"`
|
SecretName string `json:"secret_name,omitempty"`
|
||||||
SecretVar string `json:"secret_var,omitempty"`
|
SecretVar string `json:"secret_var,omitempty"`
|
||||||
|
|
||||||
When *gwapitypes.When `json:"when,omitempty"`
|
When *config.When `json:"when,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func variableCreate(cmd *cobra.Command, ownertype string, args []string) error {
|
func variableCreate(cmd *cobra.Command, ownertype string, args []string) error {
|
||||||
|
@ -121,7 +123,7 @@ func variableCreate(cmd *cobra.Command, ownertype string, args []string) error {
|
||||||
rvalues = append(rvalues, gwapitypes.VariableValueRequest{
|
rvalues = append(rvalues, gwapitypes.VariableValueRequest{
|
||||||
SecretName: value.SecretName,
|
SecretName: value.SecretName,
|
||||||
SecretVar: value.SecretVar,
|
SecretVar: value.SecretVar,
|
||||||
When: value.When,
|
When: fromCsWhen(value.When.ToCSWhen()),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
req := &gwapitypes.CreateVariableRequest{
|
req := &gwapitypes.CreateVariableRequest{
|
||||||
|
@ -148,3 +150,36 @@ func variableCreate(cmd *cobra.Command, ownertype string, args []string) error {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func fromCsWhenCondition(apiwc cstypes.WhenCondition) gwapitypes.WhenCondition {
|
||||||
|
return gwapitypes.WhenCondition{
|
||||||
|
Type: gwapitypes.WhenConditionType(apiwc.Type),
|
||||||
|
Match: apiwc.Match,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func fromCsWhenConditions(apiwcs *cstypes.WhenConditions) *gwapitypes.WhenConditions {
|
||||||
|
if apiwcs == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
wcs := &gwapitypes.WhenConditions{
|
||||||
|
Include: make([]gwapitypes.WhenCondition, len(apiwcs.Include)),
|
||||||
|
Exclude: make([]gwapitypes.WhenCondition, len(apiwcs.Exclude)),
|
||||||
|
}
|
||||||
|
for i, include := range apiwcs.Include {
|
||||||
|
wcs.Include[i] = fromCsWhenCondition(include)
|
||||||
|
}
|
||||||
|
for i, exclude := range apiwcs.Exclude {
|
||||||
|
wcs.Exclude[i] = fromCsWhenCondition(exclude)
|
||||||
|
}
|
||||||
|
|
||||||
|
return wcs
|
||||||
|
}
|
||||||
|
|
||||||
|
func fromCsWhen(apiwhen *cstypes.When) *gwapitypes.When {
|
||||||
|
return &gwapitypes.When{
|
||||||
|
Branch: fromCsWhenConditions(apiwhen.Branch),
|
||||||
|
Tag: fromCsWhenConditions(apiwhen.Tag),
|
||||||
|
Ref: fromCsWhenConditions(apiwhen.Ref),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -94,7 +94,7 @@ func variableUpdate(cmd *cobra.Command, ownertype string, args []string) error {
|
||||||
rvalues = append(rvalues, gwapitypes.VariableValueRequest{
|
rvalues = append(rvalues, gwapitypes.VariableValueRequest{
|
||||||
SecretName: value.SecretName,
|
SecretName: value.SecretName,
|
||||||
SecretVar: value.SecretVar,
|
SecretVar: value.SecretVar,
|
||||||
When: value.When,
|
When: fromCsWhen(value.When.ToCSWhen()),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
req := &gwapitypes.UpdateVariableRequest{
|
req := &gwapitypes.UpdateVariableRequest{
|
||||||
|
|
|
@ -23,9 +23,9 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
slog "agola.io/agola/internal/log"
|
slog "agola.io/agola/internal/log"
|
||||||
|
"agola.io/agola/internal/testutil"
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
uuid "github.com/satori/go.uuid"
|
uuid "github.com/satori/go.uuid"
|
||||||
"agola.io/agola/internal/testutil"
|
|
||||||
|
|
||||||
"github.com/google/go-cmp/cmp"
|
"github.com/google/go-cmp/cmp"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
|
|
@ -235,6 +235,9 @@ func fromApiWhenCondition(apiwc gwapitypes.WhenCondition) cstypes.WhenCondition
|
||||||
}
|
}
|
||||||
|
|
||||||
func fromApiWhenConditions(apiwcs *gwapitypes.WhenConditions) *cstypes.WhenConditions {
|
func fromApiWhenConditions(apiwcs *gwapitypes.WhenConditions) *cstypes.WhenConditions {
|
||||||
|
if apiwcs == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
wcs := &cstypes.WhenConditions{
|
wcs := &cstypes.WhenConditions{
|
||||||
Include: make([]cstypes.WhenCondition, len(apiwcs.Include)),
|
Include: make([]cstypes.WhenCondition, len(apiwcs.Include)),
|
||||||
Exclude: make([]cstypes.WhenCondition, len(apiwcs.Exclude)),
|
Exclude: make([]cstypes.WhenCondition, len(apiwcs.Exclude)),
|
||||||
|
@ -265,6 +268,9 @@ func fromCsWhenCondition(apiwc cstypes.WhenCondition) gwapitypes.WhenCondition {
|
||||||
}
|
}
|
||||||
|
|
||||||
func fromCsWhenConditions(apiwcs *cstypes.WhenConditions) *gwapitypes.WhenConditions {
|
func fromCsWhenConditions(apiwcs *cstypes.WhenConditions) *gwapitypes.WhenConditions {
|
||||||
|
if apiwcs == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
wcs := &gwapitypes.WhenConditions{
|
wcs := &gwapitypes.WhenConditions{
|
||||||
Include: make([]gwapitypes.WhenCondition, len(apiwcs.Include)),
|
Include: make([]gwapitypes.WhenCondition, len(apiwcs.Include)),
|
||||||
Exclude: make([]gwapitypes.WhenCondition, len(apiwcs.Exclude)),
|
Exclude: make([]gwapitypes.WhenCondition, len(apiwcs.Exclude)),
|
||||||
|
|
Loading…
Reference in New Issue