-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
9 changed files
with
303 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// 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 reports | ||
|
||
import ( | ||
"internal/apiclient" | ||
"net/url" | ||
"path" | ||
"strconv" | ||
) | ||
|
||
// Create a report | ||
func Create(contents []byte) (respBody []byte, err error) { | ||
u, _ := url.Parse(apiclient.GetApigeeBaseURL()) | ||
u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "reports") | ||
respBody, err = apiclient.HttpClient(u.String(), string(contents)) | ||
return respBody, err | ||
} | ||
|
||
// Get a report | ||
func Get(name string) (respBody []byte, err error) { | ||
u, _ := url.Parse(apiclient.GetApigeeBaseURL()) | ||
u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "reports", name) | ||
respBody, err = apiclient.HttpClient(u.String()) | ||
return respBody, err | ||
} | ||
|
||
// Delete a report | ||
func Delete(name string) (respBody []byte, err error) { | ||
u, _ := url.Parse(apiclient.GetApigeeBaseURL()) | ||
u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "reports", name) | ||
respBody, err = apiclient.HttpClient(u.String(), "", "DELETE") | ||
return respBody, err | ||
} | ||
|
||
// List reports | ||
func List(expand bool) (respBody []byte, err error) { | ||
u, _ := url.Parse(apiclient.GetApigeeBaseURL()) | ||
u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "reports") | ||
q := u.Query() | ||
q.Set("expand", strconv.FormatBool(expand)) | ||
u.RawQuery = q.Encode() | ||
respBody, err = apiclient.HttpClient(u.String()) | ||
return respBody, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// 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 reports | ||
|
||
import ( | ||
"internal/apiclient" | ||
"internal/client/reports" | ||
"internal/cmd/utils" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// CrtCmd to get a resource | ||
var CrtCmd = &cobra.Command{ | ||
Use: "create", | ||
Short: "Create a new custom report", | ||
Long: "Create a new custom report", | ||
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 | ||
|
||
contents, err := utils.ReadFile(contentPath) | ||
if err != nil { | ||
return err | ||
} | ||
_, err = reports.Create(contents) | ||
return err | ||
}, | ||
} | ||
|
||
var contentPath string | ||
|
||
func init() { | ||
CrtCmd.Flags().StringVarP(&contentPath, "file", "f", | ||
"", "Path to a file containing the custom report content") | ||
|
||
_ = CrtCmd.MarkFlagRequired("file") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// 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 reports | ||
|
||
import ( | ||
"internal/apiclient" | ||
"internal/client/reports" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// DelCmd to get a resource | ||
var DelCmd = &cobra.Command{ | ||
Use: "delete", | ||
Short: "Delete a custom report", | ||
Long: "Delete a custom report", | ||
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 = reports.Delete(name) | ||
return err | ||
}, | ||
} | ||
|
||
func init() { | ||
DelCmd.Flags().StringVarP(&name, "name", "n", | ||
"", "Name of the custom report") | ||
|
||
_ = DelCmd.MarkFlagRequired("name") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// 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 reports | ||
|
||
import ( | ||
"internal/apiclient" | ||
"internal/client/reports" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// GetCmd to get a resource | ||
var GetCmd = &cobra.Command{ | ||
Use: "get", | ||
Short: "Get details for a custom report", | ||
Long: "Get details for a custom report", | ||
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 = reports.Get(name) | ||
return err | ||
}, | ||
} | ||
|
||
func init() { | ||
GetCmd.Flags().StringVarP(&name, "name", "n", | ||
"", "Name of the custom report") | ||
|
||
_ = GetCmd.MarkFlagRequired("name") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// 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 reports | ||
|
||
import ( | ||
"internal/apiclient" | ||
"internal/client/reports" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// ListCmd to get a resource | ||
var ListCmd = &cobra.Command{ | ||
Use: "list", | ||
Short: "List all custom reports in the org", | ||
Long: "List all custom reports in the org", | ||
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 = reports.List(expand) | ||
return | ||
}, | ||
} | ||
|
||
var expand bool | ||
|
||
func init() { | ||
ListCmd.Flags().BoolVarP(&expand, "expand", "x", | ||
false, "Set to 'true' to get expanded details about each custom report") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// 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 reports | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// Cmd to manage identities | ||
var Cmd = &cobra.Command{ | ||
Use: "reports", | ||
Short: "Manage Analytics custom reports", | ||
Long: "Manage analytics custom reports", | ||
} | ||
|
||
var org, name, region string | ||
|
||
func init() { | ||
Cmd.PersistentFlags().StringVarP(&org, "org", "o", | ||
"", "Apigee organization name") | ||
Cmd.PersistentFlags().StringVarP(®ion, "region", "r", | ||
"", "Apigee control plane region name; default is https://apigee.googleapis.com") | ||
|
||
Cmd.AddCommand(GetCmd) | ||
Cmd.AddCommand(DelCmd) | ||
Cmd.AddCommand(ListCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters