这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions client/apis/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,28 @@ func GetProxy(name string, revision int) (respBody []byte, err error) {
return respBody, err
}

//GetHighestProxyRevision
func GetHighestProxyRevision(name string) (version int, err error) {
apiclient.SetPrintOutput(false)
u, _ := url.Parse(apiclient.BaseURL)
u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "apis", name)
respBody, err := apiclient.HttpClient(apiclient.GetPrintOutput(), u.String())
apiclient.SetPrintOutput(true)
if err != nil {
return -1, err
}

proxyRevisions := proxy{}
if err = json.Unmarshal(respBody, &proxyRevisions); err != nil {
return -1, err
}
version, err = strconv.Atoi(maxRevision(proxyRevisions.Revision))
if err != nil {
return -1, nil
}
return version, nil
}

//GenerateDeployChangeReport
func GenerateDeployChangeReport(name string, revision int, overrides bool) (respBody []byte, err error) {
u, _ := url.Parse(apiclient.BaseURL)
Expand Down
22 changes: 22 additions & 0 deletions client/sharedflows/sharedflows.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,28 @@ func Get(name string, revision int) (respBody []byte, err error) {
return respBody, err
}

//GetHighestSfRevision
func GetHighestSfRevision(name string) (version int, err error) {
apiclient.SetPrintOutput(false)
u, _ := url.Parse(apiclient.BaseURL)
u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "sharedflows", name)
respBody, err := apiclient.HttpClient(apiclient.GetPrintOutput(), u.String())
apiclient.SetPrintOutput(true)
if err != nil {
return -1, err
}

sfRevisions := sharedflow{}
if err = json.Unmarshal(respBody, &sfRevisions); err != nil {
return -1, err
}
version, err = strconv.Atoi(maxRevision(sfRevisions.Revision))
if err != nil {
return -1, nil
}
return version, nil
}

//Delete
func Delete(name string, revision int) (respBody []byte, err error) {
u, _ := url.Parse(apiclient.BaseURL)
Expand Down
7 changes: 6 additions & 1 deletion cmd/apis/depapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ var DepCmd = &cobra.Command{
return apiclient.SetApigeeOrg(org)
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
if revision == -1 {
if revision, err = apis.GetHighestProxyRevision(name); err != nil {
return
}
}
_, err = apis.DeployProxy(name, revision, overrides, serviceAccountName)
return
},
Expand All @@ -45,7 +50,7 @@ func init() {
DepCmd.Flags().StringVarP(&env, "env", "e",
"", "Apigee environment name")
DepCmd.Flags().IntVarP(&revision, "rev", "v",
-1, "API Proxy revision")
-1, "API Proxy revision. If not set, the highest revision is used")
DepCmd.Flags().BoolVarP(&overrides, "ovr", "r",
false, "Forces deployment of the new revision")
DepCmd.Flags().StringVarP(&serviceAccountName, "sa", "s",
Expand Down
7 changes: 6 additions & 1 deletion cmd/apis/depwaitapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ var DepWaitCmd = &cobra.Command{
return nil
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
if revision == -1 {
if revision, err = apis.GetHighestProxyRevision(name); err != nil {
return
}
}

if _, err = apis.DeployProxy(name, revision, overrides, serviceAccountName); err != nil {
return err
Expand Down Expand Up @@ -82,7 +87,7 @@ func init() {
DepWaitCmd.Flags().StringVarP(&env, "env", "e",
"", "Apigee environment name")
DepWaitCmd.Flags().IntVarP(&revision, "rev", "v",
-1, "API Proxy revision")
-1, "API Proxy revision. If not set, the highest revision is used.")
DepWaitCmd.Flags().BoolVarP(&overrides, "ovr", "r",
false, "Forces deployment of the new revision")
DepWaitCmd.Flags().StringVarP(&serviceAccountName, "sa", "s",
Expand Down
10 changes: 7 additions & 3 deletions cmd/apis/fetchapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ var FetCmd = &cobra.Command{
Args: func(cmd *cobra.Command, args []string) (err error) {
return apiclient.SetApigeeOrg(org)
},
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, args []string) (err error) {
if revision == -1 {
if revision, err = apis.GetHighestProxyRevision(name); err != nil {
return
}
}
return apis.FetchProxy(name, revision)
},
}
Expand All @@ -38,8 +43,7 @@ func init() {
FetCmd.Flags().StringVarP(&name, "name", "n",
"", "API Proxy Bundle Name")
FetCmd.Flags().IntVarP(&revision, "rev", "v",
-1, "API Proxy revision")
-1, "API Proxy revision. If not set, the highest revision is used")

_ = FetCmd.MarkFlagRequired("name")
_ = FetCmd.MarkFlagRequired("rev")
}
5 changes: 5 additions & 0 deletions cmd/apis/undepapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ var UndepCmd = &cobra.Command{
return apiclient.SetApigeeOrg(org)
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
if revision == -1 {
if revision, err = apis.GetHighestProxyRevision(name); err != nil {
return
}
}
_, err = apis.UndeployProxy(name, revision)
return
},
Expand Down
7 changes: 6 additions & 1 deletion cmd/sharedflows/depsf.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ var DepCmd = &cobra.Command{
return apiclient.SetApigeeOrg(org)
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
if revision == -1 {
if revision, err = sharedflows.GetHighestSfRevision(name); err != nil {
return
}
}
_, err = sharedflows.Deploy(name, revision, overrides, serviceAccountName)
return
},
Expand All @@ -45,7 +50,7 @@ func init() {
DepCmd.Flags().StringVarP(&env, "env", "e",
"", "Apigee environment name")
DepCmd.Flags().IntVarP(&revision, "rev", "v",
-1, "Sharedflow revision")
-1, "Sharedflow revision. If not set, the highest revision is used")
DepCmd.Flags().BoolVarP(&overrides, "ovr", "r",
false, "Forces deployment of the new revision")
DepCmd.Flags().StringVarP(&serviceAccountName, "sa", "s",
Expand Down
10 changes: 7 additions & 3 deletions cmd/sharedflows/fetchsf.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ var FetCmd = &cobra.Command{
apiclient.SetApigeeEnv(env)
return apiclient.SetApigeeOrg(org)
},
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, args []string) (err error) {
if revision == -1 {
if revision, err = sharedflows.GetHighestSfRevision(name); err != nil {
return
}
}
return sharedflows.Fetch(name, revision)
},
}
Expand All @@ -39,8 +44,7 @@ func init() {
FetCmd.Flags().StringVarP(&name, "name", "n",
"", "Shared flow Bundle Name")
FetCmd.Flags().IntVarP(&revision, "rev", "v",
-1, "Shared flow revision")
-1, "Shared flow revision. If not set, the highest revision is used")

_ = FetCmd.MarkFlagRequired("name")
_ = FetCmd.MarkFlagRequired("rev")
}