Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adds support to list sites #345 #346

Merged
merged 9 commits into from
Dec 12, 2023
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ apiproxy/

#keys for envoy
remote-service.*

#json files
*.json
2 changes: 2 additions & 0 deletions cmd/apidocs/apidocs.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ func init() {
Cmd.AddCommand(DocCmd)
Cmd.AddCommand(CreateCmd)
Cmd.AddCommand(UpdateCmd)
Cmd.AddCommand(ExpCmd)
Cmd.AddCommand(ImpCmd)

_ = Cmd.MarkFlagRequired("org")
_ = Cmd.MarkFlagRequired("siteid")
Expand Down
52 changes: 52 additions & 0 deletions cmd/apidocs/export.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// 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 apidocs

import (
"os"

"internal/apiclient"

"internal/client/apidocs"

"github.com/spf13/cobra"
)

// ExpCmd to export apidocs
var ExpCmd = &cobra.Command{
Use: "export",
Short: "Export API Docs to a file",
Long: "Export API Docs to a file",
Args: func(cmd *cobra.Command, args []string) (err error) {
return apiclient.SetApigeeOrg(org)
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
if folder == "" {
folder, _ = os.Getwd()
}
if err = apiclient.FolderExists(folder); err != nil {
return err
}
apiclient.DisableCmdPrintHttpResponse()
return apidocs.Export(folder)
},
}

var folder string

func init() {
ExpCmd.Flags().StringVarP(&folder, "folder", "f",
"", "folder to export API Docs")
}
47 changes: 47 additions & 0 deletions cmd/apidocs/import.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// 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 apidocs

import (
"fmt"
"internal/apiclient"

"internal/client/apidocs"

"github.com/spf13/cobra"
)

// ImpCmd to import products
var ImpCmd = &cobra.Command{
Use: "import",
Short: "Import from a folder containing apidocs",
Long: "Import from a folder containing apidocs",
Args: func(cmd *cobra.Command, args []string) (err error) {
return apiclient.SetApigeeOrg(org)
},
RunE: func(cmd *cobra.Command, args []string) error {
if siteid == "" {
return fmt.Errorf("siteid is a mandatory parameter")
}
return apidocs.Import(siteid, folder)
},
}

func init() {
ImpCmd.Flags().StringVarP(&folder, "folder", "f",
"", "Folder containing site_<siteid>.json and apidocs_<siteid>_<id>.json files")

_ = ImpCmd.MarkFlagRequired("file")
}
14 changes: 13 additions & 1 deletion cmd/apidocs/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,19 @@ var ListCmd = &cobra.Command{
return apiclient.SetApigeeOrg(org)
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
_, err = apidocs.List(siteid)
_, err = apidocs.List(siteid, pageSize, pageToken)
return
},
}

var (
pageSize int
pageToken string
)

func init() {
ListCmd.Flags().IntVarP(&pageSize, "page-size", "",
-1, "The maximum number of versions to return")
ListCmd.Flags().StringVarP(&pageToken, "page-token", "",
"", "A page token, received from a previous call")
}
15 changes: 13 additions & 2 deletions cmd/org/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

"internal/clilog"

"internal/client/apidocs"
"internal/client/apis"
"internal/client/appgroups"
"internal/client/apps"
Expand Down Expand Up @@ -180,6 +181,11 @@ var ExportCmd = &cobra.Command{
}
}

clilog.Info.Println("Exporting API Portal apidocs Configuration...")
if err = apidocs.Export(portalsFolderName); proceedOnError(err) != nil {
return err
}

if runtimeType == "HYBRID" {
clilog.Info.Println("Exporting Sync Authorization Identities...")
if respBody, err = sync.Get(); err != nil {
Expand Down Expand Up @@ -307,8 +313,13 @@ func createFolders() (err error) {
if err = os.Mkdir(proxiesFolderName, 0o755); err != nil {
return err
}
err = os.Mkdir(sharedFlowsFolderName, 0o755)
return err
if err = os.Mkdir(sharedFlowsFolderName, 0o755); err != nil {
return err
}
if err = os.Mkdir(portalsFolderName, 0o755); err != nil {
return err
}
return nil
}

func exportKVMEntries(scope string, env string, listKVMBytes []byte) (err error) {
Expand Down
1 change: 1 addition & 0 deletions cmd/org/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const (

proxiesFolderName = "proxies"
sharedFlowsFolderName = "sharedflows"
portalsFolderName = "portals"
)

var conn int
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import (
res "github.com/apigee/apigeecli/cmd/res"
"github.com/apigee/apigeecli/cmd/securityprofiles"
"github.com/apigee/apigeecli/cmd/sharedflows"
"github.com/apigee/apigeecli/cmd/sites"
"github.com/apigee/apigeecli/cmd/sync"
targetservers "github.com/apigee/apigeecli/cmd/targetservers"
"github.com/apigee/apigeecli/cmd/token"
Expand Down Expand Up @@ -180,6 +181,7 @@ func init() {
RootCmd.AddCommand(apicategories.Cmd)
RootCmd.AddCommand(datastores.Cmd)
RootCmd.AddCommand(securityprofiles.Cmd)
RootCmd.AddCommand(sites.Cmd)
}

func initConfig() {
Expand Down
36 changes: 36 additions & 0 deletions cmd/sites/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// 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 sites

import (
"internal/apiclient"
"internal/client/sites"

"github.com/spf13/cobra"
)

// ListCmd to list catalog items
var ListCmd = &cobra.Command{
Use: "list",
Short: "Returns the API Portals associated with the org",
Long: "Returns the API Portals associated with the org",
Args: func(cmd *cobra.Command, args []string) (err error) {
return apiclient.SetApigeeOrg(org)
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
_, err = sites.List()
return
},
}
37 changes: 37 additions & 0 deletions cmd/sites/sites.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// 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 sites

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

// Cmd to manage
var Cmd = &cobra.Command{
Use: "sites",
Short: "Manage Apigee API Portals",
Long: "Manage Apigee API Portals",
}

var org string

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

Cmd.AddCommand(ListCmd)

_ = Cmd.MarkFlagRequired("org")
}
Loading