diff --git a/sherlock/db/migrations/000102_add_banner_field_to_environments.down.sql b/sherlock/db/migrations/000102_add_banner_field_to_environments.down.sql new file mode 100644 index 00000000..fee3e60b --- /dev/null +++ b/sherlock/db/migrations/000102_add_banner_field_to_environments.down.sql @@ -0,0 +1,2 @@ +alter table environments + drop column if exists service_banner_bucket; diff --git a/sherlock/db/migrations/000102_add_banner_field_to_environments.up.sql b/sherlock/db/migrations/000102_add_banner_field_to_environments.up.sql new file mode 100644 index 00000000..5e2b10bd --- /dev/null +++ b/sherlock/db/migrations/000102_add_banner_field_to_environments.up.sql @@ -0,0 +1,2 @@ +alter table environments + add if not exists service_banner_bucket text; diff --git a/sherlock/docs/docs.go b/sherlock/docs/docs.go index 2506ac50..731499a8 100644 --- a/sherlock/docs/docs.go +++ b/sherlock/docs/docs.go @@ -5067,6 +5067,11 @@ const docTemplate = `{ "name": "requiresSuitability", "in": "query" }, + { + "type": "string", + "name": "serviceBannerBucket", + "in": "query" + }, { "type": "string", "description": "Required for dynamic environments", @@ -9356,6 +9361,9 @@ const docTemplate = `{ "requiresSuitability": { "type": "boolean" }, + "serviceBannerBucket": { + "type": "string" + }, "templateEnvironment": { "description": "Required for dynamic environments", "type": "string" @@ -9476,6 +9484,9 @@ const docTemplate = `{ "requiresSuitability": { "type": "boolean" }, + "serviceBannerBucket": { + "type": "string" + }, "templateEnvironment": { "description": "Required for dynamic environments", "type": "string" @@ -9567,6 +9578,9 @@ const docTemplate = `{ }, "requiresSuitability": { "type": "boolean" + }, + "serviceBannerBucket": { + "type": "string" } } }, diff --git a/sherlock/docs/swagger.json b/sherlock/docs/swagger.json index 88d5997a..b16b0235 100644 --- a/sherlock/docs/swagger.json +++ b/sherlock/docs/swagger.json @@ -5064,6 +5064,11 @@ "name": "requiresSuitability", "in": "query" }, + { + "type": "string", + "name": "serviceBannerBucket", + "in": "query" + }, { "type": "string", "description": "Required for dynamic environments", @@ -9353,6 +9358,9 @@ "requiresSuitability": { "type": "boolean" }, + "serviceBannerBucket": { + "type": "string" + }, "templateEnvironment": { "description": "Required for dynamic environments", "type": "string" @@ -9473,6 +9481,9 @@ "requiresSuitability": { "type": "boolean" }, + "serviceBannerBucket": { + "type": "string" + }, "templateEnvironment": { "description": "Required for dynamic environments", "type": "string" @@ -9564,6 +9575,9 @@ }, "requiresSuitability": { "type": "boolean" + }, + "serviceBannerBucket": { + "type": "string" } } }, diff --git a/sherlock/docs/swagger.yaml b/sherlock/docs/swagger.yaml index b1fd1cfc..f283b5ac 100644 --- a/sherlock/docs/swagger.yaml +++ b/sherlock/docs/swagger.yaml @@ -1111,6 +1111,8 @@ definitions: $ref: '#/definitions/sherlock.RoleV3' requiresSuitability: type: boolean + serviceBannerBucket: + type: string templateEnvironment: description: Required for dynamic environments type: string @@ -1209,6 +1211,8 @@ definitions: type: string requiresSuitability: type: boolean + serviceBannerBucket: + type: string templateEnvironment: description: Required for dynamic environments type: string @@ -1285,6 +1289,8 @@ definitions: type: string requiresSuitability: type: boolean + serviceBannerBucket: + type: string type: object sherlock.GitCommitV3: properties: @@ -5307,6 +5313,9 @@ paths: - in: query name: requiresSuitability type: boolean + - in: query + name: serviceBannerBucket + type: string - description: Required for dynamic environments in: query name: templateEnvironment diff --git a/sherlock/internal/api/sherlock/environments_v3.go b/sherlock/internal/api/sherlock/environments_v3.go index 03d49a14..620b6f6c 100644 --- a/sherlock/internal/api/sherlock/environments_v3.go +++ b/sherlock/internal/api/sherlock/environments_v3.go @@ -57,6 +57,7 @@ type EnvironmentV3Edit struct { OfflineScheduleEndTime *time.Time `json:"offlineScheduleEndTime,omitempty" form:"offlineScheduleEndTime" format:"date-time"` // Stored with timezone to determine day of the week OfflineScheduleEndWeekends *bool `json:"offlineScheduleEndWeekends,omitempty" form:"offlineScheduleEndWeekends"` EnableJanitor *bool `json:"enableJanitor,omitempty" form:"enableJanitor"` // If true, janitor resource cleanup will be enabled for this environment. BEEs default to template's value, templates default to true, and static/live environments default to false. + ServiceBannerBucket *string `json:"serviceBannerBucket" form:"serviceBannerBucket"` } func (e EnvironmentV3) toModel(db *gorm.DB) (models.Environment, error) { @@ -83,6 +84,7 @@ func (e EnvironmentV3) toModel(db *gorm.DB) (models.Environment, error) { OfflineScheduleEndWeekends: e.OfflineScheduleEndWeekends, PactIdentifier: e.PactIdentifier, EnableJanitor: e.EnableJanitor, + ServiceBannerBucket: e.ServiceBannerBucket, } if e.DeleteAfter != nil { if *e.DeleteAfter == "" { @@ -200,6 +202,7 @@ func environmentFromModel(model models.Environment) EnvironmentV3 { OfflineScheduleEndEnabled: model.OfflineScheduleEndEnabled, OfflineScheduleEndWeekends: model.OfflineScheduleEndWeekends, EnableJanitor: model.EnableJanitor, + ServiceBannerBucket: model.ServiceBannerBucket, }, }, } diff --git a/sherlock/internal/api/sherlock/environments_v3_test.go b/sherlock/internal/api/sherlock/environments_v3_test.go index ff4de637..93b48c0d 100644 --- a/sherlock/internal/api/sherlock/environments_v3_test.go +++ b/sherlock/internal/api/sherlock/environments_v3_test.go @@ -175,6 +175,7 @@ func (s *handlerSuite) TestEnvironmentV3_toModel() { OfflineScheduleEndTime: utils.PointerTo(now), OfflineScheduleEndWeekends: utils.PointerTo(true), EnableJanitor: utils.PointerTo(true), + ServiceBannerBucket: utils.PointerTo("firecloud-alerts-qa-bees"), }, }, }, @@ -215,6 +216,7 @@ func (s *handlerSuite) TestEnvironmentV3_toModel() { OfflineScheduleEndWeekends: utils.PointerTo(true), PactIdentifier: &pactUuid, EnableJanitor: utils.PointerTo(true), + ServiceBannerBucket: utils.PointerTo("firecloud-alerts-qa-bees"), }, }, { @@ -253,6 +255,7 @@ func (s *handlerSuite) TestEnvironmentV3_toModel() { OfflineScheduleEndTime: utils.PointerTo(now), OfflineScheduleEndWeekends: utils.PointerTo(true), EnableJanitor: utils.PointerTo(true), + ServiceBannerBucket: utils.PointerTo("firecloud-alerts-qa-bees"), }, }, }, @@ -292,6 +295,7 @@ func (s *handlerSuite) TestEnvironmentV3_toModel() { OfflineScheduleEndWeekends: utils.PointerTo(true), PactIdentifier: &pactUuid, EnableJanitor: utils.PointerTo(true), + ServiceBannerBucket: utils.PointerTo("firecloud-alerts-qa-bees"), }, }, } @@ -380,6 +384,7 @@ func Test_environmentFromModel(t *testing.T) { OfflineScheduleEndWeekends: utils.PointerTo(true), PactIdentifier: &pactUuid, EnableJanitor: utils.PointerTo(true), + ServiceBannerBucket: utils.PointerTo("firecloud-alerts-qa-bees"), }}, want: EnvironmentV3{ CommonFields: CommonFields{ @@ -423,6 +428,7 @@ func Test_environmentFromModel(t *testing.T) { OfflineScheduleEndTime: nowTimeParsedAgain, OfflineScheduleEndWeekends: utils.PointerTo(true), EnableJanitor: utils.PointerTo(true), + ServiceBannerBucket: utils.PointerTo("firecloud-alerts-qa-bees"), }, }, }, diff --git a/sherlock/internal/models/environment.go b/sherlock/internal/models/environment.go index e436cd8d..4242a4b1 100644 --- a/sherlock/internal/models/environment.go +++ b/sherlock/internal/models/environment.go @@ -53,6 +53,7 @@ type Environment struct { OfflineScheduleEndWeekends *bool PactIdentifier *uuid.UUID EnableJanitor *bool + ServiceBannerBucket *string } func (e *Environment) GetCiIdentifier() CiIdentifier { @@ -299,6 +300,10 @@ func (e *Environment) setCreationDefaults(tx *gorm.DB) error { } } } + + if e.ServiceBannerBucket == nil { + e.ServiceBannerBucket = template.ServiceBannerBucket + } } else { if e.ValuesName == "" { e.ValuesName = e.Name diff --git a/sherlock/internal/models/environment_test.go b/sherlock/internal/models/environment_test.go index 820d96ab..cb2fa417 100644 --- a/sherlock/internal/models/environment_test.go +++ b/sherlock/internal/models/environment_test.go @@ -456,3 +456,26 @@ func TestEnvironment_ArgoCdUrl(t *testing.T) { }) } } + +func (s *modelSuite) TestEnvironmentLiveServiceBannerDefaultUnpopulated() { + ddpAzureProd := s.TestData.Environment_DdpAzureProd() + ddpAsureDev := s.TestData.Environment_DdpAzureDev() + + s.Nil(ddpAsureDev.ServiceBannerBucket) + s.Nil(ddpAzureProd.ServiceBannerBucket) +} + +func (s *modelSuite) TestEnvironmentLiveServiceBannerPopulated() { + dev := s.TestData.Environment_Dev() + prod := s.TestData.Environment_Prod() + + s.Equal(*dev.ServiceBannerBucket, "firecloud-alerts-dev") + s.Equal(*prod.ServiceBannerBucket, "firecloud-alerts") +} + +func (s *modelSuite) TestEnvironmentBeeServiceBannerDefaultPopulated() { + swatTpl := s.TestData.Environment_Swatomation() + bee := s.TestData.Environment_Swatomation_TestBee() + + s.Equal(*bee.ServiceBannerBucket, *swatTpl.ServiceBannerBucket) +} diff --git a/sherlock/internal/models/test_data.go b/sherlock/internal/models/test_data.go index 1e81e3ef..78452569 100644 --- a/sherlock/internal/models/test_data.go +++ b/sherlock/internal/models/test_data.go @@ -793,6 +793,7 @@ func (td *testDataImpl) Environment_Prod() Environment { Description: utils.PointerTo("Terra's production environment"), PagerdutyIntegrationID: utils.PointerTo(td.PagerdutyIntegration_ManuallyTriggeredTerraIncident().ID), Offline: utils.PointerTo(false), + ServiceBannerBucket: utils.PointerTo("firecloud-alerts"), } td.h.SetSuitableTestUserForDB() td.create(&td.environment_prod) @@ -817,6 +818,7 @@ func (td *testDataImpl) Environment_Staging() Environment { PreventDeletion: utils.PointerTo(true), Description: utils.PointerTo("Terra's staging environment"), Offline: utils.PointerTo(false), + ServiceBannerBucket: utils.PointerTo("firecloud-alerts-staging"), } td.h.SetSuitableTestUserForDB() td.create(&td.environment_staging) @@ -841,6 +843,7 @@ func (td *testDataImpl) Environment_Dev() Environment { PreventDeletion: utils.PointerTo(true), Description: utils.PointerTo("Terra's development environment"), Offline: utils.PointerTo(false), + ServiceBannerBucket: utils.PointerTo("firecloud-alerts-dev"), } td.h.SetSuitableTestUserForDB() td.create(&td.environment_dev) @@ -865,6 +868,7 @@ func (td *testDataImpl) Environment_Swatomation() Environment { PreventDeletion: utils.PointerTo(true), Description: utils.PointerTo("The software-automation testing template, with all of Terra"), Offline: utils.PointerTo(false), + ServiceBannerBucket: utils.PointerTo("firecloud-alerts-qa-bees"), } // Config defines honeycomb as being auto-populated in template environments td.Chart_Honeycomb()