Skip to content

Commit

Permalink
Merge pull request #190 from GoogleCloudPlatform/issue189
Browse files Browse the repository at this point in the history
bug: fixes default value of int #189
  • Loading branch information
ssvaidyanathan authored Feb 22, 2024
2 parents 6d1164a + 58b10e5 commit d845d84
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 40 deletions.
65 changes: 32 additions & 33 deletions internal/client/integrations/integrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,14 @@ type tasks struct {
}

type eventparameter struct {
Key string `json:"key,omitempty"`
Value valueType `json:"value,omitempty"`
Key string `json:"key,omitempty"`
Value valueType `json:"value,omitempty"`
Masked bool `json:"masked,omitempty"`
}

type valueType struct {
StringValue *string `json:"stringValue,omitempty"`
IntValue *string `json:"intValue,omitempty"`
BooleanValue *bool `json:"booleanValue,omitempty"`
StringArray *stringarraytype `json:"stringArray,omitempty"`
JsonValue *string `json:"jsonValue,omitempty"`
Expand Down Expand Up @@ -494,30 +496,33 @@ func Get(name string, version string, basicInfo bool, minimal bool, override boo

u, _ := url.Parse(apiclient.GetBaseIntegrationURL())
u.Path = path.Join(u.Path, "integrations", name, "versions", version)
if basicInfo {
apiclient.ClientPrintHttpResponse.Set(false)
respBody, err := apiclient.HttpClient(u.String())
if err != nil {
return nil, err
}
// restore print setting
apiclient.ClientPrintHttpResponse.Set(false)

respBody, err := apiclient.HttpClient(u.String())

if !override && !minimal && !basicInfo {
apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting())
return getBasicInfo(respBody)
apiclient.PrettyPrint(respBody)
return respBody, nil
}

if override || minimal {
apiclient.ClientPrintHttpResponse.Set(false)
iversion := integrationVersion{}
err = json.Unmarshal(respBody, &iversion)
if err != nil {
return nil, err
}

respBody, err := apiclient.HttpClient(u.String())

if minimal {
iversion := integrationVersion{}
err = json.Unmarshal(respBody, &iversion)
if err != nil {
if basicInfo {
var respBasicBody []byte
apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting())
if respBasicBody, err = getBasicInfo(respBody); err != nil {
return nil, err
}
apiclient.PrettyPrint(respBasicBody)
return respBasicBody, nil
}

if minimal {
eversion := convertInternalToExternal(iversion)
respExtBody, err := json.Marshal(eversion)
if err != nil {
Expand All @@ -529,12 +534,6 @@ func Get(name string, version string, basicInfo bool, minimal bool, override boo
}

if override {
iversion := integrationVersion{}
err = json.Unmarshal(respBody, &iversion)
if err != nil {
return nil, err
}

var or overrides
var respOvrBody []byte
if or, err = extractOverrides(iversion); err != nil {
Expand All @@ -545,20 +544,22 @@ func Get(name string, version string, basicInfo bool, minimal bool, override boo
}
apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting())
apiclient.PrettyPrint(respOvrBody)
return respOvrBody, err
return respOvrBody, nil
}
return respBody, err
}

// GetBySnapshot
func GetBySnapshot(name string, snapshot string, minimal bool, override bool) ([]byte, error) {
func GetBySnapshot(name string, snapshot string, basicInfo bool, minimal bool, override bool) ([]byte, error) {
apiclient.ClientPrintHttpResponse.Set(false)

listBody, err := ListVersions(name, -1, "", "snapshotNumber="+snapshot, "", false, false, true)
if err != nil {
return nil, err
}

apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting())

listBasicVersions := listbasicIntegrationVersions{}
err = json.Unmarshal(listBody, &listBasicVersions)
if err != nil {
Expand All @@ -570,13 +571,11 @@ func GetBySnapshot(name string, snapshot string, minimal bool, override bool) ([
}

version := getVersion(listBasicVersions.BasicIntegrationVersions[0].Version)
respBody, err := Get(name, version, false, minimal, override)
apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting())
return respBody, err
return Get(name, version, basicInfo, minimal, override)
}

// GetByUserlabel
func GetByUserlabel(name string, userLabel string, minimal bool, override bool) ([]byte, error) {
func GetByUserlabel(name string, userLabel string, basicInfo bool, minimal bool, override bool) ([]byte, error) {
apiclient.ClientPrintHttpResponse.Set(false)

listBody, err := ListVersions(name, -1, "", "userLabel="+userLabel, "", false, false, true)
Expand Down Expand Up @@ -619,7 +618,7 @@ func DeleteVersion(name string, version string) (respBody []byte, err error) {
// DeleteByUserlabel
func DeleteByUserlabel(name string, userLabel string) (respBody []byte, err error) {
apiclient.ClientPrintHttpResponse.Set(false)
iversionBytes, err := GetByUserlabel(name, userLabel, false, false)
iversionBytes, err := GetByUserlabel(name, userLabel, false, false, false)
if err != nil {
return nil, err
}
Expand All @@ -638,7 +637,7 @@ func DeleteByUserlabel(name string, userLabel string) (respBody []byte, err erro
// DeleteBySnapshot
func DeleteBySnapshot(name string, snapshot string) (respBody []byte, err error) {
apiclient.ClientPrintHttpResponse.Set(false)
iversionBytes, err := GetBySnapshot(name, snapshot, false, false)
iversionBytes, err := GetBySnapshot(name, snapshot, false, false, false)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1256,7 +1255,7 @@ func getBasicInfo(respBody []byte) (newResp []byte, err error) {
bIVer.Version = getVersion(iVer.Name)

if newResp, err = json.Marshal(bIVer); err != nil {
apiclient.PrettyPrint(newResp)
return nil, err
}

return newResp, err
Expand Down
9 changes: 9 additions & 0 deletions internal/client/integrations/integrations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,12 @@ func TestCreateVersionOverrides(t *testing.T) {
t.Fatalf("Create failed: %v", err)
}
}

func TestDelete(t *testing.T) {
if err := clienttest.TestSetup(); err != nil {
t.Fatalf("TestSetup failed: %v", err)
}
if _, err := Delete("test"); err != nil {
t.Fatalf("Delete failed: %v", err)
}
}
4 changes: 3 additions & 1 deletion internal/client/integrations/overrides.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,9 @@ func extractOverrides(iversion integrationVersion) (overrides, error) {
if strings.HasPrefix(param.Key, "_") && !inputOutputVariable(param.InputOutputType) {
ip := parameterExternal{}
ip.Key = param.Key
ip.DefaultValue = param.DefaultValue
if param.DefaultValue != nil {
ip.DefaultValue = param.DefaultValue
}
taskOverrides.ParamOverrides = append(taskOverrides.ParamOverrides, ip)
}
}
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/integrations/getversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ var GetVerCmd = &cobra.Command{
if version != "" {
_, err = integrations.Get(name, version, basic, minimal, overrides)
} else if snapshot != "" {
_, err = integrations.GetBySnapshot(name, snapshot, minimal, overrides)
_, err = integrations.GetBySnapshot(name, snapshot, basic, minimal, overrides)
} else {
_, err = integrations.GetByUserlabel(name, userLabel, minimal, overrides)
_, err = integrations.GetByUserlabel(name, userLabel, basic, minimal, overrides)
}
return err
},
Expand Down
8 changes: 4 additions & 4 deletions internal/cmd/integrations/scaffold.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,17 @@ var ScaffoldCmd = &cobra.Command{
return err
}
} else if userLabel != "" {
if integrationBody, err = integrations.GetByUserlabel(name, userLabel, true, false); err != nil {
if integrationBody, err = integrations.GetByUserlabel(name, userLabel, false, true, false); err != nil {
return err
}
if overridesBody, err = integrations.GetByUserlabel(name, userLabel, false, true); err != nil {
if overridesBody, err = integrations.GetByUserlabel(name, userLabel, false, false, true); err != nil {
return err
}
} else if snapshot != "" {
if integrationBody, err = integrations.GetBySnapshot(name, snapshot, true, false); err != nil {
if integrationBody, err = integrations.GetBySnapshot(name, snapshot, false, true, false); err != nil {
return err
}
if overridesBody, err = integrations.GetBySnapshot(name, snapshot, false, true); err != nil {
if overridesBody, err = integrations.GetBySnapshot(name, snapshot, false, false, true); err != nil {
return err
}
}
Expand Down

0 comments on commit d845d84

Please sign in to comment.