Skip to content

Commit

Permalink
Merge pull request #38 from Interhyp/RELTEC-10091
Browse files Browse the repository at this point in the history
feat(#37): Make additional promoters configurable on a user level
  • Loading branch information
Roshick authored Nov 2, 2022
2 parents c5c3896 + 9853b67 commit 4d91627
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 38 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ the [`local-config.yaml`][config] can be used to set the variables.
| `ALERT_TARGET_PREFIX` | | Validates the alert target to either match the prefix or suffix. |
| `ALERT_TARGET_SUFFIX` | | |
| | | |
| `ADDITIONAL_PROMOTERS` | | promoters to be added for all services. Can be left empty, or contain a comma separated list of usernames |
| `ADDITIONAL_PROMOTERS_FROM_OWNERS` | | owner aliases from which to get additional promoters to be added for all services. Can be left empty, or contain a comma separated list of owner aliases |

## Datastore
Expand Down
1 change: 1 addition & 0 deletions acorns/repository/customconfigint.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type CustomConfiguration interface {
AlertTargetPrefix() string
AlertTargetSuffix() string

AdditionalPromoters() []string
AdditionalPromotersFromOwners() []string

ElasticApmEnabled() bool
Expand Down
6 changes: 5 additions & 1 deletion internal/repository/config/accessors.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,14 @@ func (c *CustomConfigImpl) AlertTargetSuffix() string {
return c.VAlertTargetSuffix
}

func (c *CustomConfigImpl) AdditionalPromotersFromOwners() []string {
func (c *CustomConfigImpl) AdditionalPromoters() []string {
return strings.Split(c.VAdditionalPromoters, ",")
}

func (c *CustomConfigImpl) AdditionalPromotersFromOwners() []string {
return strings.Split(c.VAdditionalPromotersFromOwners, ",")
}

func (c *CustomConfigImpl) ElasticApmEnabled() bool {
return !c.VElasticApmDisabled &&
os.Getenv("ELASTIC_APM_SERVER_URL") != "" &&
Expand Down
44 changes: 26 additions & 18 deletions internal/repository/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,25 @@ import (
)

const (
KeyBbUser = "BB_USER"
KeyGitCommitterName = "GIT_COMMITTER_NAME"
KeyGitCommitterEmail = "GIT_COMMITTER_EMAIL"
KeyKafkaUser = "KAFKA_USER"
KeyKafkaTopic = "KAFKA_TOPIC"
KeyKafkaSeedBrokers = "KAFKA_SEED_BROKERS"
KeyKafkaGroupIdOverride = "KAFKA_GROUP_ID_OVERRIDE"
KeyKeySetUrl = "KEY_SET_URL"
KeyMetadataRepoUrl = "METADATA_REPO_URL"
KeyOwnerRegex = "OWNER_REGEX"
KeyUpdateJobIntervalMinutes = "UPDATE_JOB_INTERVAL_MINUTES"
KeyUpdateJobTimeoutSeconds = "UPDATE_JOB_TIMEOUT_SECONDS"
KeyVaultSecretsBasePath = "VAULT_SECRETS_BASE_PATH"
KeyVaultKafkaSecretPath = "VAULT_KAFKA_SECRET_PATH"
KeyAlertTargetPrefix = "ALERT_TARGET_PREFIX"
KeyAlertTargetSuffix = "ALERT_TARGET_SUFFIX"
KeyAdditionalPromoters = "ADDITIONAL_PROMOTERS_FROM_OWNERS"
KeyElasticApmDisabled = "ELASTIC_APM_DISABLED"
KeyBbUser = "BB_USER"
KeyGitCommitterName = "GIT_COMMITTER_NAME"
KeyGitCommitterEmail = "GIT_COMMITTER_EMAIL"
KeyKafkaUser = "KAFKA_USER"
KeyKafkaTopic = "KAFKA_TOPIC"
KeyKafkaSeedBrokers = "KAFKA_SEED_BROKERS"
KeyKafkaGroupIdOverride = "KAFKA_GROUP_ID_OVERRIDE"
KeyKeySetUrl = "KEY_SET_URL"
KeyMetadataRepoUrl = "METADATA_REPO_URL"
KeyOwnerRegex = "OWNER_REGEX"
KeyUpdateJobIntervalMinutes = "UPDATE_JOB_INTERVAL_MINUTES"
KeyUpdateJobTimeoutSeconds = "UPDATE_JOB_TIMEOUT_SECONDS"
KeyVaultSecretsBasePath = "VAULT_SECRETS_BASE_PATH"
KeyVaultKafkaSecretPath = "VAULT_KAFKA_SECRET_PATH"
KeyAlertTargetPrefix = "ALERT_TARGET_PREFIX"
KeyAlertTargetSuffix = "ALERT_TARGET_SUFFIX"
KeyAdditionalPromoters = "ADDITIONAL_PROMOTERS"
KeyAdditionalPromotersFromOwners = "ADDITIONAL_PROMOTERS_FROM_OWNERS"
KeyElasticApmDisabled = "ELASTIC_APM_DISABLED"
)

var CustomConfigItems = []auconfigapi.ConfigItem{
Expand Down Expand Up @@ -142,6 +143,13 @@ var CustomConfigItems = []auconfigapi.ConfigItem{
Key: KeyAdditionalPromoters,
EnvName: KeyAdditionalPromoters,
Default: "",
Description: "promoters to be added for all services. Can be left empty, or contain a comma separated list of usernames",
Validate: auconfigenv.ObtainPatternValidator("^|[a-z](-?[a-z0-9]+)*(,[a-z](-?[a-z0-9]+)*)*$"),
},
{
Key: KeyAdditionalPromotersFromOwners,
EnvName: KeyAdditionalPromotersFromOwners,
Default: "",
Description: "owner aliases from which to get additional promoters to be added for all services. Can be left empty, or contain a comma separated list of owner aliases",
Validate: auconfigenv.ObtainPatternValidator("^|[a-z](-?[a-z0-9]+)*(,[a-z](-?[a-z0-9]+)*)*$"),
},
Expand Down
38 changes: 20 additions & 18 deletions internal/repository/config/plumbing.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,25 @@ import (
)

type CustomConfigImpl struct {
VBbUser string
VGitCommitterName string
VGitCommitterEmail string
VKafkaUser string
VKafkaTopic string
VKafkaSeedBrokers string
VKeySetUrl string
VKafkaGroupIdOverride string
VMetadataRepoUrl string
VOwnerRegex string
VUpdateJobIntervalCronPart string
VUpdateJobTimeoutSeconds uint16
VVaultSecretsBasePath string
VVaultKafkaSecretPath string
VAlertTargetPrefix string
VAlertTargetSuffix string
VAdditionalPromoters string
VElasticApmDisabled bool
VBbUser string
VGitCommitterName string
VGitCommitterEmail string
VKafkaUser string
VKafkaTopic string
VKafkaSeedBrokers string
VKeySetUrl string
VKafkaGroupIdOverride string
VMetadataRepoUrl string
VOwnerRegex string
VUpdateJobIntervalCronPart string
VUpdateJobTimeoutSeconds uint16
VVaultSecretsBasePath string
VVaultKafkaSecretPath string
VAlertTargetPrefix string
VAlertTargetSuffix string
VAdditionalPromoters string
VAdditionalPromotersFromOwners string
VElasticApmDisabled bool
}

func New() auacornapi.Acorn {
Expand All @@ -51,6 +52,7 @@ func (c *CustomConfigImpl) Obtain(getter func(key string) string) {
c.VAlertTargetPrefix = getter(KeyAlertTargetPrefix)
c.VAlertTargetSuffix = getter(KeyAlertTargetSuffix)
c.VAdditionalPromoters = getter(KeyAdditionalPromoters)
c.VAdditionalPromotersFromOwners = getter(KeyAdditionalPromotersFromOwners)
c.VElasticApmDisabled, _ = strconv.ParseBool(getter(KeyElasticApmDisabled))
}

Expand Down
1 change: 1 addition & 0 deletions internal/repository/config/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,5 +135,6 @@ func TestAccessors(t *testing.T) {
require.Equal(t, "kafka/feat/room-service", repository.Custom(cut).VaultKafkaSecretPath())
require.Equal(t, "https://some-domain.com/", repository.Custom(cut).AlertTargetPrefix())
require.Equal(t, "@some-domain.com", repository.Custom(cut).AlertTargetSuffix())
require.EqualValues(t, []string{"someguy"}, repository.Custom(cut).AdditionalPromoters())
require.EqualValues(t, []string{"add-my-promoters-to-every-service", "also-add-my-promoters"}, repository.Custom(cut).AdditionalPromotersFromOwners())
}
15 changes: 14 additions & 1 deletion internal/service/services/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,14 @@ func (s *Impl) validateDeletionDto(ctx context.Context, deletionInfo openapi.Del
func (s *Impl) GetServicePromoters(ctx context.Context, serviceOwnerAlias string) (openapi.ServicePromotersDto, error) {
resultSet := make(map[string]bool)

// add default promoters
err := s.addDefaultPromoters(ctx, resultSet)
if err != nil {
return openapi.ServicePromotersDto{}, err
}

// add the promoters for the given ownerAlias
err := s.addPromotersForOwner(ctx, serviceOwnerAlias, resultSet)
err = s.addPromotersForOwner(ctx, serviceOwnerAlias, resultSet)
if err != nil {
return openapi.ServicePromotersDto{}, err
}
Expand Down Expand Up @@ -417,6 +423,13 @@ func (s *Impl) GetServicePromoters(ctx context.Context, serviceOwnerAlias string
return openapi.ServicePromotersDto{Promoters: result}, nil
}

func (s *Impl) addDefaultPromoters(ctx context.Context, resultSet map[string]bool) error {
for _, user := range s.CustomConfiguration.AdditionalPromoters() {
resultSet[user] = true
}
return nil
}

func (s *Impl) addPromotersForOwner(ctx context.Context, ownerAlias string, resultSet map[string]bool) error {
serviceOwner, err := s.Cache.GetOwner(ctx, ownerAlias)
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions internal/service/services/services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ func tstCreateValid() openapi.ServiceCreateDto {
type MockConfig struct {
}

func (c *MockConfig) AdditionalPromoters() []string {
//TODO implement me
panic("implement me")
}

func (c *MockConfig) ElasticApmEnabled() bool {
return false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"else",
"entirely",
"kschlangenheldt",
"someguy",
"someone"
]
}
1 change: 1 addition & 0 deletions test/resources/acceptance-expected/service-promoters.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"promoters": [
"else",
"kschlangenheldt",
"someguy",
"someone"
]
}
2 changes: 2 additions & 0 deletions test/resources/valid-config-unique.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ OWNER_REGEX: '[a-z][0-9]+'
VAULT_KAFKA_SECRET_PATH: kafka/feat/room-service
ALERT_TARGET_PREFIX: https://some-domain.com/
ALERT_TARGET_SUFFIX: '@some-domain.com'

ADDITIONAL_PROMOTERS: 'someguy'
ADDITIONAL_PROMOTERS_FROM_OWNERS: 'add-my-promoters-to-every-service,also-add-my-promoters'
2 changes: 2 additions & 0 deletions test/resources/valid-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ BB_USER: localuser
METADATA_REPO_URL: http://metadata
OWNER_REGEX: .*
UPDATE_JOB_INTERVAL_MINUTES: 5

ADDITIONAL_PROMOTERS: 'someguy'
ADDITIONAL_PROMOTERS_FROM_OWNERS: 'deleteme'

0 comments on commit 4d91627

Please sign in to comment.