Skip to content
Open
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
40 changes: 39 additions & 1 deletion internal/client/sites/sites.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,52 @@ import (
"github.com/thedevsaddam/gojsonq"
)

// List
// List returns all integrated developer portals for the org.
func List() (respBody []byte, err error) {
u, _ := url.Parse(apiclient.GetApigeeBaseURL())
u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "sites")
respBody, err = apiclient.HttpClient(u.String())
return respBody, err
}

// Get returns a single integrated developer portal by site ID.
func Get(siteID string) (respBody []byte, err error) {
u, _ := url.Parse(apiclient.GetApigeeBaseURL())
u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "sites", siteID)
respBody, err = apiclient.HttpClient(u.String())
return respBody, err
}

// Create creates a new integrated developer portal from a JSON payload.
// siteID is the desired portal ID; it may be passed as a query param.
func Create(siteID string, payload []byte) (respBody []byte, err error) {
u, _ := url.Parse(apiclient.GetApigeeBaseURL())
u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "sites")
if siteID != "" {
q := u.Query()
q.Set("siteId", siteID)
u.RawQuery = q.Encode()
}
respBody, err = apiclient.HttpClient(u.String(), string(payload))
return respBody, err
}

// Update replaces an integrated developer portal configuration.
func Update(siteID string, payload []byte) (respBody []byte, err error) {
u, _ := url.Parse(apiclient.GetApigeeBaseURL())
u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "sites", siteID)
respBody, err = apiclient.HttpClient(u.String(), string(payload), "PUT")
return respBody, err
}

// Delete removes an integrated developer portal.
func Delete(siteID string) (respBody []byte, err error) {
u, _ := url.Parse(apiclient.GetApigeeBaseURL())
u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "sites", siteID)
respBody, err = apiclient.HttpClient(u.String(), "", "DELETE")
return respBody, err
}

// GetSiteIDs
func GetSiteIDs() (siteIDs []string, err error) {
apiclient.ClientPrintHttpResponse.Set(false)
Expand Down
58 changes: 58 additions & 0 deletions internal/cmd/sites/create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright 2024 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 (
"fmt"
"internal/apiclient"
"internal/client/sites"
"os"

"github.com/spf13/cobra"
)

// CreateCmd creates an integrated developer portal
var CreateCmd = &cobra.Command{
Use: "create",
Short: "Create an Apigee integrated developer portal",
Long: "Create an Apigee integrated developer portal from a JSON file",
Args: func(cmd *cobra.Command, args []string) (err error) {
if createFilePath == "" {
return fmt.Errorf("required flag \"file\" not set")
}
apiclient.SetRegion(region)
return apiclient.SetApigeeOrg(org)
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
cmd.SilenceUsage = true
content, err := os.ReadFile(createFilePath)
if err != nil {
return err
}
_, err = sites.Create(createSiteID, content)
return
},
}

var (
createSiteID string
createFilePath string
)

func init() {
CreateCmd.Flags().StringVarP(&createSiteID, "site", "s", "", "Portal site ID (optional, auto-generated if not set)")
CreateCmd.Flags().StringVarP(&createFilePath, "file", "f", "", "Path to a JSON file containing the portal definition")
_ = CreateCmd.MarkFlagRequired("file")
}
45 changes: 45 additions & 0 deletions internal/cmd/sites/delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2024 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"
)

// DeleteCmd deletes an integrated developer portal
var DeleteCmd = &cobra.Command{
Use: "delete",
Short: "Delete an Apigee integrated developer portal",
Long: "Delete an Apigee integrated developer portal by its site ID",
Args: func(cmd *cobra.Command, args []string) (err error) {
apiclient.SetRegion(region)
return apiclient.SetApigeeOrg(org)
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
cmd.SilenceUsage = true
_, err = sites.Delete(deleteSiteID)
return
},
}

var deleteSiteID string

func init() {
DeleteCmd.Flags().StringVarP(&deleteSiteID, "site", "s", "", "Portal site ID")
_ = DeleteCmd.MarkFlagRequired("site")
}
45 changes: 45 additions & 0 deletions internal/cmd/sites/get.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2024 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"
)

// GetCmd gets an integrated developer portal by site ID
var GetCmd = &cobra.Command{
Use: "get",
Short: "Get an Apigee integrated developer portal",
Long: "Get an Apigee integrated developer portal by its site ID",
Args: func(cmd *cobra.Command, args []string) (err error) {
apiclient.SetRegion(region)
return apiclient.SetApigeeOrg(org)
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
cmd.SilenceUsage = true
_, err = sites.Get(siteIDParam)
return
},
}

var siteIDParam string

func init() {
GetCmd.Flags().StringVarP(&siteIDParam, "site", "s", "", "Portal site ID")
_ = GetCmd.MarkFlagRequired("site")
}
4 changes: 4 additions & 0 deletions internal/cmd/sites/sites.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ func init() {
"", "Apigee control plane region name; default is https://apigee.googleapis.com")

Cmd.AddCommand(ListCmd)
Cmd.AddCommand(GetCmd)
Cmd.AddCommand(CreateCmd)
Cmd.AddCommand(UpdateCmd)
Cmd.AddCommand(DeleteCmd)

_ = Cmd.MarkFlagRequired("org")
}
59 changes: 59 additions & 0 deletions internal/cmd/sites/update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright 2024 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 (
"fmt"
"internal/apiclient"
"internal/client/sites"
"os"

"github.com/spf13/cobra"
)

// UpdateCmd updates an integrated developer portal
var UpdateCmd = &cobra.Command{
Use: "update",
Short: "Update an Apigee integrated developer portal",
Long: "Update (replace) an Apigee integrated developer portal from a JSON file",
Args: func(cmd *cobra.Command, args []string) (err error) {
if updateFilePath == "" {
return fmt.Errorf("required flag \"file\" not set")
}
apiclient.SetRegion(region)
return apiclient.SetApigeeOrg(org)
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
cmd.SilenceUsage = true
content, err := os.ReadFile(updateFilePath)
if err != nil {
return err
}
_, err = sites.Update(updateSiteID, content)
return
},
}

var (
updateSiteID string
updateFilePath string
)

func init() {
UpdateCmd.Flags().StringVarP(&updateSiteID, "site", "s", "", "Portal site ID")
UpdateCmd.Flags().StringVarP(&updateFilePath, "file", "f", "", "Path to a JSON file containing the updated portal definition")
_ = UpdateCmd.MarkFlagRequired("site")
_ = UpdateCmd.MarkFlagRequired("file")
}