Skip to content

Commit 1e78616

Browse files
committed
chore: generate examples for apigeecli
1 parent 11325d1 commit 1e78616

7 files changed

Lines changed: 86 additions & 37 deletions

File tree

README.md

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ The following environment variables may be set to control the behavior of `apige
192192
* `APIGEECLI_DRYRUN=true` does not execute Apigee control plane APIs
193193

194194
## Version 2.x.x Breaking Changes
195+
195196
The following command line flags have changed to follow a more consistent naming convention. The previous flag name and shorthand character are left of `==>` and the new flag name and shorthand are to the right.
196197
For example: `"flagName", "f" ==> "flag-name", "f"`
197198

@@ -232,7 +233,9 @@ Some changes merely drop the shorthand character.
232233
```
233234

234235
## Version 2.0.0 New Changes
236+
235237
A new flag was introduced to control output from apigeecli, that may impact your output if used in an automation pipeline.
238+
236239
```
237240
--no-warnings Disable printing warnings to stderr
238241
```
@@ -434,26 +437,9 @@ x-google-jwt-locations:
434437
435438
query parameters are ignored. By default, if no location is specified, the JWT location is the `Authorization` header and value_prefix is `Bearer <token>`
436439
437-
## How do I import entities using apigeecli?
438-
439-
The table below illustrates how you can import different entities into Apigee. It refers to the [samples](./samples/) directory.
440-
441-
442-
| Operations | Import command |
443-
|---|---|
444-
| apicategories | `apigeecli apicategories import -o $org -t $token -f samples/apicategories.json -s $siteId` |
445-
| apis | `apigeecli apis import -f samples/apis -o $org -t $token` |
446-
| appgroups | `apigeecli appgroups import -f samples/appgroups.json -o $org -t $token` |
447-
| datacollectors | `apigeecli datacollectors import -f samples/datacollectors.json -o $org -t $token` |
448-
| developers | `apigeecli developers import -f samples/developers.json -o $org -t $token` |
449-
| kvms | `apigeecli kvms import -f samples/kvms -o $org -t $token` (Rename the files under samples/kvms to match your Apigee setup) |
450-
| products | `apigeecli products import -f samples/apiproduct-legacy.json -o $org -t $token` `apigeecli products import -f samples/apiproduct-gqlgroup.json -o $org -t $token` `apigeecli products import -f samples/apiproduct-op-group.json -o $org -t $token` |
451-
| sharedflows | `apigeecli sharedflows import -f samples/sharedflows -o $org -t $token` |
452-
| targetservers | `apigeecli targetservers import -f samples/targetservers.json -o $org -t $token -e $env` |
453-
| keystores | `apigeecli keystores import -f samples/keystores.json -o $org -t $token -e $env` |
454-
| references | `apigeecli references import -f samples/references.json -o $org -t $token -e $env` |
455-
| apps | `apigeecli apps import -f samples/references.json -d samples/developers.json -o $org -t $token` (better used when the developers and apps are exported using the export) |
456-
| apidocs | `apigeecli apidocs import -f samples/apidocs -o $org -t $token -s $siteId` (Rename the files under samples/apidocs to match your Apigee setup for siteId) |
440+
## Samples
441+
442+
Please see [here](./samples/README.md)
457443
458444
## How do I verify the binary?
459445

docs/docs.go

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,42 @@
1515
package main
1616

1717
import (
18+
"io"
1819
"log"
1920
"os"
2021
"path/filepath"
2122

22-
cmd "internal/cmd"
23+
apiclient "internal/apiclient"
24+
"internal/cmd"
25+
apicategories "internal/cmd/apicategories"
26+
products "internal/cmd/products"
2327

2428
"github.com/spf13/cobra/doc"
2529
)
2630

31+
var samples = `# apigeecli Samples
32+
Set up apigeecli with preferences: apigeecli prefs set -o $org -t $(gcloud auth print-access-token)
33+
34+
| Operations | Command |
35+
|---|---|
36+
| apicategories | ` + apicategories.GetExample(0) + `|
37+
| apis | apigeecli apis import -f samples/apis -o $org -t $token |
38+
| appgroups | apigeecli appgroups import -f samples/appgroups.json -o $org -t $token |
39+
| datacollectors | apigeecli datacollectors import -f samples/datacollectors.json -o $org -t $token |
40+
| developers | apigeecli developers import -f samples/developers.json -o $org -t $token |
41+
| kvms | apigeecli kvms import -f samples/kvms -o $org -t $token (Rename the files under samples/kvms to match your Apigee setup) |
42+
| products | ` + products.GetExample(2) + ` |
43+
| products | ` + products.GetExample(3) + ` |
44+
| products | ` + products.GetExample(4) + ` |
45+
| products | ` + products.GetExample(0) + ` |
46+
| products | ` + products.GetExample(1) + ` |
47+
| sharedflows | apigeecli sharedflows import -f samples/sharedflows -o $org -t $token |
48+
| targetservers | apigeecli targetservers import -f samples/targetservers.json -o $org -t $token -e $env |
49+
| keystores | apigeecli keystores import -f samples/keystores.json -o $org -t $token -e $env |
50+
| references | apigeecli references import -f samples/references.json -o $org -t $token -e $env |
51+
| apps | apigeecli apps import -f samples/references.json -d samples/developers.json -o $org -t $token (better used when the developers and apps are exported using the export) |
52+
| apidocs | apigeecli apidocs import -f samples/apidocs -o $org -t $token -s $siteId (Rename the files under samples/apidocs to match your Apigee setup for siteId) |`
53+
2754
func main() {
2855
var err error
2956
var docFiles []string
@@ -41,4 +68,21 @@ func main() {
4168
if err = doc.GenMarkdownTree(cmd.RootCmd, "./docs"); err != nil {
4269
log.Fatal(err)
4370
}
71+
72+
_ = apiclient.WriteByteArrayToFile("./samples/README.md", false, []byte(samples))
73+
}
74+
75+
func WriteFile() (byteValue []byte, err error) {
76+
userFile, err := os.Open("./samples/README.md")
77+
if err != nil {
78+
return nil, err
79+
}
80+
81+
defer userFile.Close()
82+
83+
byteValue, err = io.ReadAll(userFile)
84+
if err != nil {
85+
return nil, err
86+
}
87+
return byteValue, err
4488
}

internal/cmd/apicategories/apicategories.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ var Cmd = &cobra.Command{
2727

2828
var org, siteid, id, region string
2929

30+
var examples = []string{"apigeecli apicategories import --file samples/apicategories.json --siteid $siteId"}
31+
3032
func init() {
3133
Cmd.PersistentFlags().StringVarP(&org, "org", "o",
3234
"", "Apigee organization name")
@@ -47,3 +49,7 @@ func init() {
4749
_ = Cmd.MarkFlagRequired("org")
4850
_ = Cmd.MarkFlagRequired("siteid")
4951
}
52+
53+
func GetExample(i int) string {
54+
return examples[i]
55+
}

internal/cmd/apicategories/import.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ var ImpCmd = &cobra.Command{
3333
apiclient.SetRegion(region)
3434
return apiclient.SetApigeeOrg(org)
3535
},
36+
Example: `Import an existing apicategories from a file:
37+
` + GetExample(0),
3638
RunE: func(cmd *cobra.Command, args []string) error {
3739
if siteid == "" {
3840
return fmt.Errorf("siteid is a mandatory parameter")

internal/cmd/products/crtprod.go

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -71,24 +71,10 @@ var CreateCmd = &cobra.Command{
7171
return err
7272
},
7373
Example: `Create an API product, using externally defined operations, with auto approval and access=public:
74-
apigeecli products create --name "$product_name" \
75-
--display-name "$product_name" \
76-
--opgrp "$ops_file" \
77-
--envs "$env" \
78-
--approval auto \
79-
--attrs access=public \
80-
--token $TOKEN
74+
` + GetExample(0) + `
8175
8276
Create an API product, using externally defined operations, with auto approval and access=public, and a quota of 100/minute:
83-
apigeecli products create --name "$product_name" \
84-
--display-name "$product_name" \
85-
--opgrp "$ops_file" \
86-
--envs "$env" \
87-
--approval auto \
88-
--attrs access=public \
89-
--quota 100 --interval 1 --unit minute \
90-
--token $TOKEN
91-
`,
77+
` + GetExample(1),
9278
}
9379

9480
var operationGroupFile, gqlOperationGroupFile, grpcOperationGroupFile, quotaCounterScope string

internal/cmd/products/impprod.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ var ImpCmd = &cobra.Command{
2727
Use: "import",
2828
Short: "Import a file containing API products",
2929
Long: "Import a file containing API products",
30+
Example: `Import API Products from a file containing REST Operations
31+
` + GetExample(2) + `
32+
33+
Import API Products from a file containing GraphQL Operations
34+
` + GetExample(3),
3035
Args: func(cmd *cobra.Command, args []string) (err error) {
3136
apiclient.SetRegion(region)
3237
return apiclient.SetApigeeOrg(org)

internal/cmd/products/products.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,22 @@ var (
4444
attrs map[string]string
4545
)
4646

47+
var examples = []string{`apigeecli products create --name $product_name \\
48+
--display-name $product_name \
49+
--opgrp $ops_file \
50+
--envs $env \
51+
--approval auto \
52+
--attrs access=public`, `apigeecli products create --name $product_name \
53+
--display-name $product_name \
54+
--opgrp $ops_file \
55+
--envs $env \
56+
--approval auto \
57+
--attrs access=public \
58+
--quota 100 --interval 1 --unit minute`,
59+
`apigeecli products import -f samples/apiproduct-legacy.json`,
60+
`apigeecli products import -f samples/apiproduct-gqlgroup.json`,
61+
`apigeecli products import -f samples/apiproduct-op-group.json`}
62+
4763
func init() {
4864
Cmd.PersistentFlags().StringVarP(&org, "org", "o",
4965
"", "Apigee organization name")
@@ -136,3 +152,7 @@ func getAttributes(attrs map[string]string) []products.Attribute {
136152

137153
return nil
138154
}
155+
156+
func GetExample(i int) string {
157+
return examples[i]
158+
}

0 commit comments

Comments
 (0)