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

Commit

Permalink
add support for trace and cache
Browse files Browse the repository at this point in the history
  • Loading branch information
srinandan committed Oct 26, 2019
1 parent 03ffa69 commit 98e5690
Show file tree
Hide file tree
Showing 16 changed files with 502 additions and 5 deletions.
92 changes: 92 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ ___

* [apis](#apis)
* [apps](#apps)
* [cache](#cache)
* [developers](#devs)
* [envs](#env)
* [flowhooks](#flow)
Expand All @@ -100,6 +101,7 @@ ___
* [export](#expapis)
* [list](#listorgs)
* [listdeploy](#listdeploy)
* [trace](#trace)
* [undeploy](#undepapi)

### <a name="createapi"/> create
Expand Down Expand Up @@ -234,6 +236,62 @@ The following parameters are supported. See Common Reference for a list of addit
* `--expand -x` (optional) Returns an expanded list of proxies for the organization.
* `--count -c` (optional) Number of apis to return

### <a name="trace"/> trace

Manage debug sessions/trace for API Proxy revisions

* [create](#crttrcapi)
* [get](#gettrcapi)
* [list](#listtrcapi)

#### <a name="crttrcapi"> create

Create a new trace/debug session

```
apigeecli apis trace create -o org -e env -n name -v 1 -f "name1=value1,name2=value2"
```
Parameters
The following parameters are supported. See Common Reference for a list of additional parameters.

* `--org -o` (required) Apigee organization name
* `--env -e` (required) Apigee environment name
* `--name -n` (required) API proxy name
* `--rev -v` (required) API proxy revision
* `--filter -f` (optional) Trace filter; format is: name1=value1,name2=value2

#### <a name="getrcapi"> get

Get details for trace/debug session

```
apigeecli apis trace create -o org -e env -n name -v 1 -s uuid
```
Parameters
The following parameters are supported. See Common Reference for a list of additional parameters.

* `--org -o` (required) Apigee organization name
* `--env -e` (required) Apigee environment name
* `--name -n` (required) API proxy name
* `--rev -v` (required) API proxy revision
* `--ses -s` (required) Trace session ID
* `--msg -m` (optional) Message ID

#### <a name="listtrcapi"> list

List all trace/debug session for a proxy revision in the last 24 hours

```
apigeecli apis trace create -o org -e env -n name -v 1
```
Parameters
The following parameters are supported. See Common Reference for a list of additional parameters.

* `--org -o` (required) Apigee organization name
* `--env -e` (required) Apigee environment name
* `--name -n` (required) API proxy name
* `--rev -v` (required) API proxy revision

### <a name="undepapi"/> undeploy

Undeploys a revision of an existing API proxy to an environment in an organization.
Expand Down Expand Up @@ -378,6 +436,40 @@ The following parameters are supported. See Common Reference for a list of addit

---

## <name ="cache"/> cache

* [delete](#delcache)
* [list](#listlist)

### <a name="delcache"/> delete

Delete a cache resource from an environment

```
apigeecli cache delete -o org -e env -n name
```
Parameters
The following parameters are supported. See Common Reference for a list of additional parameters.

* `--org -o` (required) Apigee organization name
* `--env -e` (required) Apigee environment name
* `--name -n` (required) Cache name

### <a name="listcache"/> lsit

List cache resources in an environment

```
apigeecli cache list -o org -e env
```
Parameters
The following parameters are supported. See Common Reference for a list of additional parameters.

* `--org -o` (required) Apigee organization name
* `--env -e` (required) Apigee environment name

---

## <a name="devs"/> developers

Supported alias `developers`
Expand Down
2 changes: 2 additions & 0 deletions cmd/apis/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
impapis "github.com/srinandan/apigeecli/cmd/apis/impapis"
"github.com/srinandan/apigeecli/cmd/apis/listapis"
"github.com/srinandan/apigeecli/cmd/apis/listdeploy"
traceapi "github.com/srinandan/apigeecli/cmd/apis/traceapi"
"github.com/srinandan/apigeecli/cmd/apis/undepapi"
"github.com/srinandan/apigeecli/cmd/shared"
)
Expand Down Expand Up @@ -39,4 +40,5 @@ func init() {
Cmd.AddCommand(getapi.Cmd)
Cmd.AddCommand(impapis.Cmd)
Cmd.AddCommand(undepapi.Cmd)
Cmd.AddCommand(traceapi.Cmd)
}
2 changes: 1 addition & 1 deletion cmd/apis/fetchapi/fetchapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ func init() {
"", "API Proxy revision")

_ = Cmd.MarkFlagRequired("name")
_ = Cmd.MarkFlagRequired("revision")
_ = Cmd.MarkFlagRequired("rev")
}
60 changes: 60 additions & 0 deletions cmd/apis/traceapi/crttrcapi/crttrcapi.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package crttrcapi

import (
"bytes"
"fmt"
"net/url"
"path"

"github.com/spf13/cobra"
"github.com/srinandan/apigeecli/cmd/shared"
)

//Cmd to manage tracing of apis
var Cmd = &cobra.Command{
Use: "create",
Short: "Create a new debug session for an API proxy",
Long: "Create a new debug session for Apigee API proxy revision deployed in an environment",
RunE: func(cmd *cobra.Command, args []string) (err error) {
u, _ := url.Parse(shared.BaseURL)
u.Path = path.Join(u.Path, shared.RootArgs.Org, "environments", shared.RootArgs.Env, "apis", name, "revisions", revision, "debugsessions")
q := u.Query()
q.Set("timeout", "567")
u.RawQuery = q.Encode()

var payload = ""
if len(filter) != 0 {
payload = "{\"filter\":" + getFilterStr() + "}"
} else {
payload = "{}"
}
_, err = shared.HttpClient(true, u.String(), payload)
return

},
}

var name, revision string
var filter map[string]string

func init() {

Cmd.Flags().StringVarP(&name, "name", "n",
"", "API proxy name")
Cmd.Flags().StringVarP(&revision, "rev", "v",
"", "API Proxy revision")
Cmd.Flags().StringToStringVar(&filter, "filter",
nil, "Filter Conditions; format is name1=value1,name2=value2...")

_ = Cmd.MarkFlagRequired("name")
_ = Cmd.MarkFlagRequired("rev")

}

func getFilterStr() string {
b := new(bytes.Buffer)
for key, value := range filter {
fmt.Fprintf(b, "%s=\"%s\"\n", key, value)
}
return b.String()
}
50 changes: 50 additions & 0 deletions cmd/apis/traceapi/gettrcapi/gettrcapi.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package gettrcapi

import (
"net/url"
"path"

"github.com/spf13/cobra"
"github.com/srinandan/apigeecli/cmd/shared"
)

//Cmd to manage tracing of apis
var Cmd = &cobra.Command{
Use: "get",
Short: "Get a debug session for an API proxy revision",
Long: "Get a debug session for an API proxy revision deployed in an environment",
RunE: func(cmd *cobra.Command, args []string) (err error) {
u, _ := url.Parse(shared.BaseURL)
if messageID == "" {
u.Path = path.Join(u.Path, shared.RootArgs.Org, "environments", shared.RootArgs.Env, "apis", name, "revisions", revision, "debugsessions", sessionID, "data")
q := u.Query()
q.Set("limit", "20")
u.RawQuery = q.Encode()
} else {
u.Path = path.Join(u.Path, shared.RootArgs.Org, "environments", shared.RootArgs.Env, "apis", name, "revisions", revision, "debugsessions", sessionID, "data", messageID)
}

_, err = shared.HttpClient(true, u.String())
return

},
}

var name, revision, sessionID, messageID string

func init() {

Cmd.Flags().StringVarP(&name, "name", "n",
"", "API proxy name")
Cmd.Flags().StringVarP(&revision, "rev", "v",
"", "API Proxy revision")
Cmd.Flags().StringVarP(&sessionID, "ses", "s",
"", "Debug session Id")
Cmd.Flags().StringVarP(&messageID, "msg", "m",
"", "Debug session Id")

_ = Cmd.MarkFlagRequired("name")
_ = Cmd.MarkFlagRequired("rev")
_ = Cmd.MarkFlagRequired("ses")

}
37 changes: 37 additions & 0 deletions cmd/apis/traceapi/listtrcapi/listtrcapi.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package listtrcapi

import (
"net/url"
"path"

"github.com/spf13/cobra"
"github.com/srinandan/apigeecli/cmd/shared"
)

//Cmd to manage tracing of apis
var Cmd = &cobra.Command{
Use: "list",
Short: "List all debug sessions for an API proxy revision",
Long: "List all debug sessions for an API proxy revision deployed in an environment",
RunE: func(cmd *cobra.Command, args []string) (err error) {
u, _ := url.Parse(shared.BaseURL)
u.Path = path.Join(u.Path, shared.RootArgs.Org, "environments", shared.RootArgs.Env, "apis", name, "revisions", revision, "debugsessions")
_, err = shared.HttpClient(true, u.String())
return

},
}

var name, revision string

func init() {

Cmd.Flags().StringVarP(&name, "name", "n",
"", "API proxy name")
Cmd.Flags().StringVarP(&revision, "rev", "v",
"", "API Proxy revision")

_ = Cmd.MarkFlagRequired("name")
_ = Cmd.MarkFlagRequired("rev")

}
28 changes: 28 additions & 0 deletions cmd/apis/traceapi/traceapi.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package apis

import (
"github.com/spf13/cobra"
"github.com/srinandan/apigeecli/cmd/apis/traceapi/crttrcapi"
"github.com/srinandan/apigeecli/cmd/apis/traceapi/gettrcapi"
"github.com/srinandan/apigeecli/cmd/apis/traceapi/listtrcapi"
"github.com/srinandan/apigeecli/cmd/shared"
)

//Cmd to manage tracing of apis
var Cmd = &cobra.Command{
Use: "trace",
Short: "Manage debugging/tracing of Apigee API proxies",
Long: "Manage debugging/tracing of Apigee API proxy revisions deployed in an environment",
}

func init() {

Cmd.PersistentFlags().StringVarP(&shared.RootArgs.Env, "env", "e",
"", "Apigee environment name")

_ = Cmd.MarkPersistentFlagRequired("env")

Cmd.AddCommand(crttrcapi.Cmd)
Cmd.AddCommand(listtrcapi.Cmd)
Cmd.AddCommand(gettrcapi.Cmd)
}
30 changes: 30 additions & 0 deletions cmd/cache/cache.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package cache

import (
"github.com/spf13/cobra"
"github.com/srinandan/apigeecli/cmd/cache/delcache"
"github.com/srinandan/apigeecli/cmd/cache/listcache"
"github.com/srinandan/apigeecli/cmd/shared"
)

//Cmd to manage tracing of apis
var Cmd = &cobra.Command{
Use: "cache",
Short: "Manage caches within an Apigee environment",
Long: "Manage caches within an Apigee environment",
}

func init() {

Cmd.PersistentFlags().StringVarP(&shared.RootArgs.Org, "org", "o",
"", "Apigee organization name")

Cmd.PersistentFlags().StringVarP(&shared.RootArgs.Env, "env", "e",
"", "Apigee environment name")

_ = Cmd.MarkPersistentFlagRequired("org")
_ = Cmd.MarkPersistentFlagRequired("env")

Cmd.AddCommand(listcache.Cmd)
Cmd.AddCommand(delcache.Cmd)
}
34 changes: 34 additions & 0 deletions cmd/cache/delcache/delcache.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package delcache

import (
"net/url"
"path"

"github.com/spf13/cobra"
"github.com/srinandan/apigeecli/cmd/shared"
)

//Cmd to delete cache
var Cmd = &cobra.Command{
Use: "delete",
Short: "Delete a cache resource from the environment",
Long: "Delete a cache resource from the environment",
RunE: func(cmd *cobra.Command, args []string) (err error) {
u, _ := url.Parse(shared.BaseURL)
u.Path = path.Join(u.Path, shared.RootArgs.Org, "environments", shared.RootArgs.Env, "caches", name)
_, err = shared.HttpClient(true, u.String())
return

},
}

var name string

func init() {

Cmd.Flags().StringVarP(&name, "name", "n",
"", "API proxy name")

_ = Cmd.MarkFlagRequired("name")

}
Loading

0 comments on commit 98e5690

Please sign in to comment.