Skip to content
This repository has been archived by the owner on Mar 9, 2023. It is now read-only.

Commit

Permalink
Merge pull request #126 from srinandan/minimal
Browse files Browse the repository at this point in the history
Return Minimal fields
  • Loading branch information
srinandan authored Feb 26, 2023
2 parents 0a2c175 + d16151c commit 00b2865
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 14 deletions.
31 changes: 29 additions & 2 deletions client/connections/connectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,14 +331,41 @@ func Delete(name string) (respBody []byte, err error) {
}

// Get
func Get(name string, view string) (respBody []byte, err error) {
func Get(name string, view string, minimal bool) (respBody []byte, err error) {
u, _ := url.Parse(apiclient.GetBaseConnectorURL())
q := u.Query()
if view != "" {
q.Set("view", view)
}
u.Path = path.Join(u.Path, name)

tmp := apiclient.GetPrintOutput()

if minimal {
apiclient.SetPrintOutput(false)
}

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

if minimal {
c := connection{}
err := json.Unmarshal(respBody, &c)
if err != nil {
return nil, err
}
c.ConnectorDetails = new(connectorDetails)
c.ConnectorDetails.Name = getConnectorName(*c.ConnectorVersion)
c.ConnectorDetails.Version = getConnectorVersion(*c.ConnectorVersion)
c.ConnectorVersion = nil
c.Name = nil
connectionPayload, err := json.Marshal(c)
if err != nil {
return nil, err
}
apiclient.SetPrintOutput(tmp) //set original print output
apiclient.PrettyPrint(connectionPayload)
return connectionPayload, err
}
return respBody, err
}

Expand Down Expand Up @@ -419,7 +446,7 @@ func Import(folder string) (err error) {
return err
}

if _, err := Get(name, ""); err != nil { //create only if connection doesn't exist
if _, err := Get(name, "", false); err != nil { //create only if connection doesn't exist
_, err = Create(name, content, "", "", "", false)
if err != nil {
errs = append(errs, err.Error())
Expand Down
39 changes: 32 additions & 7 deletions client/integrations/integrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ func List(pageSize int, pageToken string, filter string, orderBy string) (respBo
}

// Get
func Get(name string, version string, basicInfo bool, override bool) ([]byte, error) {
func Get(name string, version string, basicInfo bool, minimal bool, override bool) ([]byte, error) {
u, _ := url.Parse(apiclient.GetBaseIntegrationURL())
u.Path = path.Join(u.Path, "integrations", name, "versions", version)
if basicInfo {
Expand All @@ -448,25 +448,50 @@ func Get(name string, version string, basicInfo bool, override bool) ([]byte, er
apiclient.SetPrintOutput(printSetting)
return getBasicInfo(respBody)
}
apiclient.SetPrintOutput(!override)

tmp := apiclient.GetPrintOutput()

if override || minimal {
apiclient.SetPrintOutput(false)
}

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

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

eversion := convertInternalToExternal(iversion)
respBody, err = json.Marshal(eversion)
apiclient.SetPrintOutput(tmp)
apiclient.PrettyPrint(respBody)
}

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

or := overrides{}
if or, err = extractOverrides(iversion); err != nil {
return nil, err
}
if respBody, err = json.Marshal(or); err != nil {
return nil, err
}
apiclient.SetPrintOutput(tmp)
apiclient.PrettyPrint(respBody)
}
return respBody, err
}

// GetBySnapshot
func GetBySnapshot(name string, snapshot string, override bool) ([]byte, error) {
func GetBySnapshot(name string, snapshot string, minimal bool, override bool) ([]byte, error) {
apiclient.SetPrintOutput(false)
listBody, err := ListVersions(name, -1, "", "snapshotNumber="+snapshot, "", false, false, true)
if err != nil {
Expand All @@ -485,11 +510,11 @@ func GetBySnapshot(name string, snapshot string, override bool) ([]byte, error)
}

version := getVersion(listBasicVersions.BasicIntegrationVersions[0].Version)
return Get(name, version, false, override)
return Get(name, version, false, minimal, override)
}

// GetByUserlabel
func GetByUserlabel(name string, userLabel string, override bool) ([]byte, error) {
func GetByUserlabel(name string, userLabel string, minimal bool, override bool) ([]byte, error) {
apiclient.SetPrintOutput(false)
listBody, err := ListVersions(name, -1, "", "userLabel="+userLabel, "", false, false, true)
if err != nil {
Expand All @@ -507,7 +532,7 @@ func GetByUserlabel(name string, userLabel string, override bool) ([]byte, error
}

version := getVersion(listBasicVersions.BasicIntegrationVersions[0].Version)
return Get(name, version, false, override)
return Get(name, version, false, minimal, override)
}

// Delete - THIS IS UNIMPLEMENTED!!!
Expand Down
2 changes: 1 addition & 1 deletion client/integrations/overrides.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ func getNewConnectionParams(connectionName string, connectionLocation string) (c
integrationRegion = apiclient.GetRegion() //store the integration location
apiclient.SetRegion(connectionLocation) //set the connector region
}
connResp, err := connections.Get(connectionName, "BASIC") //get connector details
connResp, err := connections.Get(connectionName, "BASIC", false) //get connector details
apiclient.SetPrintOutput(true)
if connectionLocation != "" {
apiclient.SetRegion(integrationRegion) //set the integration region back
Expand Down
5 changes: 4 additions & 1 deletion cmd/connectors/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,21 @@ var GetCmd = &cobra.Command{
return apiclient.SetProjectID(project)
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
_, err = connections.Get(name, view)
_, err = connections.Get(name, view, minimal)
return
},
}

var view string
var minimal bool

func init() {
GetCmd.Flags().StringVarP(&name, "name", "n",
"", "The name of the connection")
GetCmd.Flags().StringVarP(&view, "view", "",
"BASIC", "fields of the Connection to be returned; default is BASIC. FULL is the other option")
GetCmd.Flags().BoolVarP(&minimal, "minimal", "",
false, "fields of the Connection to be returned; default is false")

_ = GetCmd.MarkFlagRequired("name")
}
10 changes: 7 additions & 3 deletions cmd/integrations/getversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,19 @@ var GetVerCmd = &cobra.Command{
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
if version != "" {
_, err = integrations.Get(name, version, basic, overrides)
_, err = integrations.Get(name, version, basic, minimal, overrides)
} else if snapshot != "" {
_, err = integrations.GetBySnapshot(name, snapshot, overrides)
_, err = integrations.GetBySnapshot(name, snapshot, minimal, overrides)
} else {
_, err = integrations.GetByUserlabel(name, userLabel, overrides)
_, err = integrations.GetByUserlabel(name, userLabel, minimal, overrides)
}
return

},
}

var minimal bool

func init() {
GetVerCmd.Flags().StringVarP(&name, "name", "n",
"", "Integration flow name")
Expand All @@ -72,6 +74,8 @@ func init() {
false, "Returns snapshot and version only")
GetVerCmd.Flags().BoolVarP(&overrides, "overrides", "o",
false, "Returns overrides only for integration")
GetVerCmd.Flags().BoolVarP(&minimal, "minimal", "",
false, "fields of the Integration to be returned; default is false")

_ = GetVerCmd.MarkFlagRequired("name")
}

0 comments on commit 00b2865

Please sign in to comment.