Skip to content

Commit

Permalink
WIP: onboard APIs for the developer portal #333
Browse files Browse the repository at this point in the history
  • Loading branch information
srinandan committed Nov 14, 2023
1 parent 1ede3b3 commit 142e40d
Show file tree
Hide file tree
Showing 17 changed files with 919 additions and 0 deletions.
42 changes: 42 additions & 0 deletions cmd/apicategories/apicategories.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// 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 apicategories

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

// Cmd to manage api catalog items
var Cmd = &cobra.Command{
Use: "apicategories",
Short: "Manage Apigee API categories that are tagged on catalog items",
Long: "Manage Apigee API categories that are tagged on catalog items",
}

var org, siteid, name string

func init() {
Cmd.PersistentFlags().StringVarP(&org, "org", "o",
"", "Apigee organization name")
Cmd.PersistentFlags().StringVarP(&siteid, "siteid", "s",
"", "Name or siteid of the portal")

Cmd.AddCommand(ListCmd)
Cmd.AddCommand(GetCmd)
Cmd.AddCommand(DelCmd)

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

import (
"internal/apiclient"

"internal/client/apicategories"

"github.com/spf13/cobra"
)

// CreateCmd to get a catalog items
var CreateCmd = &cobra.Command{
Use: "create",
Short: "Creates a new API category",
Long: "Creates a new API category",
Args: func(cmd *cobra.Command, args []string) (err error) {
return apiclient.SetApigeeOrg(org)
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
_, err = apicategories.Create(siteid, name)
return
},
}

func init() {
CreateCmd.Flags().StringVarP(&name, "name", "n",
"", "Catalog name")
_ = CreateCmd.MarkFlagRequired("name")
}
42 changes: 42 additions & 0 deletions cmd/apicategories/delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// 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 apicategories

import (
"internal/apiclient"
"internal/client/apicategories"

"github.com/spf13/cobra"
)

// DelCmd to get a catalog items
var DelCmd = &cobra.Command{
Use: "delete",
Short: "Deletes a catalog item",
Long: "Deletes a catalog item",
Args: func(cmd *cobra.Command, args []string) (err error) {
return apiclient.SetApigeeOrg(org)
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
_, err = apicategories.Delete(siteid, name)
return
},
}

func init() {
DelCmd.Flags().StringVarP(&name, "name", "n",
"", "Catalog name")
_ = DelCmd.MarkFlagRequired("name")
}
43 changes: 43 additions & 0 deletions cmd/apicategories/get.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// 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 apicategories

import (
"internal/apiclient"

"internal/client/apicategories"

"github.com/spf13/cobra"
)

// GetCmd to get a catalog items
var GetCmd = &cobra.Command{
Use: "get",
Short: "Gets a catalog item",
Long: "Gets a catalog item",
Args: func(cmd *cobra.Command, args []string) (err error) {
return apiclient.SetApigeeOrg(org)
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
_, err = apicategories.Get(siteid, name)
return
},
}

func init() {
GetCmd.Flags().StringVarP(&name, "name", "n",
"", "Catalog name")
_ = GetCmd.MarkFlagRequired("name")
}
36 changes: 36 additions & 0 deletions cmd/apicategories/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 apicategories

import (
"internal/apiclient"
"internal/client/apicategories"

"github.com/spf13/cobra"
)

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

// Cmd to manage apis
var Cmd = &cobra.Command{
Use: "apidocs",
Short: "Manage Apigee API catalog item through ApiDoc",
Long: "Manage Apigee API catalog item through ApiDoc",
}

var org, siteid, name string

func init() {
Cmd.PersistentFlags().StringVarP(&org, "org", "o",
"", "Apigee organization name")
Cmd.PersistentFlags().StringVarP(&siteid, "siteid", "s",
"", "Name or siteid of the portal")

Cmd.AddCommand(ListCmd)
Cmd.AddCommand(GetCmd)
Cmd.AddCommand(DelCmd)
Cmd.AddCommand(DocCmd)

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

"internal/apiclient"
"internal/client/apidocs"

"github.com/spf13/cobra"
)

// CreateCmd to create a catalog items
var CreateCmd = &cobra.Command{
Use: "create",
Short: "Create a new catalog item",
Long: "Create a new catalog item",
Args: func(cmd *cobra.Command, args []string) (err error) {
_, err = strconv.ParseBool(published)
if err != nil {
return fmt.Errorf("published must be a boolean value: %v", err)
}
_, err = strconv.ParseBool(anonAllowed)
if err != nil {
return fmt.Errorf("allow-anon must be a boolean value: %v", err)
}

_, err = strconv.ParseBool(requireCallbackUrl)
if err != nil {
return fmt.Errorf("require-callback-url must be a boolean value: %v", err)
}

return apiclient.SetApigeeOrg(org)
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
_, err = apidocs.Create(siteid, title, description, published,
anonAllowed, apiProductName, requireCallbackUrl, imageUrl, categoryIds)
return
},
}

var (
title, description, published, anonAllowed, apiProductName string
requireCallbackUrl, imageUrl string
categoryIds []string
)

func init() {
CreateCmd.Flags().StringVarP(&title, "title", "t",
"", "The user-facing name of the catalog item")
CreateCmd.Flags().StringVarP(&description, "desc", "d",
"", "Description of the catalog item")
CreateCmd.Flags().StringVarP(&published, "published", "p",
"", "Denotes whether the catalog item is published to the portal or is in a draft state")
CreateCmd.Flags().StringVarP(&anonAllowed, "allow-anon", "",
"", "Boolean flag that manages user access to the catalog item")
CreateCmd.Flags().StringVarP(&apiProductName, "api-product", "",
"", "The name field of the associated API product")
CreateCmd.Flags().StringVarP(&requireCallbackUrl, "require-callback-url", "",
"", "Whether a callback URL is required when this catalog item's developer app is created")
CreateCmd.Flags().StringVarP(&imageUrl, "image-url", "",
"", "Location of the image used for the catalog item in the catalog")

CreateCmd.Flags().StringArrayVarP(&categoryIds, "category-ids", "",
nil, "The IDs of the API categories to which this catalog item belongs")

_ = CreateCmd.MarkFlagRequired("name")
_ = CreateCmd.MarkFlagRequired("title")
_ = CreateCmd.MarkFlagRequired("apiProductName")
}
42 changes: 42 additions & 0 deletions cmd/apidocs/delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// 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 (
"internal/apiclient"
"internal/client/apidocs"

"github.com/spf13/cobra"
)

// DelCmd to get a catalog items
var DelCmd = &cobra.Command{
Use: "delete",
Short: "Deletes a catalog item",
Long: "Deletes a catalog item",
Args: func(cmd *cobra.Command, args []string) (err error) {
return apiclient.SetApigeeOrg(org)
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
_, err = apidocs.Delete(siteid, name)
return
},
}

func init() {
DelCmd.Flags().StringVarP(&name, "name", "n",
"", "Catalog name")
_ = DelCmd.MarkFlagRequired("name")
}
Loading

0 comments on commit 142e40d

Please sign in to comment.