-
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.
- Loading branch information
Showing
27 changed files
with
1,260 additions
and
7 deletions.
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 |
---|---|---|
|
@@ -17,6 +17,7 @@ package apidocs | |
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"internal/apiclient" | ||
"internal/client/apidocs" | ||
|
||
|
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,64 @@ | ||
// 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 datastores | ||
|
||
import ( | ||
"internal/apiclient" | ||
"internal/client/datastores" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// CreateCmd to create a datastore | ||
var CreateCmd = &cobra.Command{ | ||
Use: "create", | ||
Short: "Create a new data store", | ||
Long: "Create a new data store", | ||
Args: func(cmd *cobra.Command, args []string) (err error) { | ||
if err = validate(targetType, bucketName, gcsPath, | ||
tablePrefix, datasetName); err != nil { | ||
return err | ||
} | ||
return apiclient.SetApigeeOrg(org) | ||
}, | ||
RunE: func(cmd *cobra.Command, args []string) (err error) { | ||
_, err = datastores.Create(name, targetType, projectID, bucketName, | ||
gcsPath, datasetName, tablePrefix) | ||
return | ||
}, | ||
} | ||
|
||
var projectID, bucketName, gcsPath, datasetName, tablePrefix string | ||
|
||
func init() { | ||
CreateCmd.Flags().StringVarP(&name, "name", "n", | ||
"", "Display name for the data store") | ||
CreateCmd.Flags().StringVarP(&targetType, "target", "", | ||
"", "Destination storage type. Supported types gcs or bigquery") | ||
CreateCmd.Flags().StringVarP(&projectID, "project-id", "p", | ||
"", "GCP project in which the datastore exists") | ||
CreateCmd.Flags().StringVarP(&bucketName, "bucket-name", "b", | ||
"", "Name of the Cloud Storage bucket. Required for gcs targetType") | ||
CreateCmd.Flags().StringVarP(&gcsPath, "gcs-path", "g", | ||
"", "Path of Cloud Storage bucket Required for gcs targetType") | ||
CreateCmd.Flags().StringVarP(&datasetName, "dataset", "d", | ||
"", "BigQuery dataset name Required for bigquery targetType") | ||
CreateCmd.Flags().StringVarP(&tablePrefix, "prefix", "f", | ||
"", "Prefix of BigQuery table Required for bigquery targetType") | ||
|
||
_ = CreateCmd.MarkFlagRequired("name") | ||
_ = CreateCmd.MarkFlagRequired("target") | ||
_ = CreateCmd.MarkFlagRequired("project-id") | ||
} |
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,64 @@ | ||
// 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 datastores | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// Cmd to manage datastores | ||
var Cmd = &cobra.Command{ | ||
Use: "datastores", | ||
Short: "Manage data stores to export analytics data", | ||
Long: "Manage data stores to export analytics data", | ||
} | ||
|
||
var org, name, targetType string | ||
|
||
func init() { | ||
Cmd.PersistentFlags().StringVarP(&org, "org", "o", | ||
"", "Apigee organization name") | ||
|
||
Cmd.AddCommand(ListCmd) | ||
Cmd.AddCommand(GetCmd) | ||
Cmd.AddCommand(DeleteCmd) | ||
Cmd.AddCommand(CreateCmd) | ||
Cmd.AddCommand(UpdateCmd) | ||
Cmd.AddCommand(TestCmd) | ||
|
||
_ = Cmd.MarkFlagRequired("org") | ||
} | ||
|
||
func validate(targetType string, bucketName string, gcsPath string, | ||
tablePrefix string, datasetName string, | ||
) (err error) { | ||
if targetType != "gcs" && targetType != "bigquery" { | ||
return fmt.Errorf("invalid targetType; must be gcs or bigquery") | ||
} | ||
if targetType == "gcs" { | ||
if bucketName == "" || gcsPath == "" { | ||
return fmt.Errorf("bucketName and path are mandatory parameters for gcs targetType") | ||
} | ||
} | ||
if targetType == "bigquery" { | ||
if tablePrefix == "" || datasetName == "" { | ||
return fmt.Errorf("tablePrefix and datasetName are mandatory " + | ||
"parameters for bigquery targetType") | ||
} | ||
} | ||
return nil | ||
} |
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,59 @@ | ||
// 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 datastores | ||
|
||
import ( | ||
"fmt" | ||
|
||
"internal/apiclient" | ||
"internal/client/datastores" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// DeleteCmd to delete a datastore | ||
var DeleteCmd = &cobra.Command{ | ||
Use: "delete", | ||
Short: "Deletes a datastore connection", | ||
Long: "Deletes a datastore connection", | ||
Args: func(cmd *cobra.Command, args []string) (err error) { | ||
if name == "" && id == "" { | ||
return fmt.Errorf("id or name must be passed to the command") | ||
} | ||
if name != "" && id != "" { | ||
return fmt.Errorf("id and name cannot be passed together") | ||
} | ||
return apiclient.SetApigeeOrg(org) | ||
}, | ||
RunE: func(cmd *cobra.Command, args []string) (err error) { | ||
if id != "" { | ||
_, err = datastores.Delete(id) | ||
} else { | ||
var version string | ||
if version, err = datastores.GetVersion(name); err != nil { | ||
return err | ||
} | ||
_, err = datastores.Delete(version) | ||
} | ||
return | ||
}, | ||
} | ||
|
||
func init() { | ||
DeleteCmd.Flags().StringVarP(&id, "id", "i", | ||
"", "Datastore UUID") | ||
DeleteCmd.Flags().StringVarP(&name, "name", "n", | ||
"", "Datastore display 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,59 @@ | ||
// 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 datastores | ||
|
||
import ( | ||
"fmt" | ||
|
||
"internal/apiclient" | ||
"internal/client/datastores" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// GetCmd to get a datastore | ||
var GetCmd = &cobra.Command{ | ||
Use: "get", | ||
Short: "Gets a datastore connection", | ||
Long: "Gets a datastore connection", | ||
Args: func(cmd *cobra.Command, args []string) (err error) { | ||
if name == "" && id == "" { | ||
return fmt.Errorf("id or name must be passed to the command") | ||
} | ||
if name != "" && id != "" { | ||
return fmt.Errorf("id and name cannot be passed together") | ||
} | ||
return apiclient.SetApigeeOrg(org) | ||
}, | ||
RunE: func(cmd *cobra.Command, args []string) (err error) { | ||
if id != "" { | ||
_, err = datastores.Get(id) | ||
} else { | ||
var respBody []byte | ||
if respBody, err = datastores.GetName(name); err != nil { | ||
return err | ||
} | ||
apiclient.PrettyPrint("application/json", respBody) | ||
} | ||
return | ||
}, | ||
} | ||
|
||
func init() { | ||
GetCmd.Flags().StringVarP(&id, "id", "i", | ||
"", "Datastore UUID") | ||
GetCmd.Flags().StringVarP(&name, "name", "n", | ||
"", "Datastore display 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,41 @@ | ||
// 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 datastores | ||
|
||
import ( | ||
"internal/apiclient" | ||
"internal/client/datastores" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// ListCmd to list datastores | ||
var ListCmd = &cobra.Command{ | ||
Use: "list", | ||
Short: "Returns a list of data stores in the org", | ||
Long: "Returns a list of data stores in 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 = datastores.List(targetType) | ||
return | ||
}, | ||
} | ||
|
||
func init() { | ||
ListCmd.Flags().StringVarP(&targetType, "name", "n", | ||
"", "TargetType is used to fetch datastores of matching type; default is fetch all") | ||
} |
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,67 @@ | ||
// 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 datastores | ||
|
||
import ( | ||
"internal/apiclient" | ||
"internal/client/datastores" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// TestCmd to update a datastore | ||
var TestCmd = &cobra.Command{ | ||
Use: "test", | ||
Short: "Test an existing data store", | ||
Long: "Test an existing data store", | ||
Args: func(cmd *cobra.Command, args []string) (err error) { | ||
if err = validate(targetType, bucketName, gcsPath, | ||
tablePrefix, datasetName); err != nil { | ||
return err | ||
} | ||
return apiclient.SetApigeeOrg(org) | ||
}, | ||
RunE: func(cmd *cobra.Command, args []string) (err error) { | ||
_, err = datastores.Test(id, name, targetType, projectID, bucketName, | ||
gcsPath, datasetName, tablePrefix) | ||
return | ||
}, | ||
} | ||
|
||
var id string | ||
|
||
func init() { | ||
TestCmd.Flags().StringVarP(&id, "id", "i", | ||
"", "Data store id") | ||
TestCmd.Flags().StringVarP(&name, "name", "n", | ||
"", "Display name for the data store") | ||
TestCmd.Flags().StringVarP(&targetType, "target", "", | ||
"", "Destination storage type. Supported types gcs or bigquery") | ||
TestCmd.Flags().StringVarP(&projectID, "project-id", "p", | ||
"", "GCP project in which the datastore exists") | ||
TestCmd.Flags().StringVarP(&bucketName, "bucket-name", "b", | ||
"", "Name of the Cloud Storage bucket. Required for gcs targetType") | ||
TestCmd.Flags().StringVarP(&gcsPath, "gcs-path", "g", | ||
"", "Path of Cloud Storage bucket Required for gcs targetType") | ||
TestCmd.Flags().StringVarP(&datasetName, "dataset", "d", | ||
"", "BigQuery dataset name Required for bigquery targetType") | ||
TestCmd.Flags().StringVarP(&tablePrefix, "prefix", "f", | ||
"", "Prefix of BigQuery table Required for bigquery targetType") | ||
|
||
_ = TestCmd.MarkFlagRequired("id") | ||
_ = TestCmd.MarkFlagRequired("name") | ||
_ = TestCmd.MarkFlagRequired("target") | ||
_ = TestCmd.MarkFlagRequired("project-id") | ||
} |
Oops, something went wrong.