diff --git a/internal/apiclient/options.go b/internal/apiclient/options.go index d9d8cb1ce..f67bcd8ef 100644 --- a/internal/apiclient/options.go +++ b/internal/apiclient/options.go @@ -31,6 +31,9 @@ const ( // registryBaseURL is the Apigee API Hub control plane endpoint const registryBaseURL = "https://apihub.googleapis.com/v1/projects/%s/locations/%s" +// API Observability control plane endpoint +const apiObserveBaseURL = "https://apim.googleapis.com/v1alpha/projects/%s/locations/%s" + // baseDRZURL is the Apigee control plane endpoint const baseDRZURL = "https://%s-apigee.googleapis.com/v1/organizations/" @@ -336,6 +339,14 @@ func GetApigeeRegistryURL() (registryURL string) { return fmt.Sprintf(registryBaseURL, options.ProjectID, options.Region) } +// GetAPIObserveURL +func GetAPIObserveURL() (apiObserveURL string) { + if options.ProjectID == "" { + options.ProjectID = options.Org + } + return fmt.Sprintf(apiObserveBaseURL, options.ProjectID, options.Region) +} + // GetApigeeBaseURL func GetApigeeBaseURL() string { if options.Region != "" { diff --git a/internal/client/observe/observe.go b/internal/client/observe/observe.go new file mode 100644 index 000000000..bb12540c6 --- /dev/null +++ b/internal/client/observe/observe.go @@ -0,0 +1,163 @@ +// 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 observe + +import ( + "encoding/json" + "net/url" + "path" + "strconv" + "strings" + + "internal/apiclient" +) + +type Action uint8 + +const ( + ENABLE Action = iota + DISABLE +) + +func CreateObservationJob(observationJobId string, sources []string) (respBody []byte, err error) { + var payload string + + u, _ := url.Parse(apiclient.GetAPIObserveURL()) + u.Path = path.Join(u.Path, "observationJobs") + q := u.Query() + q.Set("observationJobId", observationJobId) + u.RawQuery = q.Encode() + + if len(sources) != 0 { + payload = "{ \"sources\":[\"" + strings.Join(sources, "\", \"") + "\"]}" + } + respBody, err = apiclient.HttpClient(u.String(), payload, "POST") + return respBody, err +} + +func GetObservationJob(observationJobId string) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetAPIObserveURL()) + u.Path = path.Join(u.Path, "observationJobs", observationJobId) + respBody, err = apiclient.HttpClient(u.String()) + return respBody, err +} + +func DeleteObservationJob(observationJobId string) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetAPIObserveURL()) + u.Path = path.Join(u.Path, "observationJobs", observationJobId) + respBody, err = apiclient.HttpClient(u.String(), "", "DELETE") + return respBody, err +} + +func ListObservationJobs(pageSize int, pageToken string) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetAPIObserveURL()) + u.Path = path.Join(u.Path, "observationJobs") + q := u.Query() + if pageSize != -1 { + q.Set("pageSize", strconv.Itoa(pageSize)) + } + if pageToken != "" { + q.Set("pageToken", pageToken) + } + u.RawQuery = q.Encode() + respBody, err = apiclient.HttpClient(u.String()) + return respBody, err +} + +func EnableObservationJob(observationJob string) (respBody []byte, err error) { + return controlObservation(observationJob, ENABLE) +} + +func DisableObservationJob(observationJob string) (respBody []byte, err error) { + return controlObservation(observationJob, DISABLE) +} + +func GetApiObservation(name string, observationJob string) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetAPIObserveURL()) + u.Path = path.Join(u.Path, "observationJobs", observationJob, "apiObservations", name) + respBody, err = apiclient.HttpClient(u.String()) + return respBody, err +} + +func ListApiObservations(observationJob string, pageSize int, pageToken string) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetAPIObserveURL()) + u.Path = path.Join(u.Path, "observationJobs", observationJob, "apiObservations") + q := u.Query() + if pageSize != -1 { + q.Set("pageSize", strconv.Itoa(pageSize)) + } + if pageToken != "" { + q.Set("pageToken", pageToken) + } + u.RawQuery = q.Encode() + respBody, err = apiclient.HttpClient(u.String()) + return respBody, err +} + +func CreateObservationSource(observationSourceId string, pscNetworkConfigs map[string]string) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetAPIObserveURL()) + u.Path = path.Join(u.Path, "observationSources") + q := u.Query() + q.Set("observationSourceId", observationSourceId) + u.RawQuery = q.Encode() + + networkConfig, err := json.Marshal(pscNetworkConfigs) + if err != nil { + return nil, err + } + payload := "{ \"gclbObservationSource\":{\"pscNetworkConfigs\":" + string(networkConfig) + "}}" + respBody, err = apiclient.HttpClient(u.String(), payload, "POST") + return respBody, err +} + +func GetObservationSource(observationSourceId string) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetAPIObserveURL()) + u.Path = path.Join(u.Path, "observationSources", observationSourceId) + respBody, err = apiclient.HttpClient(u.String()) + return respBody, err +} + +func DeleteObservationSource(observationSourceId string) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetAPIObserveURL()) + u.Path = path.Join(u.Path, "observationSources", observationSourceId) + respBody, err = apiclient.HttpClient(u.String(), "", "DELETE") + return respBody, err +} + +func ListObservationSources(pageSize int, pageToken string) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetAPIObserveURL()) + u.Path = path.Join(u.Path, "observationSources") + q := u.Query() + if pageSize != -1 { + q.Set("pageSize", strconv.Itoa(pageSize)) + } + if pageToken != "" { + q.Set("pageToken", pageToken) + } + u.RawQuery = q.Encode() + respBody, err = apiclient.HttpClient(u.String()) + return respBody, err +} + +func controlObservation(observationJob string, action Action) (respBody []byte, err error) { + u, _ := url.Parse(apiclient.GetAPIObserveURL()) + if action == ENABLE { + u.Path = path.Join(u.Path, "observationJobs", observationJob+":enable") + } else { + u.Path = path.Join(u.Path, "observationJobs", observationJob+":disable") + } + respBody, err = apiclient.HttpClient(u.String(), "", "POST") + return respBody, err +} diff --git a/internal/cmd/observe/jobs/create.go b/internal/cmd/observe/jobs/create.go new file mode 100644 index 000000000..8a093431b --- /dev/null +++ b/internal/cmd/observe/jobs/create.go @@ -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 jobs + +import ( + "internal/apiclient" + "internal/client/observe" + + "github.com/spf13/cobra" +) + +// CrtCmd +var CrtCmd = &cobra.Command{ + Use: "create", + Short: "Create a new Observation Job", + Long: "Create a new Observation Job", + 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 = observe.CreateObservationJob(observationJobId, sources) + return + }, +} + +var ( + observationJobId string + sources []string +) + +func init() { + CrtCmd.Flags().StringVarP(&observationJobId, "id", "i", + "", "Observation Job") + CrtCmd.Flags().StringArrayVarP(&sources, "sources", "s", + nil, "The full path to source (repeat for multiple)") + + _ = CrtCmd.MarkFlagRequired("id") + _ = CrtCmd.MarkFlagRequired("sources") +} diff --git a/internal/cmd/observe/jobs/delete.go b/internal/cmd/observe/jobs/delete.go new file mode 100644 index 000000000..00b8ee00d --- /dev/null +++ b/internal/cmd/observe/jobs/delete.go @@ -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 jobs + +import ( + "internal/apiclient" + "internal/client/observe" + + "github.com/spf13/cobra" +) + +// DeleteCmd to get a catalog items +var DeleteCmd = &cobra.Command{ + Use: "delete", + Short: "Delete an Observation Job", + Long: "Delete an Observation Job", + 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 = observe.DeleteObservationJob(observationJobId) + return + }, +} + +func init() { + DeleteCmd.Flags().StringVarP(&observationJobId, "id", "i", + "", "Observation Job Id") + + _ = DeleteCmd.MarkFlagRequired("id") +} diff --git a/internal/cmd/observe/jobs/disable.go b/internal/cmd/observe/jobs/disable.go new file mode 100644 index 000000000..f743e3842 --- /dev/null +++ b/internal/cmd/observe/jobs/disable.go @@ -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 jobs + +import ( + "internal/apiclient" + "internal/client/observe" + + "github.com/spf13/cobra" +) + +// DisableCmd to get a catalog items +var DisableCmd = &cobra.Command{ + Use: "disable", + Short: "Disable an Observation Job", + Long: "Disable an Observation Job", + 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 = observe.DisableObservationJob(observationJobId) + return + }, +} + +func init() { + DisableCmd.Flags().StringVarP(&observationJobId, "id", "i", + "", "Observation Job Id") + + _ = DisableCmd.MarkFlagRequired("id") +} diff --git a/internal/cmd/observe/jobs/enable.go b/internal/cmd/observe/jobs/enable.go new file mode 100644 index 000000000..7b6666f39 --- /dev/null +++ b/internal/cmd/observe/jobs/enable.go @@ -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 jobs + +import ( + "internal/apiclient" + "internal/client/observe" + + "github.com/spf13/cobra" +) + +// EnableCmd to get a catalog items +var EnableCmd = &cobra.Command{ + Use: "enable", + Short: "Enable an Observation Job", + Long: "Enable an Observation Job", + 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 = observe.EnableObservationJob(observationJobId) + return + }, +} + +func init() { + EnableCmd.Flags().StringVarP(&observationJobId, "id", "i", + "", "Observation Job Id") + + _ = EnableCmd.MarkFlagRequired("id") +} diff --git a/internal/cmd/observe/jobs/get.go b/internal/cmd/observe/jobs/get.go new file mode 100644 index 000000000..667b70f58 --- /dev/null +++ b/internal/cmd/observe/jobs/get.go @@ -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 jobs + +import ( + "internal/apiclient" + "internal/client/observe" + + "github.com/spf13/cobra" +) + +// GetCmd to get a catalog items +var GetCmd = &cobra.Command{ + Use: "get", + Short: "Get details for an Observation Job", + Long: "Get details for an Observation Job", + 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 = observe.GetObservationJob(observationJobId) + return + }, +} + +func init() { + GetCmd.Flags().StringVarP(&observationJobId, "id", "i", + "", "Observation Job Id") + + _ = GetCmd.MarkFlagRequired("id") +} diff --git a/internal/cmd/observe/jobs/jobs.go b/internal/cmd/observe/jobs/jobs.go new file mode 100644 index 000000000..af82c7cec --- /dev/null +++ b/internal/cmd/observe/jobs/jobs.go @@ -0,0 +1,40 @@ +// 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 jobs + +import "github.com/spf13/cobra" + +// ObservationJobCmd to manage apis +var ObservationJobCmd = &cobra.Command{ + Use: "jobs", + Short: "Manage Observation jobs for Shadow API Discovery", + Long: "Manage Observation jobs for Shadow API Discovery", +} + +var org, region string + +func init() { + ObservationJobCmd.PersistentFlags().StringVarP(&org, "org", "o", + "", "Apigee organization name") + ObservationJobCmd.PersistentFlags().StringVarP(®ion, "region", "r", + "", "API Observation region name") + + ObservationJobCmd.AddCommand(CrtCmd) + ObservationJobCmd.AddCommand(GetCmd) + ObservationJobCmd.AddCommand(DeleteCmd) + ObservationJobCmd.AddCommand(ListCmd) + ObservationJobCmd.AddCommand(EnableCmd) + ObservationJobCmd.AddCommand(DisableCmd) +} diff --git a/internal/cmd/observe/jobs/list.go b/internal/cmd/observe/jobs/list.go new file mode 100644 index 000000000..41b959c3f --- /dev/null +++ b/internal/cmd/observe/jobs/list.go @@ -0,0 +1,50 @@ +// 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 jobs + +import ( + "internal/apiclient" + "internal/client/observe" + + "github.com/spf13/cobra" +) + +// ListCmd to get a catalog items +var ListCmd = &cobra.Command{ + Use: "list", + Short: "List Observation Jobs", + Long: "List Observation Jobs", + 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 = observe.ListObservationJobs(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") +} diff --git a/internal/cmd/observe/observe.go b/internal/cmd/observe/observe.go new file mode 100644 index 000000000..48a330a0f --- /dev/null +++ b/internal/cmd/observe/observe.go @@ -0,0 +1,34 @@ +// 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 observe + +import ( + "internal/cmd/observe/jobs" + "internal/cmd/observe/sources" + + "github.com/spf13/cobra" +) + +// Cmd to api observability +var Cmd = &cobra.Command{ + Use: "observations", + Short: "Enables users to discover shadow APIs in GCP", + Long: "Enables users to discover shadow APIs in existing Google Cloud infrastructure", +} + +func init() { + Cmd.AddCommand(jobs.ObservationJobCmd) + Cmd.AddCommand(sources.ObservationSourceCmd) +} diff --git a/internal/cmd/observe/sources/create.go b/internal/cmd/observe/sources/create.go new file mode 100644 index 000000000..99cb316ab --- /dev/null +++ b/internal/cmd/observe/sources/create.go @@ -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 sources + +import ( + "internal/apiclient" + "internal/client/observe" + + "github.com/spf13/cobra" +) + +// CrtCmd +var CrtCmd = &cobra.Command{ + Use: "create", + Short: "Create a new Observation Source", + Long: "Create a new Observation Source", + 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 = observe.CreateObservationSource(observationSourceId, pscConfig) + return + }, +} + +var ( + observationSourceId string + pscConfig map[string]string +) + +func init() { + CrtCmd.Flags().StringVarP(&observationSourceId, "id", "i", + "", "Observation Job") + CrtCmd.Flags().StringToStringVarP(&pscConfig, "psc-config", "p", + nil, "The full path to the VPC network and subnetwork where traffic will be observed. (repeat or comma separated)") + + _ = CrtCmd.MarkFlagRequired("id") + _ = CrtCmd.MarkFlagRequired("sources") +} diff --git a/internal/cmd/observe/sources/delete.go b/internal/cmd/observe/sources/delete.go new file mode 100644 index 000000000..db0934660 --- /dev/null +++ b/internal/cmd/observe/sources/delete.go @@ -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 sources + +import ( + "internal/apiclient" + "internal/client/observe" + + "github.com/spf13/cobra" +) + +// DeleteCmd to get a catalog items +var DeleteCmd = &cobra.Command{ + Use: "delete", + Short: "Delete an Observation Source", + Long: "Delete an Observation Source", + 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 = observe.DeleteObservationSource(observationSourceId) + return + }, +} + +func init() { + DeleteCmd.Flags().StringVarP(&observationSourceId, "id", "i", + "", "Observation Source Id") + + _ = DeleteCmd.MarkFlagRequired("id") +} diff --git a/internal/cmd/observe/sources/get.go b/internal/cmd/observe/sources/get.go new file mode 100644 index 000000000..6c88145b9 --- /dev/null +++ b/internal/cmd/observe/sources/get.go @@ -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 sources + +import ( + "internal/apiclient" + "internal/client/observe" + + "github.com/spf13/cobra" +) + +// GetCmd to get a catalog items +var GetCmd = &cobra.Command{ + Use: "get", + Short: "Get details for an Observation Source", + Long: "Get details for an Observation Source", + 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 = observe.GetObservationSource(observationSourceId) + return + }, +} + +func init() { + GetCmd.Flags().StringVarP(&observationSourceId, "id", "i", + "", "Observation Source Id") + + _ = GetCmd.MarkFlagRequired("id") +} diff --git a/internal/cmd/observe/sources/list.go b/internal/cmd/observe/sources/list.go new file mode 100644 index 000000000..a5795a5e4 --- /dev/null +++ b/internal/cmd/observe/sources/list.go @@ -0,0 +1,50 @@ +// 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 sources + +import ( + "internal/apiclient" + "internal/client/observe" + + "github.com/spf13/cobra" +) + +// ListCmd to get a catalog items +var ListCmd = &cobra.Command{ + Use: "list", + Short: "List Observation Sources", + Long: "List Observation Sources", + 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 = observe.ListObservationSources(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") +} diff --git a/internal/cmd/observe/sources/sources.go b/internal/cmd/observe/sources/sources.go new file mode 100644 index 000000000..e1c26439f --- /dev/null +++ b/internal/cmd/observe/sources/sources.go @@ -0,0 +1,38 @@ +// 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 sources + +import "github.com/spf13/cobra" + +// ObservationSourceCmd to manage apis +var ObservationSourceCmd = &cobra.Command{ + Use: "sources", + Short: "Manage Observation sources for Shadow API Discovery", + Long: "Manage Observation sources for Shadow API Discovery", +} + +var org, region string + +func init() { + ObservationSourceCmd.PersistentFlags().StringVarP(&org, "org", "o", + "", "Apigee organization name") + ObservationSourceCmd.PersistentFlags().StringVarP(®ion, "region", "r", + "", "API Observation region name") + + ObservationSourceCmd.AddCommand(CrtCmd) + ObservationSourceCmd.AddCommand(GetCmd) + ObservationSourceCmd.AddCommand(DeleteCmd) + ObservationSourceCmd.AddCommand(ListCmd) +} diff --git a/internal/cmd/root.go b/internal/cmd/root.go index 654bc3be5..ac51fd91d 100644 --- a/internal/cmd/root.go +++ b/internal/cmd/root.go @@ -37,6 +37,7 @@ import ( "internal/cmd/keyaliases" "internal/cmd/keystores" "internal/cmd/kvm" + "internal/cmd/observe" "internal/cmd/ops" "internal/cmd/org" "internal/cmd/preferences" @@ -197,6 +198,7 @@ func init() { RootCmd.AddCommand(securityprofiles.Cmd) RootCmd.AddCommand(sites.Cmd) RootCmd.AddCommand(apihub.Cmd) + RootCmd.AddCommand(observe.Cmd) RootCmd.AddCommand(tree.Cmd) RootCmd.AddCommand(reports.Cmd) }