Skip to content

Commit

Permalink
Add service banner bucket field to environments
Browse files Browse the repository at this point in the history
  • Loading branch information
em-may committed Nov 19, 2024
1 parent c2b1035 commit dcd6dec
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table environments
drop column if exists service_banner_bucket;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table environments
add if not exists service_banner_bucket text;
14 changes: 14 additions & 0 deletions sherlock/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5067,6 +5067,11 @@ const docTemplate = `{
"name": "requiresSuitability",
"in": "query"
},
{
"type": "string",
"name": "serviceBannerBucket",
"in": "query"
},
{
"type": "string",
"description": "Required for dynamic environments",
Expand Down Expand Up @@ -9356,6 +9361,9 @@ const docTemplate = `{
"requiresSuitability": {
"type": "boolean"
},
"serviceBannerBucket": {
"type": "string"
},
"templateEnvironment": {
"description": "Required for dynamic environments",
"type": "string"
Expand Down Expand Up @@ -9476,6 +9484,9 @@ const docTemplate = `{
"requiresSuitability": {
"type": "boolean"
},
"serviceBannerBucket": {
"type": "string"
},
"templateEnvironment": {
"description": "Required for dynamic environments",
"type": "string"
Expand Down Expand Up @@ -9567,6 +9578,9 @@ const docTemplate = `{
},
"requiresSuitability": {
"type": "boolean"
},
"serviceBannerBucket": {
"type": "string"
}
}
},
Expand Down
14 changes: 14 additions & 0 deletions sherlock/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -5064,6 +5064,11 @@
"name": "requiresSuitability",
"in": "query"
},
{
"type": "string",
"name": "serviceBannerBucket",
"in": "query"
},
{
"type": "string",
"description": "Required for dynamic environments",
Expand Down Expand Up @@ -9353,6 +9358,9 @@
"requiresSuitability": {
"type": "boolean"
},
"serviceBannerBucket": {
"type": "string"
},
"templateEnvironment": {
"description": "Required for dynamic environments",
"type": "string"
Expand Down Expand Up @@ -9473,6 +9481,9 @@
"requiresSuitability": {
"type": "boolean"
},
"serviceBannerBucket": {
"type": "string"
},
"templateEnvironment": {
"description": "Required for dynamic environments",
"type": "string"
Expand Down Expand Up @@ -9564,6 +9575,9 @@
},
"requiresSuitability": {
"type": "boolean"
},
"serviceBannerBucket": {
"type": "string"
}
}
},
Expand Down
9 changes: 9 additions & 0 deletions sherlock/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1111,6 +1111,8 @@ definitions:
$ref: '#/definitions/sherlock.RoleV3'
requiresSuitability:
type: boolean
serviceBannerBucket:
type: string
templateEnvironment:
description: Required for dynamic environments
type: string
Expand Down Expand Up @@ -1209,6 +1211,8 @@ definitions:
type: string
requiresSuitability:
type: boolean
serviceBannerBucket:
type: string
templateEnvironment:
description: Required for dynamic environments
type: string
Expand Down Expand Up @@ -1285,6 +1289,8 @@ definitions:
type: string
requiresSuitability:
type: boolean
serviceBannerBucket:
type: string
type: object
sherlock.GitCommitV3:
properties:
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions sherlock/internal/api/sherlock/environments_v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 == "" {
Expand Down Expand Up @@ -200,6 +202,7 @@ func environmentFromModel(model models.Environment) EnvironmentV3 {
OfflineScheduleEndEnabled: model.OfflineScheduleEndEnabled,
OfflineScheduleEndWeekends: model.OfflineScheduleEndWeekends,
EnableJanitor: model.EnableJanitor,
ServiceBannerBucket: model.ServiceBannerBucket,
},
},
}
Expand Down
6 changes: 6 additions & 0 deletions sherlock/internal/api/sherlock/environments_v3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
},
},
},
Expand Down Expand Up @@ -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"),
},
},
{
Expand Down Expand Up @@ -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"),
},
},
},
Expand Down Expand Up @@ -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"),
},
},
}
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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"),
},
},
},
Expand Down
5 changes: 5 additions & 0 deletions sherlock/internal/models/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type Environment struct {
OfflineScheduleEndWeekends *bool
PactIdentifier *uuid.UUID
EnableJanitor *bool
ServiceBannerBucket *string
}

func (e *Environment) GetCiIdentifier() CiIdentifier {
Expand Down Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions sherlock/internal/models/environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
4 changes: 4 additions & 0 deletions sherlock/internal/models/test_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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()
Expand Down

0 comments on commit dcd6dec

Please sign in to comment.