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

Commit

Permalink
import sharedflow
Browse files Browse the repository at this point in the history
  • Loading branch information
srinandan committed Jul 21, 2019
1 parent c288de4 commit 8d2fafc
Show file tree
Hide file tree
Showing 18 changed files with 161 additions and 445 deletions.
458 changes: 71 additions & 387 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cmd/apis/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func init() {
"", "Apigee organization name")

_ = Cmd.MarkPersistentFlagRequired("org")

Cmd.AddCommand(listapis.Cmd)
Cmd.AddCommand(listdeploy.Cmd)
Cmd.AddCommand(crtapi.Cmd)
Expand Down
36 changes: 1 addition & 35 deletions cmd/apis/crtapi/crtapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@ package crtapis

import (
"../../shared"
"archive/zip"
"errors"
"github.com/spf13/cobra"
"net/url"
"os"
"path"
"strings"
)

var Cmd = &cobra.Command{
Expand All @@ -24,7 +20,7 @@ var Cmd = &cobra.Command{
q.Set("name", name)
q.Set("action", "import")
u.RawQuery = q.Encode()
err := readProxyBundle()
err := shared.ReadBundle(name)
if err == nil {
_ = shared.PostHttpOctet(u.String(), proxy)
}
Expand All @@ -46,33 +42,3 @@ func init() {

_ = Cmd.MarkFlagRequired("name")
}

func readProxyBundle() error {

if !strings.HasSuffix(proxy, ".zip") {
shared.Error.Fatalln("Proxy bundle must be a zip file")
return errors.New("source must be a zipfile")
}

file, err := os.Open(proxy)

if err != nil {
shared.Error.Fatalln("Cannot open/read API Proxy Bundle: ", err)
return err
}

fi, err := file.Stat()
if err != nil {
shared.Error.Fatalln("Error accessing file: ", err)
return err
}
_, err = zip.NewReader(file, fi.Size())

if err != nil {
shared.Error.Fatalln("Invalid API Proxy Bundle: ", err)
return err
}

defer file.Close()
return nil
}
2 changes: 1 addition & 1 deletion cmd/developers/developers.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func init() {
"", "Apigee organization name")

_ = Cmd.MarkPersistentFlagRequired("org")

Cmd.AddCommand(listdev.Cmd)
Cmd.AddCommand(getdev.Cmd)
Cmd.AddCommand(deldev.Cmd)
Expand Down
2 changes: 1 addition & 1 deletion cmd/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func init() {
"", "Apigee organization name")

_ = Cmd.MarkPersistentFlagRequired("org")

Cmd.AddCommand(listenv.Cmd)
Cmd.AddCommand(getenv.Cmd)
}
3 changes: 1 addition & 2 deletions cmd/flowhooks/crtfh/crtfh.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var Cmd = &cobra.Command{

flowhook = append(flowhook, "\"sharedFlow\":\""+sharedflow+"\"")

if continueOnErr {
if continueOnErr {
flowhook = append(flowhook, "\"continueOnError\":"+strconv.FormatBool(continueOnErr))
}

Expand All @@ -53,4 +53,3 @@ func init() {
_ = Cmd.MarkFlagRequired("name")
_ = Cmd.MarkFlagRequired("sharedflow")
}

1 change: 0 additions & 1 deletion cmd/flowhooks/delfh/delfh.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,3 @@ func init() {

_ = Cmd.MarkFlagRequired("name")
}

1 change: 0 additions & 1 deletion cmd/flowhooks/getfh/getfh.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,3 @@ func init() {

_ = Cmd.MarkFlagRequired("name")
}

2 changes: 0 additions & 2 deletions cmd/flowhooks/listfh/listfh.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,4 @@ var Cmd = &cobra.Command{

func init() {


}

7 changes: 3 additions & 4 deletions cmd/org/setmart/setmart.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ var Cmd = &cobra.Command{
Long: "Set MART endpoint for an Apigee Org",
Run: func(cmd *cobra.Command, args []string) {
u, _ := url.Parse(shared.BaseURL)
orgname := "\"name\":\""+shared.RootArgs.Org+"\","
orgname := "\"name\":\"" + shared.RootArgs.Org + "\","
martprop := "{\"name\":\"features.mart.server.endpoint\","
martpropvalue := "\"value\":\""+mart+"\"}"
martpropvalue := "\"value\":\"" + mart + "\"}"
props := "\"properties\": {" + "\"property\": [" + martprop + martpropvalue + "]}"
payload := "{" + orgname + props +"}"
payload := "{" + orgname + props + "}"
u.Path = path.Join(u.Path, shared.RootArgs.Org)
_ = shared.HttpClient(u.String(), payload)
},
Expand All @@ -32,6 +32,5 @@ func init() {
Cmd.Flags().StringVarP(&mart, "mart", "m",
"", "MART Endpoint")


_ = Cmd.MarkFlagRequired("org")
}
37 changes: 34 additions & 3 deletions cmd/shared/shared.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package shared

import (
"archive/zip"
"bytes"
"crypto/x509"
"encoding/json"
Expand Down Expand Up @@ -112,7 +113,7 @@ func PostHttpOctet(url string, proxyName string) error {
if err != nil {
Error.Fatalln("Error in client:\n", err)
return err
}
}

Info.Println("Setting token : ", RootArgs.Token)
req.Header.Add("Authorization", "Bearer "+RootArgs.Token)
Expand Down Expand Up @@ -161,7 +162,7 @@ func DownloadResource(url string, name string) error {
Error.Fatalln("Error in client:\n", err)
return err
}

Info.Println("Setting token : ", RootArgs.Token)
req.Header.Add("Authorization", "Bearer "+RootArgs.Token)

Expand Down Expand Up @@ -213,7 +214,7 @@ func HttpClient(params ...string) error {
} else {
return errors.New("Incorrect parameters to invoke the method")
}

if err != nil {
Error.Fatalln("Error in client:\n", err)
return err
Expand Down Expand Up @@ -461,3 +462,33 @@ func SetAccessToken() error {
}
}
}

func ReadBundle(filename string) error {

if !strings.HasSuffix(filename, ".zip") {
Error.Fatalln("Proxy bundle must be a zip file")
return errors.New("source must be a zipfile")
}

file, err := os.Open(filename)

if err != nil {
Error.Fatalln("Cannot open/read API Proxy Bundle: ", err)
return err
}

fi, err := file.Stat()
if err != nil {
Error.Fatalln("Error accessing file: ", err)
return err
}
_, err = zip.NewReader(file, fi.Size())

if err != nil {
Error.Fatalln("Invalid API Proxy Bundle: ", err)
return err
}

defer file.Close()
return nil
}
44 changes: 44 additions & 0 deletions cmd/sharedflows/crtsf/crtsf.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package crtsf

import (
"../../shared"
"github.com/spf13/cobra"
"net/url"
"path"
)

var Cmd = &cobra.Command{
Use: "create",
Short: "Creates a sharedflow in an Apigee Org",
Long: "Creates a sharedflow in an Apigee Org",
Run: func(cmd *cobra.Command, args []string) {
u, _ := url.Parse(shared.BaseURL)
u.Path = path.Join(u.Path, shared.RootArgs.Org, "sharedflows")

if proxy != "" {
q := u.Query()
q.Set("name", name)
q.Set("action", "import")
u.RawQuery = q.Encode()
err := shared.ReadBundle(name)
if err == nil {
_ = shared.PostHttpOctet(u.String(), proxy)
}
} else {
proxyName := "{\"name\":\"" + name + "\"}"
_ = shared.HttpClient(u.String(), proxyName)
}
},
}

var name, proxy string

func init() {

Cmd.Flags().StringVarP(&name, "name", "n",
"", "Sharedflow name")
Cmd.Flags().StringVarP(&proxy, "proxy", "p",
"", "Sharedflow bundle path")

_ = Cmd.MarkFlagRequired("name")
}
2 changes: 2 additions & 0 deletions cmd/sharedflows/sharedflows.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sharedflows

import (
"../shared"
"./crtsf"
"./delsf"
"./depsf"
"./fetchsf"
Expand Down Expand Up @@ -29,4 +30,5 @@ func init() {
Cmd.AddCommand(delsf.Cmd)
Cmd.AddCommand(undepsf.Cmd)
Cmd.AddCommand(depsf.Cmd)
Cmd.AddCommand(crtsf.Cmd)
}
2 changes: 1 addition & 1 deletion cmd/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ func init() {
"", "Apigee organization name")

_ = Cmd.MarkPersistentFlagRequired("org")
Cmd.AddCommand(setsync.Cmd)
Cmd.AddCommand(setsync.Cmd)
Cmd.AddCommand(getsync.Cmd)
}
3 changes: 1 addition & 2 deletions cmd/targetservers/crtts/crtts.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var Cmd = &cobra.Command{
targetserver = append(targetserver, "\"host\":\""+host+"\"")
targetserver = append(targetserver, "\"port\":"+strconv.Itoa(port))

if enable {
if enable {
targetserver = append(targetserver, "\"isEnabled\":"+strconv.FormatBool(enable))
}

Expand Down Expand Up @@ -57,4 +57,3 @@ func init() {
_ = Cmd.MarkFlagRequired("name")
_ = Cmd.MarkFlagRequired("host")
}

1 change: 0 additions & 1 deletion cmd/targetservers/delts/delts.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,3 @@ func init() {

_ = Cmd.MarkFlagRequired("name")
}

1 change: 0 additions & 1 deletion cmd/targetservers/getts/getts.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,3 @@ func init() {

_ = Cmd.MarkFlagRequired("name")
}

2 changes: 0 additions & 2 deletions cmd/targetservers/listts/listts.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,4 @@ var Cmd = &cobra.Command{

func init() {


}

0 comments on commit 8d2fafc

Please sign in to comment.