这是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
33 changes: 33 additions & 0 deletions cmd/org/deployments.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package org

import (
"github.com/spf13/cobra"
)

// DeployCmd to get api deployments in an org
var DeployCmd = &cobra.Command{
Use: "deployments",
Short: "Manage deployments in an Apigee org",
Long: "Manage deployments in an Apigee org",
}

func init() {
DeployCmd.PersistentFlags().StringVarP(&org, "org", "o",
"", "Apigee organization name")

DeployCmd.AddCommand(GetDeployCmd)
}
50 changes: 50 additions & 0 deletions cmd/org/getdeployments.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package org

import (
"internal/apiclient"

orgs "internal/client/orgs"

"github.com/spf13/cobra"
)

// GetDeployCmd to get deployed apis in an env
var GetDeployCmd = &cobra.Command{
Use: "get",
Short: "Get deployments for an Apigee org",
Long: "Get deployments for an Apigee org",
Args: func(cmd *cobra.Command, args []string) (err error) {
return apiclient.SetApigeeOrg(org)
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
if all {
_, err = orgs.GetAllDeployments()
} else {
_, err = orgs.GetDeployments(sf)
}
return err
},
}

var sf, all bool

func init() {
GetDeployCmd.Flags().BoolVarP(&sf, "sharedflows", "s",
false, "Return sharedflow deployments")
GetDeployCmd.Flags().BoolVarP(&all, "all", "",
false, "Return all deployments")
}
1 change: 1 addition & 0 deletions cmd/org/org.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ func init() {
Cmd.AddCommand(SetAddonCmd)
Cmd.AddCommand(ReportCmd)
Cmd.AddCommand(DelCmd)
Cmd.AddCommand(DeployCmd)
}
37 changes: 37 additions & 0 deletions internal/client/orgs/orgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,43 @@ func GetDeployedIngressConfig(view bool) (respBody []byte, err error) {
return respBody, err
}

// GetlDeployments
func GetDeployments(sharedflows bool) (respBody []byte, err error) {
u, _ := url.Parse(apiclient.BaseURL)
if sharedflows {
q := u.Query()
q.Set("sharedFlows", "true")
u.RawQuery = q.Encode()
}
u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "deployments")
respBody, err = apiclient.HttpClient(u.String())
return respBody, err
}

// GetAllDeployments
func GetAllDeployments() (respBody []byte, err error) {
apiclient.ClientPrintHttpResponse.Set(false)
proxiesResponse, err := GetDeployments(false)
if err != nil {
return nil, err
}

sharedFlowsResponse, err := GetDeployments(true)
if err != nil {
return nil, err
}

deployments := []string{}

deployments = append(deployments, "\"proxies\":"+string(proxiesResponse))
deployments = append(deployments, "\"sharedFlows\":"+string(sharedFlowsResponse))
payload := "{" + strings.Join(deployments, ",") + "}"

apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting())
err = apiclient.PrettyPrint("json", []byte(payload))
return []byte(payload), err
}

// SetOrgProperty is used to set org properties
func SetOrgProperty(name string, value string) (err error) {
u, _ := url.Parse(apiclient.BaseURL)
Expand Down