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

Commit 00b2865

Browse files
authored
Merge pull request #126 from srinandan/minimal
Return Minimal fields
2 parents 0a2c175 + d16151c commit 00b2865

File tree

5 files changed

+73
-14
lines changed

5 files changed

+73
-14
lines changed

client/connections/connectors.go

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,14 +331,41 @@ func Delete(name string) (respBody []byte, err error) {
331331
}
332332

333333
// Get
334-
func Get(name string, view string) (respBody []byte, err error) {
334+
func Get(name string, view string, minimal bool) (respBody []byte, err error) {
335335
u, _ := url.Parse(apiclient.GetBaseConnectorURL())
336336
q := u.Query()
337337
if view != "" {
338338
q.Set("view", view)
339339
}
340340
u.Path = path.Join(u.Path, name)
341+
342+
tmp := apiclient.GetPrintOutput()
343+
344+
if minimal {
345+
apiclient.SetPrintOutput(false)
346+
}
347+
341348
respBody, err = apiclient.HttpClient(apiclient.GetPrintOutput(), u.String())
349+
350+
if minimal {
351+
c := connection{}
352+
err := json.Unmarshal(respBody, &c)
353+
if err != nil {
354+
return nil, err
355+
}
356+
c.ConnectorDetails = new(connectorDetails)
357+
c.ConnectorDetails.Name = getConnectorName(*c.ConnectorVersion)
358+
c.ConnectorDetails.Version = getConnectorVersion(*c.ConnectorVersion)
359+
c.ConnectorVersion = nil
360+
c.Name = nil
361+
connectionPayload, err := json.Marshal(c)
362+
if err != nil {
363+
return nil, err
364+
}
365+
apiclient.SetPrintOutput(tmp) //set original print output
366+
apiclient.PrettyPrint(connectionPayload)
367+
return connectionPayload, err
368+
}
342369
return respBody, err
343370
}
344371

@@ -419,7 +446,7 @@ func Import(folder string) (err error) {
419446
return err
420447
}
421448

422-
if _, err := Get(name, ""); err != nil { //create only if connection doesn't exist
449+
if _, err := Get(name, "", false); err != nil { //create only if connection doesn't exist
423450
_, err = Create(name, content, "", "", "", false)
424451
if err != nil {
425452
errs = append(errs, err.Error())

client/integrations/integrations.go

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ func List(pageSize int, pageToken string, filter string, orderBy string) (respBo
432432
}
433433

434434
// Get
435-
func Get(name string, version string, basicInfo bool, override bool) ([]byte, error) {
435+
func Get(name string, version string, basicInfo bool, minimal bool, override bool) ([]byte, error) {
436436
u, _ := url.Parse(apiclient.GetBaseIntegrationURL())
437437
u.Path = path.Join(u.Path, "integrations", name, "versions", version)
438438
if basicInfo {
@@ -448,25 +448,50 @@ func Get(name string, version string, basicInfo bool, override bool) ([]byte, er
448448
apiclient.SetPrintOutput(printSetting)
449449
return getBasicInfo(respBody)
450450
}
451-
apiclient.SetPrintOutput(!override)
451+
452+
tmp := apiclient.GetPrintOutput()
453+
454+
if override || minimal {
455+
apiclient.SetPrintOutput(false)
456+
}
457+
452458
respBody, err := apiclient.HttpClient(apiclient.GetPrintOutput(), u.String())
459+
460+
if minimal {
461+
iversion := integrationVersion{}
462+
err = json.Unmarshal(respBody, &iversion)
463+
if err != nil {
464+
return nil, err
465+
}
466+
467+
eversion := convertInternalToExternal(iversion)
468+
respBody, err = json.Marshal(eversion)
469+
apiclient.SetPrintOutput(tmp)
470+
apiclient.PrettyPrint(respBody)
471+
}
472+
453473
if override {
454474
iversion := integrationVersion{}
455-
json.Unmarshal(respBody, &iversion)
475+
err = json.Unmarshal(respBody, &iversion)
476+
if err != nil {
477+
return nil, err
478+
}
479+
456480
or := overrides{}
457481
if or, err = extractOverrides(iversion); err != nil {
458482
return nil, err
459483
}
460484
if respBody, err = json.Marshal(or); err != nil {
461485
return nil, err
462486
}
487+
apiclient.SetPrintOutput(tmp)
463488
apiclient.PrettyPrint(respBody)
464489
}
465490
return respBody, err
466491
}
467492

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

487512
version := getVersion(listBasicVersions.BasicIntegrationVersions[0].Version)
488-
return Get(name, version, false, override)
513+
return Get(name, version, false, minimal, override)
489514
}
490515

491516
// GetByUserlabel
492-
func GetByUserlabel(name string, userLabel string, override bool) ([]byte, error) {
517+
func GetByUserlabel(name string, userLabel string, minimal bool, override bool) ([]byte, error) {
493518
apiclient.SetPrintOutput(false)
494519
listBody, err := ListVersions(name, -1, "", "userLabel="+userLabel, "", false, false, true)
495520
if err != nil {
@@ -507,7 +532,7 @@ func GetByUserlabel(name string, userLabel string, override bool) ([]byte, error
507532
}
508533

509534
version := getVersion(listBasicVersions.BasicIntegrationVersions[0].Version)
510-
return Get(name, version, false, override)
535+
return Get(name, version, false, minimal, override)
511536
}
512537

513538
// Delete - THIS IS UNIMPLEMENTED!!!

client/integrations/overrides.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ func getNewConnectionParams(connectionName string, connectionLocation string) (c
295295
integrationRegion = apiclient.GetRegion() //store the integration location
296296
apiclient.SetRegion(connectionLocation) //set the connector region
297297
}
298-
connResp, err := connections.Get(connectionName, "BASIC") //get connector details
298+
connResp, err := connections.Get(connectionName, "BASIC", false) //get connector details
299299
apiclient.SetPrintOutput(true)
300300
if connectionLocation != "" {
301301
apiclient.SetRegion(integrationRegion) //set the integration region back

cmd/connectors/get.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,21 @@ var GetCmd = &cobra.Command{
3838
return apiclient.SetProjectID(project)
3939
},
4040
RunE: func(cmd *cobra.Command, args []string) (err error) {
41-
_, err = connections.Get(name, view)
41+
_, err = connections.Get(name, view, minimal)
4242
return
4343
},
4444
}
4545

4646
var view string
47+
var minimal bool
4748

4849
func init() {
4950
GetCmd.Flags().StringVarP(&name, "name", "n",
5051
"", "The name of the connection")
5152
GetCmd.Flags().StringVarP(&view, "view", "",
5253
"BASIC", "fields of the Connection to be returned; default is BASIC. FULL is the other option")
54+
GetCmd.Flags().BoolVarP(&minimal, "minimal", "",
55+
false, "fields of the Connection to be returned; default is false")
5356

5457
_ = GetCmd.MarkFlagRequired("name")
5558
}

cmd/integrations/getversion.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,19 @@ var GetVerCmd = &cobra.Command{
4848
},
4949
RunE: func(cmd *cobra.Command, args []string) (err error) {
5050
if version != "" {
51-
_, err = integrations.Get(name, version, basic, overrides)
51+
_, err = integrations.Get(name, version, basic, minimal, overrides)
5252
} else if snapshot != "" {
53-
_, err = integrations.GetBySnapshot(name, snapshot, overrides)
53+
_, err = integrations.GetBySnapshot(name, snapshot, minimal, overrides)
5454
} else {
55-
_, err = integrations.GetByUserlabel(name, userLabel, overrides)
55+
_, err = integrations.GetByUserlabel(name, userLabel, minimal, overrides)
5656
}
5757
return
5858

5959
},
6060
}
6161

62+
var minimal bool
63+
6264
func init() {
6365
GetVerCmd.Flags().StringVarP(&name, "name", "n",
6466
"", "Integration flow name")
@@ -72,6 +74,8 @@ func init() {
7274
false, "Returns snapshot and version only")
7375
GetVerCmd.Flags().BoolVarP(&overrides, "overrides", "o",
7476
false, "Returns overrides only for integration")
77+
GetVerCmd.Flags().BoolVarP(&minimal, "minimal", "",
78+
false, "fields of the Integration to be returned; default is false")
7579

7680
_ = GetVerCmd.MarkFlagRequired("name")
7781
}

0 commit comments

Comments
 (0)