Skip to content

Commit

Permalink
Merge pull request #143 from Interhyp/git_url
Browse files Browse the repository at this point in the history
feat(RELTEC-11171): switched to git-url clone instead of http
  • Loading branch information
mpl-interhyp committed May 12, 2023
2 parents 999d136 + 55f43c0 commit fd5bb95
Show file tree
Hide file tree
Showing 18 changed files with 529 additions and 260 deletions.
12 changes: 9 additions & 3 deletions acorns/config/customconfigint.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package config

import (
librepo "github.com/StephanHCB/go-backend-service-common/acorns/repository"
"regexp"

librepo "github.com/StephanHCB/go-backend-service-common/acorns/repository"
)

type CustomConfiguration interface {
Expand All @@ -12,6 +13,10 @@ type CustomConfiguration interface {
BitbucketUsername() string
BitbucketPassword() string

SSHPrivateKey() string
SSHPrivateKeyPassword() string
SSHMetadataRepositoryUrl() string

BitbucketServer() string
BitbucketCacheSize() int
BitbucketCacheRetentionSeconds() uint32
Expand All @@ -30,7 +35,6 @@ type CustomConfiguration interface {
AuthOidcTokenAudience() string
AuthGroupWrite() string

MetadataRepoUrl() string
MetadataRepoMainline() string

UpdateJobIntervalCronPart() string
Expand Down Expand Up @@ -68,6 +72,9 @@ func Custom(configuration librepo.Configuration) CustomConfiguration {
const (
KeyBasicAuthUsername = "BASIC_AUTH_USERNAME"
KeyBasicAuthPassword = "BASIC_AUTH_PASSWORD"
KeySSHPrivateKey = "SSH_PRIVATE_KEY"
KeySSHPrivateKeyPassword = "SSH_PRIVATE_KEY_PASSWORD"
KeySSHMetadataRepositoryUrl = "SSH_METADATA_REPO_URL"
KeyBitbucketUsername = "BITBUCKET_USERNAME"
KeyBitbucketPassword = "BITBUCKET_PASSWORD"
KeyBitbucketServer = "BITBUCKET_SERVER"
Expand All @@ -84,7 +91,6 @@ const (
KeyAuthOidcKeySetUrl = "AUTH_OIDC_KEY_SET_URL"
KeyAuthOidcTokenAudience = "AUTH_OIDC_TOKEN_AUDIENCE"
KeyAuthGroupWrite = "AUTH_GROUP_WRITE"
KeyMetadataRepoUrl = "METADATA_REPO_URL"
KeyMetadataRepoMainline = "METADATA_REPO_MAINLINE"
KeyUpdateJobIntervalMinutes = "UPDATE_JOB_INTERVAL_MINUTES"
KeyUpdateJobTimeoutSeconds = "UPDATE_JOB_TIMEOUT_SECONDS"
Expand Down
18 changes: 18 additions & 0 deletions acorns/repository/sshAuthProviderInt.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package repository

import (
"context"

"github.com/go-git/go-git/v5/plumbing/transport/ssh"
)

const SshAuthProviderAcornName = "SshAuthProvider"

// SshAuthProvider is an SshAuthProvider business logic component.
type SshAuthProvider interface {
IsSshAuthProvider() bool

Setup(ctx context.Context) error

ProvideSshAuth(ctx context.Context) (*ssh.PublicKeys, error)
}
2 changes: 1 addition & 1 deletion docs/local-config.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ VAULT_SECRETS_CONFIG: >-
AUTH_OIDC_KEY_SET_URL: https://login.microsoftonline.com/<YOU MUST ADD CLIENT ID HERE>/discovery/v2.0/keys
AUTH_OIDC_TOKEN_AUDIENCE: <YOU MUST ADD TOKEN AUDIENCE HERE>

METADATA_REPO_URL: https://github.com/Interhyp/service-metadata-example
SSH_METADATA_REPO_URL: ssh://git@github.com/Interhyp/service-metadata-example.git

UPDATE_JOB_INTERVAL_MINUTES: 15
UPDATE_JOB_TIMEOUT_SECONDS: 30
Expand Down
16 changes: 12 additions & 4 deletions internal/repository/config/accessors.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ func (c *CustomConfigImpl) BasicAuthPassword() string {
return c.VBasicAuthPassword
}

func (c *CustomConfigImpl) SSHPrivateKey() string {
return c.VSSHPrivateKey
}

func (c *CustomConfigImpl) SSHPrivateKeyPassword() string {
return c.VSSHPrivateKeyPassword
}

func (c *CustomConfigImpl) SSHMetadataRepositoryUrl() string {
return c.VSSHMetadataRepoUrl
}

func (c *CustomConfigImpl) BitbucketUsername() string {
return c.VBitbucketUsername
}
Expand Down Expand Up @@ -78,10 +90,6 @@ func (c *CustomConfigImpl) KafkaGroupIdOverride() string {
return c.VKafkaGroupIdOverride
}

func (c *CustomConfigImpl) MetadataRepoUrl() string {
return c.VMetadataRepoUrl
}

func (c *CustomConfigImpl) MetadataRepoMainline() string {
return c.VMetadataRepoMainline
}
Expand Down
31 changes: 23 additions & 8 deletions internal/repository/config/config.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package config

import (
"math"

"github.com/Interhyp/metadata-service/acorns/config"
auconfigapi "github.com/StephanHCB/go-autumn-config-api"
auconfigenv "github.com/StephanHCB/go-autumn-config-env"
"math"
)

var CustomConfigItems = []auconfigapi.ConfigItem{
Expand All @@ -22,6 +23,27 @@ var CustomConfigItems = []auconfigapi.ConfigItem{
Description: "password for basic-auth write access to this service",
Validate: auconfigenv.ObtainNotEmptyValidator(),
},
{
Key: config.KeySSHPrivateKey,
EnvName: config.KeySSHPrivateKey,
Description: "ssh private key used to access the vcs",
Default: "",
Validate: auconfigenv.ObtainNotEmptyValidator(),
},
{
Key: config.KeySSHPrivateKeyPassword,
EnvName: config.KeySSHPrivateKeyPassword,
Description: "ssh private key password",
Default: "",
Validate: auconfigapi.ConfigNeedsNoValidation,
},
{
Key: config.KeySSHMetadataRepositoryUrl,
EnvName: config.KeySSHMetadataRepositoryUrl,
Default: "",
Description: "ssh git clone url for service-metadata repository",
Validate: auconfigenv.ObtainNotEmptyValidator(),
},
{
Key: config.KeyBitbucketUsername,
EnvName: config.KeyBitbucketUsername,
Expand Down Expand Up @@ -134,13 +156,6 @@ var CustomConfigItems = []auconfigapi.ConfigItem{
Description: "group name or id for write access to this service",
Validate: auconfigapi.ConfigNeedsNoValidation,
},
{
Key: config.KeyMetadataRepoUrl,
EnvName: config.KeyMetadataRepoUrl,
Default: "",
Description: "git clone url for service-metadata repository",
Validate: auconfigenv.ObtainNotEmptyValidator(),
},
{
Key: config.KeyMetadataRepoMainline,
EnvName: config.KeyMetadataRepoMainline,
Expand Down
13 changes: 9 additions & 4 deletions internal/repository/config/plumbing.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
package config

import (
"regexp"
"strconv"

"github.com/Interhyp/metadata-service/acorns/config"
auacornapi "github.com/StephanHCB/go-autumn-acorn-registry/api"
auconfigapi "github.com/StephanHCB/go-autumn-config-api"
auconfigenv "github.com/StephanHCB/go-autumn-config-env"
libconfig "github.com/StephanHCB/go-backend-service-common/repository/config"
"github.com/StephanHCB/go-backend-service-common/repository/vault"
"regexp"
"strconv"
)

type CustomConfigImpl struct {
VBasicAuthUsername string
VBasicAuthPassword string
VSSHPrivateKey string
VSSHPrivateKeyPassword string
VSSHMetadataRepoUrl string
VBitbucketUsername string
VBitbucketPassword string
VBitbucketServer string
Expand All @@ -30,7 +34,6 @@ type CustomConfigImpl struct {
VAuthOidcTokenAudience string
VAuthGroupWrite string
VKafkaGroupIdOverride string
VMetadataRepoUrl string
VMetadataRepoMainline string
VUpdateJobIntervalCronPart string
VUpdateJobTimeoutSeconds uint16
Expand Down Expand Up @@ -64,6 +67,9 @@ func New() auacornapi.Acorn {
func (c *CustomConfigImpl) Obtain(getter func(key string) string) {
c.VBasicAuthUsername = getter(config.KeyBasicAuthUsername)
c.VBasicAuthPassword = getter(config.KeyBasicAuthPassword)
c.VSSHPrivateKey = getter(config.KeySSHPrivateKey)
c.VSSHPrivateKeyPassword = getter(config.KeySSHPrivateKeyPassword)
c.VSSHMetadataRepoUrl = getter(config.KeySSHMetadataRepositoryUrl)
c.VBitbucketUsername = getter(config.KeyBitbucketUsername)
c.VBitbucketPassword = getter(config.KeyBitbucketPassword)
c.VBitbucketServer = getter(config.KeyBitbucketServer)
Expand All @@ -80,7 +86,6 @@ func (c *CustomConfigImpl) Obtain(getter func(key string) string) {
c.VAuthOidcKeySetUrl = getter(config.KeyAuthOidcKeySetUrl)
c.VAuthOidcTokenAudience = getter(config.KeyAuthOidcTokenAudience)
c.VAuthGroupWrite = getter(config.KeyAuthGroupWrite)
c.VMetadataRepoUrl = getter(config.KeyMetadataRepoUrl)
c.VMetadataRepoMainline = getter(config.KeyMetadataRepoMainline)
c.VUpdateJobIntervalCronPart = getter(config.KeyUpdateJobIntervalMinutes)
c.VUpdateJobTimeoutSeconds = toUint16(getter(config.KeyUpdateJobTimeoutSeconds))
Expand Down
7 changes: 4 additions & 3 deletions internal/repository/config/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package config
import (
"bytes"
"context"
"testing"

"github.com/Interhyp/metadata-service/acorns/config"
"github.com/Interhyp/metadata-service/docs"
auconfigenv "github.com/StephanHCB/go-autumn-config-env"
Expand All @@ -12,7 +14,6 @@ import (
"github.com/StephanHCB/go-backend-service-common/repository/logging"
"github.com/rs/zerolog/log"
"github.com/stretchr/testify/require"
"testing"
)

const basedir = "../../../test/resources/"
Expand Down Expand Up @@ -72,7 +73,7 @@ func TestValidate_LotsOfErrors(t *testing.T) {
_, err := tstSetupCutAndLogRecorder(t, "invalid-config-values.yaml")

require.NotNil(t, err)
require.Contains(t, err.Error(), "some configuration values failed to validate or parse. There were 25 error(s). See details above")
require.Contains(t, err.Error(), "some configuration values failed to validate or parse. There were 26 error(s). See details above")

actualLog := goauzerolog.RecordedLogForTesting.String()

Expand Down Expand Up @@ -127,7 +128,7 @@ func TestAccessors(t *testing.T) {
require.Equal(t, "http://keyset", config.Custom(cut).AuthOidcKeySetUrl())
require.Equal(t, "some-audience", config.Custom(cut).AuthOidcTokenAudience())
require.Equal(t, "admin", config.Custom(cut).AuthGroupWrite())
require.Equal(t, "http://metadata", config.Custom(cut).MetadataRepoUrl())
require.Equal(t, "git://metadata", config.Custom(cut).SSHMetadataRepositoryUrl())
require.Equal(t, "5", config.Custom(cut).UpdateJobIntervalCronPart())
require.Equal(t, uint16(30), config.Custom(cut).UpdateJobTimeoutSeconds())
require.Equal(t, "https://some-domain.com/", config.Custom(cut).AlertTargetPrefix())
Expand Down
10 changes: 7 additions & 3 deletions internal/repository/metadata/acorn.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package metadata

import (
"context"
"time"

"github.com/Interhyp/metadata-service/acorns/config"
"github.com/Interhyp/metadata-service/acorns/repository"
"github.com/StephanHCB/go-autumn-acorn-registry/api"
auzerolog "github.com/StephanHCB/go-autumn-logging-zerolog"
librepo "github.com/StephanHCB/go-backend-service-common/acorns/repository"
"time"
)

// --- implementing Acorn ---
Expand All @@ -33,7 +34,7 @@ func (r *Impl) AcornName() string {
func (r *Impl) AssembleAcorn(registry auacornapi.AcornRegistry) error {
r.Configuration = registry.GetAcornByName(librepo.ConfigurationAcornName).(librepo.Configuration)
r.Logging = registry.GetAcornByName(librepo.LoggingAcornName).(librepo.Logging)

r.SshAuthProvider = registry.GetAcornByName(repository.SshAuthProviderAcornName).(repository.SshAuthProvider)
r.CustomConfiguration = config.Custom(r.Configuration)

return nil
Expand All @@ -46,6 +47,9 @@ func (r *Impl) SetupAcorn(registry auacornapi.AcornRegistry) error {
if err := registry.SetupAfter(r.Logging.(auacornapi.Acorn)); err != nil {
return err
}
if err := registry.SetupAfter(r.SshAuthProvider.(auacornapi.Acorn)); err != nil {
return err
}

ctx := auzerolog.AddLoggerToCtx(context.Background())

Expand All @@ -58,7 +62,7 @@ func (r *Impl) SetupAcorn(registry auacornapi.AcornRegistry) error {
return nil
}

func (r *Impl) TeardownAcorn(registry auacornapi.AcornRegistry) error {
func (r *Impl) TeardownAcorn(_ auacornapi.AcornRegistry) error {
ctx := auzerolog.AddLoggerToCtx(context.Background())
r.Discard(ctx)
return nil
Expand Down
Loading

0 comments on commit fd5bb95

Please sign in to comment.