From acaa7e16fac5ea2cd5330c1f1e3c6127c0b40214 Mon Sep 17 00:00:00 2001 From: mdrakos Date: Thu, 21 Nov 2024 11:03:56 -0800 Subject: [PATCH] Make changes backwards compatible --- .../internal/server/generated/generated.go | 40 +++++++++---------- cmd/state-svc/schema/schema.graphqls | 2 +- .../cmdtree/exechandlers/notifier/notifier.go | 4 +- internal/constants/constants.go | 2 +- internal/graph/generated.go | 16 ++++---- pkg/platform/api/svc/request/notification.go | 2 +- test/integration/notification_int_test.go | 36 ++++++++--------- 7 files changed, 51 insertions(+), 51 deletions(-) diff --git a/cmd/state-svc/internal/server/generated/generated.go b/cmd/state-svc/internal/server/generated/generated.go index b290494161..9e2bbb7947 100644 --- a/cmd/state-svc/internal/server/generated/generated.go +++ b/cmd/state-svc/internal/server/generated/generated.go @@ -84,14 +84,14 @@ type ComplexityRoot struct { } NotificationInfo struct { - Condition func(childComplexity int) int - EndDate func(childComplexity int) int - ID func(childComplexity int) int - Interrupt func(childComplexity int) int - Notification func(childComplexity int) int - Placement func(childComplexity int) int - Repeat func(childComplexity int) int - StartDate func(childComplexity int) int + Condition func(childComplexity int) int + EndDate func(childComplexity int) int + ID func(childComplexity int) int + Interrupt func(childComplexity int) int + Message func(childComplexity int) int + Placement func(childComplexity int) int + Repeat func(childComplexity int) int + StartDate func(childComplexity int) int } Organization struct { @@ -323,12 +323,12 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.NotificationInfo.Interrupt(childComplexity), true - case "NotificationInfo.notification": - if e.complexity.NotificationInfo.Notification == nil { + case "NotificationInfo.message": + if e.complexity.NotificationInfo.Message == nil { break } - return e.complexity.NotificationInfo.Notification(childComplexity), true + return e.complexity.NotificationInfo.Message(childComplexity), true case "NotificationInfo.placement": if e.complexity.NotificationInfo.Placement == nil { @@ -753,7 +753,7 @@ enum NotificationPlacementType { type NotificationInfo { id: String! - notification: String! + message: String! condition: String! startDate: String! endDate: String! @@ -1853,8 +1853,8 @@ func (ec *executionContext) fieldContext_NotificationInfo_id(_ context.Context, return fc, nil } -func (ec *executionContext) _NotificationInfo_notification(ctx context.Context, field graphql.CollectedField, obj *graph.NotificationInfo) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_NotificationInfo_notification(ctx, field) +func (ec *executionContext) _NotificationInfo_message(ctx context.Context, field graphql.CollectedField, obj *graph.NotificationInfo) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_NotificationInfo_message(ctx, field) if err != nil { return graphql.Null } @@ -1867,7 +1867,7 @@ func (ec *executionContext) _NotificationInfo_notification(ctx context.Context, }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Notification, nil + return obj.Message, nil }) if err != nil { ec.Error(ctx, err) @@ -1884,7 +1884,7 @@ func (ec *executionContext) _NotificationInfo_notification(ctx context.Context, return ec.marshalNString2string(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_NotificationInfo_notification(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_NotificationInfo_message(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ Object: "NotificationInfo", Field: field, @@ -2737,8 +2737,8 @@ func (ec *executionContext) fieldContext_Query_checkNotifications(ctx context.Co switch field.Name { case "id": return ec.fieldContext_NotificationInfo_id(ctx, field) - case "notification": - return ec.fieldContext_NotificationInfo_notification(ctx, field) + case "message": + return ec.fieldContext_NotificationInfo_message(ctx, field) case "condition": return ec.fieldContext_NotificationInfo_condition(ctx, field) case "startDate": @@ -5841,8 +5841,8 @@ func (ec *executionContext) _NotificationInfo(ctx context.Context, sel ast.Selec if out.Values[i] == graphql.Null { out.Invalids++ } - case "notification": - out.Values[i] = ec._NotificationInfo_notification(ctx, field, obj) + case "message": + out.Values[i] = ec._NotificationInfo_message(ctx, field, obj) if out.Values[i] == graphql.Null { out.Invalids++ } diff --git a/cmd/state-svc/schema/schema.graphqls b/cmd/state-svc/schema/schema.graphqls index 094c3b829d..606eb5cfd3 100644 --- a/cmd/state-svc/schema/schema.graphqls +++ b/cmd/state-svc/schema/schema.graphqls @@ -53,7 +53,7 @@ enum NotificationPlacementType { type NotificationInfo { id: String! - notification: String! + message: String! condition: String! startDate: String! endDate: String! diff --git a/cmd/state/internal/cmdtree/exechandlers/notifier/notifier.go b/cmd/state/internal/cmdtree/exechandlers/notifier/notifier.go index 30927dc40c..63a8083864 100644 --- a/cmd/state/internal/cmdtree/exechandlers/notifier/notifier.go +++ b/cmd/state/internal/cmdtree/exechandlers/notifier/notifier.go @@ -90,8 +90,8 @@ func (m *Notifier) PrintByPlacement(placement graph.NotificationPlacementType) e m.out.Notice("") // Line break after } - logging.Debug("Printing notification: %s, %s", notification.ID, notification.Notification) - m.out.Notice(notification.Notification) + logging.Debug("Printing notification: %s, %s", notification.ID, notification.Message) + m.out.Notice(notification.Message) if placement == graph.NotificationPlacementTypeBeforeCmd { m.out.Notice("") // Line break before diff --git a/internal/constants/constants.go b/internal/constants/constants.go index 09e979157d..c5130ab6c7 100644 --- a/internal/constants/constants.go +++ b/internal/constants/constants.go @@ -265,7 +265,7 @@ const VulnerabilitiesAPIPath = "/v13s/v1/graphql" const HasuraInventoryAPIPath = "/sv/hasura-inventory/v1/graphql" // NotificationsInfoURL is the URL we check against to see what versions are deprecated -const NotificationsInfoURL = "https://state-tool.s3.amazonaws.com/notifications.json" +const NotificationsInfoURL = "https://state-tool.s3.amazonaws.com/messages.json" // DateFormatUser is the date format we use when communicating with the end-user const DateFormatUser = "January 02, 2006" diff --git a/internal/graph/generated.go b/internal/graph/generated.go index 482806f028..f61461ffa3 100644 --- a/internal/graph/generated.go +++ b/internal/graph/generated.go @@ -44,14 +44,14 @@ type Mutation struct { } type NotificationInfo struct { - ID string `json:"id"` - Notification string `json:"notification"` - Condition string `json:"condition"` - StartDate string `json:"startDate"` - EndDate string `json:"endDate"` - Repeat NotificationRepeatType `json:"repeat"` - Interrupt NotificationInterruptType `json:"interrupt"` - Placement NotificationPlacementType `json:"placement"` + ID string `json:"id"` + Message string `json:"message"` + Condition string `json:"condition"` + StartDate string `json:"startDate"` + EndDate string `json:"endDate"` + Repeat NotificationRepeatType `json:"repeat"` + Interrupt NotificationInterruptType `json:"interrupt"` + Placement NotificationPlacementType `json:"placement"` } type Organization struct { diff --git a/pkg/platform/api/svc/request/notification.go b/pkg/platform/api/svc/request/notification.go index a4983960ac..bc5cd097f0 100644 --- a/pkg/platform/api/svc/request/notification.go +++ b/pkg/platform/api/svc/request/notification.go @@ -16,7 +16,7 @@ func (m *NotificationRequest) Query() string { return `query($command: String!, $flags: [String!]!) { checkNotifications(command: $command, flags: $flags) { id - notification + message interrupt placement } diff --git a/test/integration/notification_int_test.go b/test/integration/notification_int_test.go index 4e9f2f8f4c..9889932cdc 100644 --- a/test/integration/notification_int_test.go +++ b/test/integration/notification_int_test.go @@ -42,7 +42,7 @@ func (suite *NotificationIntegrationTestSuite) TestNotification_Basic() { "Defaults", `[{ "ID": "simple", - "Notification": "This is a [NOTICE]simple[/RESET] notification" + "Message": "This is a [NOTICE]simple[/RESET] notification" }]`, false, true, @@ -51,7 +51,7 @@ func (suite *NotificationIntegrationTestSuite) TestNotification_Basic() { "Repeat Hourly", `[{ "ID": "simple", - "Notification": "This is a [NOTICE]simple[/RESET] notification", + "Message": "This is a [NOTICE]simple[/RESET] notification", "Repeat": "Hourly" }]`, false, @@ -61,7 +61,7 @@ func (suite *NotificationIntegrationTestSuite) TestNotification_Basic() { "Repeat Constantly", `[{ "ID": "simple", - "Notification": "This is a [NOTICE]simple[/RESET] notification", + "Message": "This is a [NOTICE]simple[/RESET] notification", "Repeat": "Constantly" }]`, true, @@ -71,7 +71,7 @@ func (suite *NotificationIntegrationTestSuite) TestNotification_Basic() { "Within Date Range", fmt.Sprintf(`[{ "ID": "simple", - "Notification": "This is a [NOTICE]simple[/RESET] notification", + "Message": "This is a [NOTICE]simple[/RESET] notification", "StartDate": "%s", "EndDate": "%s" }]`, @@ -84,7 +84,7 @@ func (suite *NotificationIntegrationTestSuite) TestNotification_Basic() { "Outside Date Range", fmt.Sprintf(`[{ "ID": "simple", - "Notification": "This is a [NOTICE]simple[/RESET] notification", + "Message": "This is a [NOTICE]simple[/RESET] notification", "StartDate": "%s", "EndDate": "%s" }]`, @@ -97,7 +97,7 @@ func (suite *NotificationIntegrationTestSuite) TestNotification_Basic() { "Only Start Date - Inside Range", fmt.Sprintf(`[{ "ID": "simple", - "Notification": "This is a [NOTICE]simple[/RESET] notification", + "Message": "This is a [NOTICE]simple[/RESET] notification", "StartDate": "%s" }]`, time.Now().Add(-1*time.Hour).Format(time.RFC3339)), @@ -108,7 +108,7 @@ func (suite *NotificationIntegrationTestSuite) TestNotification_Basic() { "Only End Date - Inside Range", fmt.Sprintf(`[{ "ID": "simple", - "Notification": "This is a [NOTICE]simple[/RESET] notification", + "Message": "This is a [NOTICE]simple[/RESET] notification", "EndDate": "%s" }]`, time.Now().Add(1*time.Hour).Format(time.RFC3339)), @@ -119,7 +119,7 @@ func (suite *NotificationIntegrationTestSuite) TestNotification_Basic() { "Outside Date Range - Future", fmt.Sprintf(`[{ "ID": "simple", - "Notification": "This is a [NOTICE]simple[/RESET] notification", + "Message": "This is a [NOTICE]simple[/RESET] notification", "StartDate": "%s", "EndDate": "%s" }]`, @@ -132,7 +132,7 @@ func (suite *NotificationIntegrationTestSuite) TestNotification_Basic() { "Outside Date Range - Past", fmt.Sprintf(`[{ "ID": "simple", - "Notification": "This is a [NOTICE]simple[/RESET] notification", + "Message": "This is a [NOTICE]simple[/RESET] notification", "StartDate": "%s", "EndDate": "%s" }]`, @@ -145,7 +145,7 @@ func (suite *NotificationIntegrationTestSuite) TestNotification_Basic() { "Only Start Date - Outside Range", fmt.Sprintf(`[{ "ID": "simple", - "Notification": "This is a [NOTICE]simple[/RESET] notification", + "Message": "This is a [NOTICE]simple[/RESET] notification", "StartDate": "%s" }]`, time.Now().Add(1*time.Hour).Format(time.RFC3339)), @@ -156,7 +156,7 @@ func (suite *NotificationIntegrationTestSuite) TestNotification_Basic() { "Only End Date - Outside Range", fmt.Sprintf(`[{ "ID": "simple", - "Notification": "This is a [NOTICE]simple[/RESET] notification", + "Message": "This is a [NOTICE]simple[/RESET] notification", "EndDate": "%s" }]`, time.Now().Add(-1*time.Hour).Format(time.RFC3339)), @@ -169,7 +169,7 @@ func (suite *NotificationIntegrationTestSuite) TestNotification_Basic() { ts := e2e.New(suite.T(), false) defer ts.Close() - msgFile, err := fileutils.WriteTempFileToDir(ts.Dirs.Work, "notifications.json", []byte(tt.MessageJson), 0755) + msgFile, err := fileutils.WriteTempFileToDir(ts.Dirs.Work, "messages.json", []byte(tt.MessageJson), 0755) suite.Require().NoError(err) cp := ts.SpawnWithOpts(e2e.OptArgs("--version"), e2e.OptAppendEnv(constants.NotificationsOverrideEnvVarName+"="+msgFile)) @@ -201,10 +201,10 @@ func (suite *NotificationIntegrationTestSuite) TestNotification_Basic_PlacementA ts := e2e.New(suite.T(), false) defer ts.Close() - msgFile, err := fileutils.WriteTempFileToDir(ts.Dirs.Work, "notifications.json", []byte(fmt.Sprintf(`[ + msgFile, err := fileutils.WriteTempFileToDir(ts.Dirs.Work, "messages.json", []byte(fmt.Sprintf(`[ { "ID": "simple", - "Notification": "This is a [NOTICE]simple[/RESET] notification", + "Message": "This is a [NOTICE]simple[/RESET] notification", "Placement": "%s" } ]`, graph.NotificationPlacementTypeAfterCmd)), 0755) @@ -221,10 +221,10 @@ func (suite *NotificationIntegrationTestSuite) TestNotification_Basic_InterruptP ts := e2e.New(suite.T(), false) defer ts.Close() - msgFile, err := fileutils.WriteTempFileToDir(ts.Dirs.Work, "notifications.json", []byte(fmt.Sprintf(`[ + msgFile, err := fileutils.WriteTempFileToDir(ts.Dirs.Work, "messages.json", []byte(fmt.Sprintf(`[ { "ID": "simple", - "Notification": "This is a [NOTICE]simple[/RESET] notification", + "Message": "This is a [NOTICE]simple[/RESET] notification", "Repeat": "Constantly", "Interrupt": "%s" } @@ -253,10 +253,10 @@ func (suite *NotificationIntegrationTestSuite) TestNotification_Basic_InterruptE ts := e2e.New(suite.T(), false) defer ts.Close() - msgFile, err := fileutils.WriteTempFileToDir(ts.Dirs.Work, "notifications.json", []byte(fmt.Sprintf(`[ + msgFile, err := fileutils.WriteTempFileToDir(ts.Dirs.Work, "messages.json", []byte(fmt.Sprintf(`[ { "ID": "simple", - "Notification": "This is a [NOTICE]simple[/RESET] notification", + "Message": "This is a [NOTICE]simple[/RESET] notification", "Interrupt": "%s" } ]`, graph.NotificationInterruptTypeExit)), 0755)