Skip to content
This repository has been archived by the owner on May 6, 2022. It is now read-only.

Commit

Permalink
support to import trace config
Browse files Browse the repository at this point in the history
  • Loading branch information
srinandan committed Nov 28, 2021
1 parent 62fb6a1 commit 055c96a
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
7 changes: 7 additions & 0 deletions client/env/traceconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ func UpdateTraceConfig(exporter string, endpoint string, sampler string, sample_
return respBody, err
}

func ImportTraceConfig(payload string) (respBody []byte, err error) {
u, _ := url.Parse(apiclient.BaseURL)
u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "traceConfig")
respBody, err = apiclient.HttpClient(apiclient.GetPrintOutput(), u.String(), payload, "PATCH")
return respBody, err
}

func DisableTraceConfig() (respBody []byte, err error) {

var traceRespBody []byte
Expand Down
41 changes: 41 additions & 0 deletions cmd/org/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,33 @@ var ImportCmd = &cobra.Command{
}
}
}

if importDebugmask {
if isFileExists(path.Join(folder, environment+debugmaskFileName)) {
fmt.Println("\tImporting Debug Mask configuration...")
debugMask, _ := readEntityFileAsString(path.Join(folder, environment+debugmaskFileName))
if _, err = env.SetDebug(debugMask); err != nil {
return err
}
}
}

if importTrace {
if isFileExists(path.Join(folder, environment+tracecfgFileName)) {
fmt.Println("\tImporting Trace configuration...")
traceCfg, _ := readEntityFileAsString(path.Join(folder, environment+tracecfgFileName))
if _, err = env.ImportTraceConfig(traceCfg); err != nil {
return err
}
}
}
}

return err
},
}

var importTrace, importDebugmask bool
var folder string

func init() {
Expand All @@ -150,6 +171,10 @@ func init() {
4, "Number of connections")
ImportCmd.Flags().StringVarP(&folder, "folder", "f",
"", "folder containing API proxy bundles")
ImportCmd.Flags().BoolVarP(&importTrace, "importTrace", "",
false, "Import distributed trace configuration; default false")
ImportCmd.Flags().BoolVarP(&importDebugmask, "importDebugmask", "",
false, "Import debugmask configuration; default false")

_ = ImportCmd.MarkFlagRequired("folder")
}
Expand Down Expand Up @@ -183,3 +208,19 @@ func readEntityFile(filePath string) ([]string, error) {

return entities, nil
}

func readEntityFileAsString(filePath string) (string, error) {
jsonFile, err := os.Open(filePath)
if err != nil {
return "", err
}

defer jsonFile.Close()

byteValue, err := ioutil.ReadAll(jsonFile)
if err != nil {
return "", err
}

return string(byteValue[:]), nil
}
2 changes: 2 additions & 0 deletions cmd/org/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const (
kVMFileName = "kvms.json"
keyStoresFileName = "keystores.json"
syncAuthFileName = "syncauth.json"
debugmaskFileName = "_debugmask.json"
tracecfgFileName = "_tracecfg.json"

proxiesFolderName = "proxies"
sharedFlowsFolderName = "sharedflows"
Expand Down

0 comments on commit 055c96a

Please sign in to comment.