From a2893bc7a5111a12dcc14218fc011d52f7a26e29 Mon Sep 17 00:00:00 2001 From: Siddarth Baldwa <50803248+Siddarth-Baldwa@users.noreply.github.com> Date: Mon, 11 Nov 2024 13:31:24 +0530 Subject: [PATCH] Refactor DB Audit Logging Commands and tuck them under cluster command (#270) --- .../db_audit_log_exporter.go} | 130 +++++++++--------- cmd/cluster/cluster.go | 5 + .../log-exporter/query_log_exporter.go | 8 +- cmd/db_audit_logs_exporter_test.go | 48 +++---- cmd/root.go | 2 - cmd/util/feature_flags.go | 2 +- go.mod | 2 +- go.sum | 4 +- internal/formatter/dr.go | 4 +- 9 files changed, 103 insertions(+), 102 deletions(-) rename cmd/{db_audit_logs_exporter/db_audit_logs_exporter.go => cluster/audit-log-exporter/db_audit_log_exporter.go} (73%) diff --git a/cmd/db_audit_logs_exporter/db_audit_logs_exporter.go b/cmd/cluster/audit-log-exporter/db_audit_log_exporter.go similarity index 73% rename from cmd/db_audit_logs_exporter/db_audit_logs_exporter.go rename to cmd/cluster/audit-log-exporter/db_audit_log_exporter.go index a5ce58c..9683d1d 100644 --- a/cmd/db_audit_logs_exporter/db_audit_logs_exporter.go +++ b/cmd/cluster/audit-log-exporter/db_audit_log_exporter.go @@ -13,7 +13,7 @@ // specific language governing permissions and limitations // under the License. -package db_audit_logs_exporter +package audit_log_exporter import ( "fmt" @@ -31,19 +31,21 @@ import ( ybmclient "github.com/yugabyte/yugabytedb-managed-go-client-internal" ) -var DbAuditLogsExporterCmd = &cobra.Command{ - Use: "db-audit-logs-exporter", - Short: "Manage DB Audit Logs", - Long: "Manage DB Audit Logs", +var ClusterName string + +var DbAuditLoggingCmd = &cobra.Command{ + Use: "db-audit-logging", + Short: "Configure Database Audit Logging for your Cluster.", + Long: "Configure Database Audit Logging for your Cluster.", Run: func(cmd *cobra.Command, args []string) { cmd.Help() }, } -var assignDbAuditLogsExporterCmd = &cobra.Command{ - Use: "assign", - Short: "Assign DB Audit", - Long: "Assign DB Audit Logs to a Cluster", +var enableDbAuditLoggingCmd = &cobra.Command{ + Use: "enable", + Short: "Enable Database Audit Logging", + Long: "Enable Database Audit Logging", Run: func(cmd *cobra.Command, args []string) { authApi, err := ybmAuthClient.NewAuthApiClient() @@ -54,20 +56,20 @@ var assignDbAuditLogsExporterCmd = &cobra.Command{ clusterName, _ := cmd.Flags().GetString("cluster-name") integrationName, _ := cmd.Flags().GetString("integration-name") - ysqlConfig, _ := cmd.Flags().GetStringToString("ysql-config") - statement_classes, _ := cmd.Flags().GetString("statement_classes") clusterId, err := authApi.GetClusterIdByName(clusterName) if err != nil { logrus.Fatal(err) } - integrationId, err := getIntegrationIdFromName(integrationName, authApi) - + integrationId, err := authApi.GetIntegrationIdFromName(integrationName) if err != nil { logrus.Fatalf(ybmAuthClient.GetApiErrorDetails(err)) } + ysqlConfig, _ := cmd.Flags().GetStringToString("ysql-config") + statement_classes, _ := cmd.Flags().GetString("statement_classes") + dbAuditLogsExporterSpec, err := setDbAuditLogsExporterSpec(ysqlConfig, statement_classes, integrationId) if err != nil { @@ -82,9 +84,7 @@ var assignDbAuditLogsExporterCmd = &cobra.Command{ } respData := resp.GetData() - dbAuditLogConfigId := respData.Info.Id - - msg := fmt.Sprintf("The db audit exporter config %s is being created", formatter.Colorize(dbAuditLogConfigId, formatter.GREEN_COLOR)) + msg := fmt.Sprintf("Db audit logging is being enabled for cluster %s", formatter.Colorize(clusterName, formatter.GREEN_COLOR)) if viper.GetBool("wait") { returnStatus, err := authApi.WaitForTaskCompletion(clusterId, ybmclient.ENTITYTYPEENUM_CLUSTER, ybmclient.TASKTYPEENUM_ENABLE_DATABASE_AUDIT_LOGGING, []string{"FAILED", "SUCCEEDED"}, msg) @@ -94,7 +94,7 @@ var assignDbAuditLogsExporterCmd = &cobra.Command{ if returnStatus != "SUCCEEDED" { logrus.Fatalf("Operation failed with error: %s", returnStatus) } - fmt.Printf("DB audit logging %v has been started on the cluster %v\n", formatter.Colorize(dbAuditLogConfigId, formatter.GREEN_COLOR), formatter.Colorize(clusterName, formatter.GREEN_COLOR)) + fmt.Printf("DB audit logging has been enabled on the cluster %v\n", formatter.Colorize(clusterName, formatter.GREEN_COLOR)) respC, r, err := authApi.ListDbAuditExporterConfig(clusterId).Execute() if err != nil { @@ -115,10 +115,10 @@ var assignDbAuditLogsExporterCmd = &cobra.Command{ }, } -var updateDbAuditLogsExporterCmd = &cobra.Command{ +var updateDbAuditLoggingCmd = &cobra.Command{ Use: "update", - Short: "Update DB Audit", - Long: "Update DB Audit Log Configuration for a Cluster", + Short: "Update Database Audit Logging Configuration", + Long: "Update Database Audit Logging Configuration", Run: func(cmd *cobra.Command, args []string) { authApi, err := ybmAuthClient.NewAuthApiClient() if err != nil { @@ -158,9 +158,7 @@ var updateDbAuditLogsExporterCmd = &cobra.Command{ respData := resp.GetData() - dbAuditLogConfigId := respData.Info.Id - - msg := fmt.Sprintf("The db audit exporter config %s is being updated", formatter.Colorize(dbAuditLogConfigId, formatter.GREEN_COLOR)) + msg := fmt.Sprintf("DB audit logging configuration is being updated for cluster %s", formatter.Colorize(clusterName, formatter.GREEN_COLOR)) if viper.GetBool("wait") { returnStatus, err := authApi.WaitForTaskCompletion(clusterId, ybmclient.ENTITYTYPEENUM_CLUSTER, ybmclient.TASKTYPEENUM_EDIT_DATABASE_AUDIT_LOGGING, []string{"FAILED", "SUCCEEDED"}, msg) @@ -170,7 +168,7 @@ var updateDbAuditLogsExporterCmd = &cobra.Command{ if returnStatus != "SUCCEEDED" { logrus.Fatalf("Operation failed with error: %s", returnStatus) } - fmt.Printf("DB audit logging configuration %v has been updated on the cluster %v\n", formatter.Colorize(dbAuditLogConfigId, formatter.GREEN_COLOR), formatter.Colorize(clusterName, formatter.GREEN_COLOR)) + fmt.Printf("DB audit logging configuration has been updated for the cluster %v\n", formatter.Colorize(clusterName, formatter.GREEN_COLOR)) respC, r, err := authApi.ListDbAuditExporterConfig(clusterId).Execute() if err != nil { @@ -191,10 +189,10 @@ var updateDbAuditLogsExporterCmd = &cobra.Command{ }, } -var listDbAuditLogsExporterCmd = &cobra.Command{ - Use: "list", - Short: "List DB Audit Logs Export Config", - Long: "List DB Audit Logs Export Config", +var describeDbAuditLoggingCmd = &cobra.Command{ + Use: "describe", + Short: "Describe Database Audit Logging configuration", + Long: "Describe Database Audit Logging configuration", Run: func(cmd *cobra.Command, args []string) { authApi, err := ybmAuthClient.NewAuthApiClient() if err != nil { @@ -230,14 +228,14 @@ var listDbAuditLogsExporterCmd = &cobra.Command{ }, } -var removeDbAuditLogsExporterCmd = &cobra.Command{ - Use: "unassign", - Short: "Unassign DB Audit Logs Export Config", - Long: "Unassign DB Audit Logs Export Config", +var disableDbAuditLoggingCmd = &cobra.Command{ + Use: "disable", + Short: "Disable Database Audit Logging", + Long: "Disable Database Audit Logging, if enabled", PreRun: func(cmd *cobra.Command, args []string) { viper.BindPFlag("force", cmd.Flags().Lookup("force")) clusterName, _ := cmd.Flags().GetString("cluster-name") - err := util.ConfirmCommand(fmt.Sprintf("Are you sure you want to unassign DB audit config from cluster: %s", clusterName), viper.GetBool("force")) + err := util.ConfirmCommand(fmt.Sprintf("Are you sure you want to disable DB audit logging for cluster: %s", clusterName), viper.GetBool("force")) if err != nil { logrus.Fatal(err) } @@ -265,7 +263,7 @@ var removeDbAuditLogsExporterCmd = &cobra.Command{ logrus.Fatalf(ybmAuthClient.GetApiErrorDetails(err)) } - msg := fmt.Sprintf("Request submitted to remove Db Audit Logging %s\n", formatter.Colorize(exportConfigId, formatter.GREEN_COLOR)) + msg := fmt.Sprintf("DB Audit Logging is being disabled for cluster %s\n", formatter.Colorize(clusterName, formatter.GREEN_COLOR)) if viper.GetBool("wait") { returnStatus, err := authApi.WaitForTaskCompletion(clusterId, ybmclient.ENTITYTYPEENUM_CLUSTER, ybmclient.TASKTYPEENUM_DISABLE_DATABASE_AUDIT_LOGGING, []string{"FAILED", "SUCCEEDED"}, msg) @@ -275,7 +273,7 @@ var removeDbAuditLogsExporterCmd = &cobra.Command{ if returnStatus != "SUCCEEDED" { logrus.Fatalf("Operation failed with error: %s", returnStatus) } - fmt.Printf("DB audit logging %v has been removed from the cluster %v\n", formatter.Colorize(exportConfigId, formatter.GREEN_COLOR), formatter.Colorize(clusterName, formatter.GREEN_COLOR)) + fmt.Printf("DB audit logging has been disabled for the cluster %v\n", formatter.Colorize(clusterName, formatter.GREEN_COLOR)) return } else { fmt.Println(msg) @@ -284,46 +282,46 @@ var removeDbAuditLogsExporterCmd = &cobra.Command{ } func init() { - DbAuditLogsExporterCmd.AddCommand(assignDbAuditLogsExporterCmd) - assignDbAuditLogsExporterCmd.Flags().SortFlags = false - assignDbAuditLogsExporterCmd.Flags().String("integration-name", "", "[REQUIRED] Name of the Integration") - assignDbAuditLogsExporterCmd.MarkFlagRequired("integration-name") - assignDbAuditLogsExporterCmd.Flags().StringToString("ysql-config", nil, `[REQUIRED] The ysql config to setup DB auditting + DbAuditLoggingCmd.AddCommand(enableDbAuditLoggingCmd) + enableDbAuditLoggingCmd.Flags().SortFlags = false + enableDbAuditLoggingCmd.Flags().String("integration-name", "", "[REQUIRED] Name of the Integration") + enableDbAuditLoggingCmd.MarkFlagRequired("integration-name") + enableDbAuditLoggingCmd.Flags().StringToString("ysql-config", nil, `[REQUIRED] The ysql config to setup DB auditting Please provide key value pairs as follows: log_catalog=,log_level=,log_client=,log_parameter=, log_relation=,log_statement_once=`) - assignDbAuditLogsExporterCmd.MarkFlagRequired("ysql-config") - assignDbAuditLogsExporterCmd.Flags().String("statement_classes", "", `[REQUIRED] The ysql config statement classes + enableDbAuditLoggingCmd.MarkFlagRequired("ysql-config") + enableDbAuditLoggingCmd.Flags().String("statement_classes", "", `[REQUIRED] The ysql config statement classes Please provide key value pairs as follows: statement_classes=READ,WRITE,MISC`) - assignDbAuditLogsExporterCmd.MarkFlagRequired("statement_classes") - assignDbAuditLogsExporterCmd.Flags().String("cluster-name", "", "[REQUIRED] The cluster name to assign DB auditting") - assignDbAuditLogsExporterCmd.MarkFlagRequired("cluster-name") - - DbAuditLogsExporterCmd.AddCommand(listDbAuditLogsExporterCmd) - listDbAuditLogsExporterCmd.Flags().SortFlags = false - listDbAuditLogsExporterCmd.Flags().String("cluster-name", "", "[REQUIRED] The cluster name to list DB audit export config") - listDbAuditLogsExporterCmd.MarkFlagRequired("cluster-name") - - DbAuditLogsExporterCmd.AddCommand(updateDbAuditLogsExporterCmd) - updateDbAuditLogsExporterCmd.Flags().SortFlags = false - updateDbAuditLogsExporterCmd.Flags().String("integration-name", "", "[REQUIRED] Name of the Integration") - updateDbAuditLogsExporterCmd.MarkFlagRequired("integration-name") - updateDbAuditLogsExporterCmd.Flags().StringToString("ysql-config", nil, `The ysql config to setup DB auditting + enableDbAuditLoggingCmd.MarkFlagRequired("statement_classes") + enableDbAuditLoggingCmd.Flags().String("cluster-name", "", "[REQUIRED] The cluster name to assign DB auditting") + enableDbAuditLoggingCmd.MarkFlagRequired("cluster-name") + + DbAuditLoggingCmd.AddCommand(describeDbAuditLoggingCmd) + describeDbAuditLoggingCmd.Flags().SortFlags = false + describeDbAuditLoggingCmd.Flags().String("cluster-name", "", "[REQUIRED] The cluster name to list DB audit export config") + describeDbAuditLoggingCmd.MarkFlagRequired("cluster-name") + + DbAuditLoggingCmd.AddCommand(updateDbAuditLoggingCmd) + updateDbAuditLoggingCmd.Flags().SortFlags = false + updateDbAuditLoggingCmd.Flags().String("integration-name", "", "[REQUIRED] Name of the Integration") + updateDbAuditLoggingCmd.MarkFlagRequired("integration-name") + updateDbAuditLoggingCmd.Flags().StringToString("ysql-config", nil, `The ysql config to setup DB auditting Please provide key value pairs as follows: log_catalog=,log_level=,log_client=,log_parameter=, log_relation=,log_statement_once=`) - updateDbAuditLogsExporterCmd.Flags().String("statement_classes", "", `The ysql config statement classes + updateDbAuditLoggingCmd.Flags().String("statement_classes", "", `The ysql config statement classes Please provide key value pairs as follows: statement_classes=READ,WRITE,MISC`) - updateDbAuditLogsExporterCmd.Flags().String("cluster-name", "", "[REQUIRED] The cluster name to assign DB auditting") - updateDbAuditLogsExporterCmd.MarkFlagRequired("cluster-name") - - DbAuditLogsExporterCmd.AddCommand(removeDbAuditLogsExporterCmd) - removeDbAuditLogsExporterCmd.Flags().SortFlags = false - removeDbAuditLogsExporterCmd.Flags().String("cluster-name", "", "[REQUIRED] The cluster name to assign DB auditting") - removeDbAuditLogsExporterCmd.MarkFlagRequired("cluster-name") - removeDbAuditLogsExporterCmd.Flags().BoolP("force", "f", false, "Bypass the prompt for non-interactive usage") + updateDbAuditLoggingCmd.Flags().String("cluster-name", "", "[REQUIRED] The cluster name to assign DB auditting") + updateDbAuditLoggingCmd.MarkFlagRequired("cluster-name") + + DbAuditLoggingCmd.AddCommand(disableDbAuditLoggingCmd) + disableDbAuditLoggingCmd.Flags().SortFlags = false + disableDbAuditLoggingCmd.Flags().String("cluster-name", "", "[REQUIRED] The cluster name to assign DB auditting") + disableDbAuditLoggingCmd.MarkFlagRequired("cluster-name") + disableDbAuditLoggingCmd.Flags().BoolP("force", "f", false, "Bypass the prompt for non-interactive usage") } func getIntegrationIdFromName(integrationName string, authApi *ybmAuthClient.AuthApiClient) (string, error) { @@ -335,7 +333,7 @@ func getIntegrationIdFromName(integrationName string, authApi *ybmAuthClient.Aut integrationData := integration.GetData() if len(integrationData) == 0 { - return "", fmt.Errorf("No integrations found with given name") + return "", fmt.Errorf("no integrations found with name: %s%s", integrationName, "\n") } return integrationData[0].GetInfo().Id, nil diff --git a/cmd/cluster/cluster.go b/cmd/cluster/cluster.go index 88b48ab..839002e 100644 --- a/cmd/cluster/cluster.go +++ b/cmd/cluster/cluster.go @@ -17,6 +17,7 @@ package cluster import ( "github.com/spf13/cobra" + audit_log_exporter "github.com/yugabyte/ybm-cli/cmd/cluster/audit-log-exporter" "github.com/yugabyte/ybm-cli/cmd/cluster/cert" connectionpooling "github.com/yugabyte/ybm-cli/cmd/cluster/connection-pooling" encryption "github.com/yugabyte/ybm-cli/cmd/cluster/encryption" @@ -46,6 +47,10 @@ func init() { log_exporter.DbQueryLoggingCmd.PersistentFlags().StringVarP(&log_exporter.ClusterName, "cluster-name", "c", "", "[REQUIRED] The name of the cluster.") log_exporter.DbQueryLoggingCmd.MarkPersistentFlagRequired("cluster-name") + util.AddCommandIfFeatureFlag(ClusterCmd, audit_log_exporter.DbAuditLoggingCmd, util.DB_AUDIT_LOGGING) + audit_log_exporter.DbAuditLoggingCmd.PersistentFlags().StringVarP(&audit_log_exporter.ClusterName, "cluster-name", "c", "", "[REQUIRED] The name of the cluster.") + audit_log_exporter.DbAuditLoggingCmd.MarkPersistentFlagRequired("cluster-name") + ClusterCmd.AddCommand(network.NetworkCmd) network.NetworkCmd.PersistentFlags().StringVarP(&network.ClusterName, "cluster-name", "c", "", "[REQUIRED] The name of the cluster.") network.NetworkCmd.MarkPersistentFlagRequired("cluster-name") diff --git a/cmd/cluster/log-exporter/query_log_exporter.go b/cmd/cluster/log-exporter/query_log_exporter.go index f9a673a..7408552 100644 --- a/cmd/cluster/log-exporter/query_log_exporter.go +++ b/cmd/cluster/log-exporter/query_log_exporter.go @@ -75,7 +75,7 @@ var enableDbQueryLoggingCmd = &cobra.Command{ logrus.Fatalf(ybmAuthClient.GetApiErrorDetails(err)) } - msg := fmt.Sprintf("The db query logging for cluster %s is being enabled", clusterName) + msg := fmt.Sprintf("DB query logging is being enabled for cluster %s", clusterName) if viper.GetBool("wait") { waitForDbLoggingTaskCompletion(clusterId, ybmclient.TASKTYPEENUM_ENABLE_DATABASE_QUERY_LOGGING, msg, authApi) fmt.Printf("DB query logging has been enabled for the cluster %v\n", formatter.Colorize(clusterName, formatter.GREEN_COLOR)) @@ -155,7 +155,7 @@ var disableLogExporterCmd = &cobra.Command{ logrus.Fatalf(ybmAuthClient.GetApiErrorDetails(err)) } - msg := fmt.Sprintf("The db query logging for cluster %s is being disabled", clusterName) + msg := fmt.Sprintf("DB query logging is being disabled for cluster %s", clusterName) if viper.GetBool("wait") { waitForDbLoggingTaskCompletion(clusterId, ybmclient.TASKTYPEENUM_DISABLE_DATABASE_QUERY_LOGGING, msg, authApi) fmt.Printf("DB query logging has been disabled for the cluster %v\n", formatter.Colorize(clusterName, formatter.GREEN_COLOR)) @@ -222,10 +222,10 @@ var updateLogExporterConfigCmd = &cobra.Command{ dqlConfig := pgLogExporterConfigResponse.Data - msg := fmt.Sprintf("The db query logging config for cluster %s is being updated", clusterName) + msg := fmt.Sprintf("The db query logging configuration is being updated for cluster %s", clusterName) if viper.GetBool("wait") { waitForDbLoggingTaskCompletion(clusterId, ybmclient.TASKTYPEENUM_EDIT_DATABASE_QUERY_LOGGING, msg, authApi) - fmt.Printf("DB query logging config has been updated for the cluster %v\n", formatter.Colorize(clusterName, formatter.GREEN_COLOR)) + fmt.Printf("DB query logging configuration has been updated for the cluster %v\n", formatter.Colorize(clusterName, formatter.GREEN_COLOR)) dqlConfig = *getDbLoggingConfig(clusterId, authApi) } else { diff --git a/cmd/db_audit_logs_exporter_test.go b/cmd/db_audit_logs_exporter_test.go index 84238a8..eedc993 100644 --- a/cmd/db_audit_logs_exporter_test.go +++ b/cmd/db_audit_logs_exporter_test.go @@ -29,7 +29,7 @@ import ( openapi "github.com/yugabyte/yugabytedb-managed-go-client-internal" ) -var _ = Describe("Db Audit", func() { +var _ = Describe("DB Audit Logging", func() { var ( server *ghttp.Server @@ -51,7 +51,7 @@ var _ = Describe("Db Audit", func() { Expect(err).ToNot(HaveOccurred()) os.Setenv("YBM_HOST", fmt.Sprintf("http://%s", server.Addr())) os.Setenv("YBM_APIKEY", "test-token") - os.Setenv("YBM_FF_DB_AUDIT_LOGS", "true") + os.Setenv("YBM_FF_DB_AUDIT_LOGGING", "true") statusCode = 200 err = loadJson("./test/fixtures/list-clusters.json", &responseListClusters) Expect(err).ToNot(HaveOccurred()) @@ -63,8 +63,8 @@ var _ = Describe("Db Audit", func() { ) }) - Context("When associating DB Audit config", func() { - It("should associate cluster with DB Audit", func() { + Context("When enabling DB Audit logging", func() { + It("should enable DB Audit Logging successfully on cluster", func() { statusCode = 200 err := loadJson("./test/fixtures/list-telemetry-provider.json", &responseIntegrationList) Expect(err).ToNot(HaveOccurred()) @@ -82,11 +82,11 @@ var _ = Describe("Db Audit", func() { ghttp.RespondWithJSONEncodedPtr(&statusCode, responseDbAudit), ), ) - cmd := exec.Command(compiledCLIPath, "db-audit-logs-exporter", "assign", "--cluster-name", "stunning-sole", "--integration-name", "datadog-tp", "--ysql-config", "log_catalog=true,log_client=true,log_level=NOTICE,log_parameter=false,log_statement_once=false,log_relation=false", "--statement_classes", "READ,WRITE") + cmd := exec.Command(compiledCLIPath, "cluster", "db-audit-logging", "enable", "--cluster-name", "stunning-sole", "--integration-name", "datadog-tp", "--ysql-config", "log_catalog=true,log_client=true,log_level=NOTICE,log_parameter=false,log_statement_once=false,log_relation=false", "--statement_classes", "READ,WRITE") session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter) Expect(err).NotTo(HaveOccurred()) session.Wait(2) - Expect(session.Out).Should(gbytes.Say(`The db audit exporter config 9e3fabbc-849c-4a77-bdb2-9422e712e7dc is being created + Expect(session.Out).Should(gbytes.Say(`Db audit logging is being enabled for cluster stunning-sole ID Date Created Cluster ID Integration ID State Ysql Config 9e3fabbc-849c-4a77-bdb2-9422e712e7dc 2024-02-27T06:30:51.304Z 5f80730f-ba3f-4f7e-8c01-f8fa4c90dad8 7c07c103-e3b2-48b6-ac30-764e9b5275e1 ACTIVE {\"log_settings\":{\"log_catalog\":true,\"log_client\":true,\"log_level\":\"LOG\",\"log_parameter\":false,\"log_relation\":false,\"log_statement_once\":false},\"statement_classes\":\[\"READ\",\"WRITE\"]}`)) session.Kill() @@ -109,7 +109,7 @@ ID Date Created Cluster ID ghttp.RespondWithJSONEncodedPtr(&statusCode, responseDbAudit), ), ) - cmd := exec.Command(compiledCLIPath, "db-audit-logs-exporter", "assign") + cmd := exec.Command(compiledCLIPath, "cluster", "db-audit-logging", "enable") session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter) Expect(err).NotTo(HaveOccurred()) session.Wait(2) @@ -134,7 +134,7 @@ ID Date Created Cluster ID ghttp.RespondWithJSONEncodedPtr(&statusCode, responseDbAudit), ), ) - cmd := exec.Command(compiledCLIPath, "db-audit-logs-exporter", "assign", "--cluster-name", "stunning-sole", "--integration-name", "datadog-tp", "--ysql-config", "log_catalog=true,log_client=true,log_level=NOTICE,log_parameter=false,log_relation=false", "--statement_classes", "READ,WRITE") + cmd := exec.Command(compiledCLIPath, "cluster", "db-audit-logging", "enable", "--cluster-name", "stunning-sole", "--integration-name", "datadog-tp", "--ysql-config", "log_catalog=true,log_client=true,log_level=NOTICE,log_parameter=false,log_relation=false", "--statement_classes", "READ,WRITE") session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter) Expect(err).NotTo(HaveOccurred()) session.Wait(2) @@ -143,8 +143,8 @@ ID Date Created Cluster ID }) }) - Context("When listing db audit exporter config", func() { - It("should return the list of config", func() { + Context("When describing db audit logging configuration of a cluster", func() { + It("should return the db audit logging configuration of the cluster", func() { statusCode = 200 err := loadJson("./test/fixtures/list-db-audit.json", &responseDbAuditList) Expect(err).ToNot(HaveOccurred()) @@ -154,7 +154,7 @@ ID Date Created Cluster ID ghttp.RespondWithJSONEncodedPtr(&statusCode, responseDbAuditList), ), ) - cmd := exec.Command(compiledCLIPath, "db-audit-logs-exporter", "list", "--cluster-name", "stunning-sole") + cmd := exec.Command(compiledCLIPath, "cluster", "db-audit-logging", "describe", "--cluster-name", "stunning-sole") session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter) Expect(err).NotTo(HaveOccurred()) session.Wait(2) @@ -172,7 +172,7 @@ ID Date Created Cluster ID ghttp.RespondWithJSONEncodedPtr(&statusCode, responseIntegrationList), ), ) - cmd := exec.Command(compiledCLIPath, "db-audit-logs-exporter", "list") + cmd := exec.Command(compiledCLIPath, "cluster", "db-audit-logging", "describe") session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter) Expect(err).NotTo(HaveOccurred()) session.Wait(2) @@ -182,8 +182,8 @@ ID Date Created Cluster ID }) - Context("When removing db audit exporter config", func() { - It("should delete the config", func() { + Context("When disabling DB Audit Logging from a cluster", func() { + It("should disable db audit logging", func() { statusCode = 200 err := loadJson("./test/fixtures/list-db-audit.json", &responseDbAuditList) @@ -204,16 +204,16 @@ ID Date Created Cluster ID ), ) - cmd := exec.Command(compiledCLIPath, "db-audit-logs-exporter", "unassign", "--cluster-name", "stunning-sole", "--force") + cmd := exec.Command(compiledCLIPath, "cluster", "db-audit-logging", "disable", "--cluster-name", "stunning-sole", "--force") session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter) Expect(err).NotTo(HaveOccurred()) session.Wait(2) - Expect(session.Out).Should(gbytes.Say(`Request submitted to remove Db Audit Logging 9e3fabbc-849c-4a77-bdb2-9422e712e7dc`)) + Expect(session.Out).Should(gbytes.Say(`DB Audit Logging is being disabled for cluster stunning-sole`)) session.Kill() }) It("should return required field name and type when not set", func() { - cmd := exec.Command(compiledCLIPath, "db-audit-logs-exporter", "unassign", "--force") + cmd := exec.Command(compiledCLIPath, "cluster", "db-audit-logging", "disable", "--force") session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter) exec.Command(compiledCLIPath, "y") Expect(err).NotTo(HaveOccurred()) @@ -224,8 +224,8 @@ ID Date Created Cluster ID }) - Context("When updating DB Audit config for a cluster", func() { - It("should update cluster DB Audit config", func() { + Context("When updating DB Audit logging config for a cluster", func() { + It("should update cluster DB Audit logging config", func() { statusCode = 200 err := loadJson("./test/fixtures/list-telemetry-provider.json", &responseIntegrationList) @@ -254,17 +254,17 @@ ID Date Created Cluster ID ghttp.RespondWithJSONEncodedPtr(&statusCode, responseDbAudit), ), ) - cmd := exec.Command(compiledCLIPath, "db-audit-logs-exporter", "update", "--cluster-name", "stunning-sole", "--integration-name", "datadog-tp", "--ysql-config", "log_catalog=false,log_client=true,log_level=NOTICE,log_parameter=false,log_statement_once=false,log_relation=true", "--statement_classes", "READ,WRITE") + cmd := exec.Command(compiledCLIPath, "cluster", "db-audit-logging", "update", "--cluster-name", "stunning-sole", "--integration-name", "datadog-tp", "--ysql-config", "log_catalog=false,log_client=true,log_level=NOTICE,log_parameter=false,log_statement_once=false,log_relation=true", "--statement_classes", "READ,WRITE") session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter) Expect(err).NotTo(HaveOccurred()) session.Wait(2) - Expect(session.Out).Should(gbytes.Say(`The db audit exporter config 9e3fabbc-849c-4a77-bdb2-9422e712e7dc is being updated + Expect(session.Out).Should(gbytes.Say(`DB audit logging configuration is being updated for cluster stunning-sole ID Date Created Cluster ID Integration ID State Ysql Config 9e3fabbc-849c-4a77-bdb2-9422e712e7dc 2024-02-27T06:30:51.304Z 5f80730f-ba3f-4f7e-8c01-f8fa4c90dad8 7c07c103-e3b2-48b6-ac30-764e9b5275e1 ACTIVE {\"log_settings\":{\"log_catalog\":false,\"log_client\":true,\"log_level\":\"NOTICE\",\"log_parameter\":false,\"log_relation\":true,\"log_statement_once\":false},\"statement_classes\":\[\"READ\",\"WRITE\"]}`)) session.Kill() }) It("should return required field name and type when not set", func() { - cmd := exec.Command(compiledCLIPath, "db-audit-logs-exporter", "update") + cmd := exec.Command(compiledCLIPath, "cluster", "db-audit-logging", "update") session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter) Expect(err).NotTo(HaveOccurred()) session.Wait(2) @@ -281,7 +281,7 @@ ID Date Created Cluster ID ghttp.RespondWithJSONEncodedPtr(&statusCode, responseIntegrationList), ), ) - cmd := exec.Command(compiledCLIPath, "db-audit-logs-exporter", "update", "--cluster-name", "stunning-sole", "--integration-name", "datadog-tp", "--ysql-config", "log_catalog=true,log_client=true,log_level=NOTICE,log_parameter=false,log_relation=false", "--statement_classes", "READ,WRITE") + cmd := exec.Command(compiledCLIPath, "cluster", "db-audit-logging", "update", "--cluster-name", "stunning-sole", "--integration-name", "datadog-tp", "--ysql-config", "log_catalog=true,log_client=true,log_level=NOTICE,log_parameter=false,log_relation=false", "--statement_classes", "READ,WRITE") session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter) Expect(err).NotTo(HaveOccurred()) session.Wait(2) @@ -298,7 +298,7 @@ ID Date Created Cluster ID ghttp.RespondWithJSONEncodedPtr(&statusCode, responseIntegrationList), ), ) - cmd := exec.Command(compiledCLIPath, "db-audit-logs-exporter", "update", "--cluster-name", "stunning-sole", "--integration-name", "datadog-tp", "--ysql-config", "log_catalog=true,log_client=true,log_level=NOTICE,log_parameter=false,log_relation=false") + cmd := exec.Command(compiledCLIPath, "cluster", "db-audit-logging", "update", "--cluster-name", "stunning-sole", "--integration-name", "datadog-tp", "--ysql-config", "log_catalog=true,log_client=true,log_level=NOTICE,log_parameter=false,log_relation=false") session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter) Expect(err).NotTo(HaveOccurred()) session.Wait(2) diff --git a/cmd/root.go b/cmd/root.go index 226a37b..546d4bb 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -28,7 +28,6 @@ import ( "github.com/yugabyte/ybm-cli/cmd/backup" "github.com/yugabyte/ybm-cli/cmd/cdc" "github.com/yugabyte/ybm-cli/cmd/cluster" - "github.com/yugabyte/ybm-cli/cmd/db_audit_logs_exporter" "github.com/yugabyte/ybm-cli/cmd/dr" "github.com/yugabyte/ybm-cli/cmd/integration" "github.com/yugabyte/ybm-cli/cmd/metrics_exporter" @@ -140,7 +139,6 @@ func init() { rootCmd.AddCommand(metrics_exporter.MetricsExporterCmd) rootCmd.AddCommand(integration.IntegrationCmd) util.AddCommandIfFeatureFlag(rootCmd, dr.DrCmd, util.DR) - util.AddCommandIfFeatureFlag(rootCmd, db_audit_logs_exporter.DbAuditLogsExporterCmd, util.DB_AUDIT_LOGS) util.AddCommandIfFeatureFlag(rootCmd, tools.ToolsCmd, util.TOOLS) util.AddCommandIfFeatureFlag(rootCmd, cdc.CdcCmd, util.CDC) diff --git a/cmd/util/feature_flags.go b/cmd/util/feature_flags.go index 174622c..d25bc68 100644 --- a/cmd/util/feature_flags.go +++ b/cmd/util/feature_flags.go @@ -31,7 +31,7 @@ const ( TOOLS FeatureFlag = "TOOLS" AZURE_CIDR_ALLOWED FeatureFlag = "AZURE_CIDR_ALLOWED" ENTERPRISE_SECURITY FeatureFlag = "ENTERPRISE_SECURITY" - DB_AUDIT_LOGS FeatureFlag = "DB_AUDIT_LOGS" + DB_AUDIT_LOGGING FeatureFlag = "DB_AUDIT_LOGGING" PITR_CONFIG FeatureFlag = "PITR_CONFIG" CONNECTION_POOLING FeatureFlag = "CONNECTION_POOLING" GOOGLECLOUD_INTEGRATION FeatureFlag = "GOOGLECLOUD_INTEGRATION" diff --git a/go.mod b/go.mod index 838c92c..cb7eb6b 100644 --- a/go.mod +++ b/go.mod @@ -23,7 +23,7 @@ require ( github.com/spf13/cobra v1.8.0 github.com/spf13/viper v1.17.0 github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816 - github.com/yugabyte/yugabytedb-managed-go-client-internal v0.0.0-20241026194158-9358bc3fbd31 + github.com/yugabyte/yugabytedb-managed-go-client-internal v0.0.0-20241103123630-73a2876ea773 golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 golang.org/x/mod v0.20.0 golang.org/x/term v0.23.0 diff --git a/go.sum b/go.sum index c34c239..cf76fa4 100644 --- a/go.sum +++ b/go.sum @@ -282,8 +282,8 @@ github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8 github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816 h1:J6v8awz+me+xeb/cUTotKgceAYouhIB3pjzgRd6IlGk= github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816/go.mod h1:tzym/CEb5jnFI+Q0k4Qq3+LvRF4gO3E2pxS8fHP8jcA= -github.com/yugabyte/yugabytedb-managed-go-client-internal v0.0.0-20241026194158-9358bc3fbd31 h1:4YdZLlhG8hWPCjb9S7TIZ7THPtaLjgGDEdJnITO8IVU= -github.com/yugabyte/yugabytedb-managed-go-client-internal v0.0.0-20241026194158-9358bc3fbd31/go.mod h1:5vW0xIzIZw+1djkiWKx0qqNmqbRBSf4mjc4qw8lIMik= +github.com/yugabyte/yugabytedb-managed-go-client-internal v0.0.0-20241103123630-73a2876ea773 h1:t+n2/bsR3vGpFoPKjs0vlzErRcxlVR8YHBEZawlYSa0= +github.com/yugabyte/yugabytedb-managed-go-client-internal v0.0.0-20241103123630-73a2876ea773/go.mod h1:5vW0xIzIZw+1djkiWKx0qqNmqbRBSf4mjc4qw8lIMik= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= diff --git a/internal/formatter/dr.go b/internal/formatter/dr.go index 4d3407f..0013dfc 100644 --- a/internal/formatter/dr.go +++ b/internal/formatter/dr.go @@ -143,8 +143,8 @@ func (c *DrContext) Databases() string { } func (c *DrContext) State() string { - if v, ok := c.c.Info.GetStateOk(); ok { - return *v + if _, ok := c.c.Info.GetStateOk(); ok { + return string(*c.c.Info.State) } return "" }