diff --git a/.gitignore b/.gitignore index 2a528f5..f8426d9 100644 --- a/.gitignore +++ b/.gitignore @@ -25,5 +25,7 @@ testdata/*-config.json testdata/*-secrets.json /database.dump +db.dockerfile -docs/api-docs/admin-api/environments/ \ No newline at end of file + +docs/api-docs/admin-api/environments/ diff --git a/adapters/secrets/service.go b/adapters/secrets/service.go index 164d36d..5344c38 100644 --- a/adapters/secrets/service.go +++ b/adapters/secrets/service.go @@ -3,6 +3,7 @@ package secrets import ( "encoding/json" + "errors" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" @@ -28,7 +29,9 @@ func NewService(secretName string) (*Service, error) { return &Service{sm: svc, secretName: secretName}, nil } -func (s *Service) GetSecretValues(builderName string) (map[string]string, error) { +var ErrMissingSecret = errors.New("missing secret for builder") + +func (s *Service) GetSecretValues(builderName string) (json.RawMessage, error) { input := &secretsmanager.GetSecretValueInput{ SecretId: aws.String(s.secretName), } @@ -37,31 +40,21 @@ func (s *Service) GetSecretValues(builderName string) (map[string]string, error) if err != nil { return nil, err } - secretData := make(map[string]string) + secretData := make(map[string]json.RawMessage) err = json.Unmarshal([]byte(*result.SecretString), &secretData) if err != nil { return nil, err } - defaultStr := secretData["default"] // TODO: figured out that merging here is suboptimal and should be done in the application layer - defaultSecrets := make(map[string]string) - err = json.Unmarshal([]byte(defaultStr), &defaultSecrets) - if err != nil { - return nil, err - } - builderStr, ok := secretData[builderName] + builderSecret, ok := secretData[builderName] if !ok { - return defaultSecrets, nil + return nil, ErrMissingSecret } - builderSecrets := make(map[string]string) - err = json.Unmarshal([]byte(builderStr), &builderSecrets) - if err != nil { - return nil, err - } - return MergeSecrets(defaultSecrets, builderSecrets), nil + + return builderSecret, nil } -func (s *Service) SetSecretValues(builderName string, values map[string]string) error { +func (s *Service) SetSecretValues(builderName string, values json.RawMessage) error { input := &secretsmanager.GetSecretValueInput{ SecretId: aws.String(s.secretName), } @@ -70,17 +63,13 @@ func (s *Service) SetSecretValues(builderName string, values map[string]string) if err != nil { return err } - secretData := make(map[string]string) + secretData := make(map[string]json.RawMessage) err = json.Unmarshal([]byte(*result.SecretString), &secretData) if err != nil { return err } - marshalValues, err := json.Marshal(values) - if err != nil { - return err - } - secretData[builderName] = string(marshalValues) + secretData[builderName] = values newSecretString, err := json.Marshal(secretData) if err != nil { return err diff --git a/application/service.go b/application/service.go index 3b4dbe8..f97f9f9 100644 --- a/application/service.go +++ b/application/service.go @@ -20,7 +20,7 @@ type BuilderDataAccessor interface { } type SecretAccessor interface { - GetSecretValues(builderName string) (map[string]string, error) + GetSecretValues(builderName string) (json.RawMessage, error) } type BuilderHub struct { @@ -49,19 +49,15 @@ func (b *BuilderHub) RegisterCredentialsForBuilder(ctx context.Context, builderN } func (b *BuilderHub) GetConfigWithSecrets(ctx context.Context, builderName string) ([]byte, error) { - configOpaque, err := b.dataAccessor.GetActiveConfigForBuilder(ctx, builderName) + _, err := b.dataAccessor.GetActiveConfigForBuilder(ctx, builderName) if err != nil { return nil, fmt.Errorf("failing to fetch config for builder %s %w", builderName, err) } - secrets, err := b.secretAccessor.GetSecretValues(builderName) + secr, err := b.secretAccessor.GetSecretValues(builderName) if err != nil { return nil, fmt.Errorf("failing to fetch secrets for builder %s %w", builderName, err) } - res, err := MergeConfigSecrets(configOpaque, secrets) - if err != nil { - return nil, fmt.Errorf("failing to merge config and secrets %w", err) - } - return res, nil + return secr, nil } func (b *BuilderHub) VerifyIPAndMeasurements(ctx context.Context, ip net.IP, measurement map[string]string, attestationType string) (*domain.Builder, string, error) { diff --git a/domain/inmemory_secret.go b/domain/inmemory_secret.go index 85e5f70..70a994f 100644 --- a/domain/inmemory_secret.go +++ b/domain/inmemory_secret.go @@ -1,26 +1,29 @@ package domain -import "sync" +import ( + "encoding/json" + "sync" +) type InmemorySecretService struct { mu *sync.RWMutex - st map[string]map[string]string + st map[string]json.RawMessage } func NewMockSecretService() *InmemorySecretService { return &InmemorySecretService{ - st: make(map[string]map[string]string), + st: make(map[string]json.RawMessage), mu: &sync.RWMutex{}, } } -func (mss *InmemorySecretService) GetSecretValues(builderName string) (map[string]string, error) { +func (mss *InmemorySecretService) GetSecretValues(builderName string) (json.RawMessage, error) { mss.mu.RLock() defer mss.mu.RUnlock() return mss.st[builderName], nil } -func (mss *InmemorySecretService) SetSecretValues(builderName string, values map[string]string) error { +func (mss *InmemorySecretService) SetSecretValues(builderName string, values json.RawMessage) error { mss.mu.Lock() defer mss.mu.Unlock() mss.st[builderName] = values diff --git a/go.mod b/go.mod index 2cdccf7..0e3b794 100644 --- a/go.mod +++ b/go.mod @@ -4,28 +4,26 @@ go 1.22 require ( github.com/VictoriaMetrics/metrics v1.35.1 + github.com/aws/aws-sdk-go v1.55.5 + github.com/buger/jsonparser v1.1.1 + github.com/ethereum/go-ethereum v1.14.11 github.com/go-chi/chi/v5 v5.1.0 github.com/go-chi/httplog/v2 v2.1.1 github.com/google/uuid v1.6.0 + github.com/jackc/pgtype v1.14.3 github.com/jmoiron/sqlx v1.4.0 github.com/lib/pq v1.10.9 - github.com/rubenv/sql-migrate v1.7.0 github.com/stretchr/testify v1.9.0 github.com/urfave/cli/v2 v2.27.2 go.uber.org/atomic v1.11.0 ) require ( - github.com/aws/aws-sdk-go v1.55.5 // indirect - github.com/buger/jsonparser v1.1.1 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/ethereum/go-ethereum v1.14.11 // indirect - github.com/go-gorp/gorp/v3 v3.1.0 // indirect github.com/holiman/uint256 v1.3.1 // indirect github.com/jackc/pgio v1.0.0 // indirect - github.com/jackc/pgtype v1.14.3 // indirect - github.com/jackc/pgx/v5 v5.7.1 // indirect + github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/rogpeppe/go-internal v1.10.0 // indirect @@ -35,5 +33,6 @@ require ( github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 // indirect golang.org/x/crypto v0.27.0 // indirect golang.org/x/sys v0.25.0 // indirect + gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index f904e42..89c832d 100644 --- a/go.sum +++ b/go.sum @@ -23,8 +23,6 @@ github.com/go-chi/chi/v5 v5.1.0 h1:acVI1TYaD+hhedDJ3r54HyA6sExp3HfXq7QWEEY/xMw= github.com/go-chi/chi/v5 v5.1.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= github.com/go-chi/httplog/v2 v2.1.1 h1:ojojiu4PIaoeJ/qAO4GWUxJqvYUTobeo7zmuHQJAxRk= github.com/go-chi/httplog/v2 v2.1.1/go.mod h1:/XXdxicJsp4BA5fapgIC3VuTD+z0Z/VzukoB3VDc1YE= -github.com/go-gorp/gorp/v3 v3.1.0 h1:ItKF/Vbuj31dmV4jxA1qblpSwkl9g1typ24xoe70IGs= -github.com/go-gorp/gorp/v3 v3.1.0/go.mod h1:dLEjIyyRNiXvNZ8PSmzpt1GsWAUK8kjVhEpjH8TixEw= github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY= github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y= @@ -36,8 +34,10 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/holiman/uint256 v1.3.1 h1:JfTzmih28bittyHM8z360dCjIA9dbPIBlcTI6lmctQs= github.com/holiman/uint256 v1.3.1/go.mod h1:EOMSn4q6Nyt9P6efbI3bueV4e1b3dGlUCXeiRV4ng7E= +github.com/jackc/chunkreader v1.0.0 h1:4s39bBR8ByfqH+DKm8rQA3E1LHZWB9XWcrz8fqaZbe0= github.com/jackc/chunkreader v1.0.0/go.mod h1:RT6O25fNZIuasFJRyZ4R/Y2BbhasbmZXF9QQ7T3kePo= github.com/jackc/chunkreader/v2 v2.0.0/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk= +github.com/jackc/chunkreader/v2 v2.0.1 h1:i+RDz65UE+mmpjTfyz0MoVTnzeYxroil2G82ki7MGG8= github.com/jackc/chunkreader/v2 v2.0.1/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk= github.com/jackc/pgconn v0.0.0-20190420214824-7e0022ef6ba3/go.mod h1:jkELnwuX+w9qN5YIfX0fl88Ehu4XC3keFuOJJk9pcnA= github.com/jackc/pgconn v0.0.0-20190824142844-760dd75542eb/go.mod h1:lLjNuW/+OfW9/pnVKPazfWOgNfH2aPem8YQ7ilXGvJE= @@ -45,13 +45,16 @@ github.com/jackc/pgconn v0.0.0-20190831204454-2fabfa3c18b7/go.mod h1:ZJKsE/KZfsU github.com/jackc/pgconn v1.8.0/go.mod h1:1C2Pb36bGIP9QHGBYCjnyhqu7Rv3sGshaQUvmfGIB/o= github.com/jackc/pgconn v1.9.0/go.mod h1:YctiPyvzfU11JFxoXokUOOKQXQmDMoJL9vJzHH8/2JY= github.com/jackc/pgconn v1.9.1-0.20210724152538-d89c8390a530/go.mod h1:4z2w8XhRbP1hYxkpTuBjTS3ne3J48K83+u0zoyvg2pI= +github.com/jackc/pgconn v1.14.3 h1:bVoTr12EGANZz66nZPkMInAV/KHD2TxH9npjXXgiB3w= github.com/jackc/pgconn v1.14.3/go.mod h1:RZbme4uasqzybK2RK5c65VsHxoyaml09lx3tXOcO/VM= github.com/jackc/pgio v1.0.0 h1:g12B9UwVnzGhueNavwioyEEpAmqMe1E/BN9ES+8ovkE= github.com/jackc/pgio v1.0.0/go.mod h1:oP+2QK2wFfUWgr+gxjoBH9KGBb31Eio69xUb0w5bYf8= github.com/jackc/pgmock v0.0.0-20190831213851-13a1b77aafa2/go.mod h1:fGZlG77KXmcq05nJLRkk0+p82V8B8Dw8KN2/V9c/OAE= github.com/jackc/pgmock v0.0.0-20201204152224-4fe30f7445fd/go.mod h1:hrBW0Enj2AZTNpt/7Y5rr2xe/9Mn757Wtb2xeBzPv2c= github.com/jackc/pgmock v0.0.0-20210724152146-4ad1a8207f65/go.mod h1:5R2h2EEX+qri8jOWMbJCtaPWkrrNc7OHwsp2TCqp7ak= +github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= +github.com/jackc/pgproto3 v1.1.0 h1:FYYE4yRw+AgI8wXIinMlNjBbp/UitDJwfj5LqqewP1A= github.com/jackc/pgproto3 v1.1.0/go.mod h1:eR5FA3leWg7p9aeAqi37XOTgTIbkABlvcPB3E5rlc78= github.com/jackc/pgproto3/v2 v2.0.0-alpha1.0.20190420180111-c116219b62db/go.mod h1:bhq50y+xrl9n5mRYyCBFKkpRVTLYJVWeCc+mEAI3yXA= github.com/jackc/pgproto3/v2 v2.0.0-alpha1.0.20190609003834-432c2951c711/go.mod h1:uH0AWtUmuShn0bcesswc4aBTWGvw0cAxIJp+6OB//Wg= @@ -59,9 +62,12 @@ github.com/jackc/pgproto3/v2 v2.0.0-rc3/go.mod h1:ryONWYqW6dqSg1Lw6vXNMXoBJhpzvW github.com/jackc/pgproto3/v2 v2.0.0-rc3.0.20190831210041-4c03ce451f29/go.mod h1:ryONWYqW6dqSg1Lw6vXNMXoBJhpzvWKnT95C46ckYeM= github.com/jackc/pgproto3/v2 v2.0.6/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA= github.com/jackc/pgproto3/v2 v2.1.1/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA= +github.com/jackc/pgproto3/v2 v2.3.3 h1:1HLSx5H+tXR9pW3in3zaztoEwQYRC9SQaYUHjTSUOag= github.com/jackc/pgproto3/v2 v2.3.3/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA= github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b/go.mod h1:vsD4gTJCa9TptPL8sPkXrLZ+hDuNrZCnj29CQpr4X1E= github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= +github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo= +github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= github.com/jackc/pgtype v0.0.0-20190421001408-4ed0de4755e0/go.mod h1:hdSHsc1V01CGwFsrv11mJRHWJ6aifDLfdV3aVjFF0zg= github.com/jackc/pgtype v0.0.0-20190824184912-ab885b375b90/go.mod h1:KcahbBH1nCMSo2DXpzsoWOAfFkdEtEJpPbVLq8eE+mc= github.com/jackc/pgtype v0.0.0-20190828014616-a8802b16cc59/go.mod h1:MWlu30kVJrUS8lot6TQqcg7mtthZ9T0EoIBFiJcmcyw= @@ -73,15 +79,15 @@ github.com/jackc/pgx/v4 v4.0.0-20190420224344-cc3461e65d96/go.mod h1:mdxmSJJuR08 github.com/jackc/pgx/v4 v4.0.0-20190421002000-1b8f0016e912/go.mod h1:no/Y67Jkk/9WuGR0JG/JseM9irFbnEPbuWV2EELPNuM= github.com/jackc/pgx/v4 v4.0.0-pre1.0.20190824185557-6972a5742186/go.mod h1:X+GQnOEnf1dqHGpw7JmHqHc1NxDoalibchSk9/RWuDc= github.com/jackc/pgx/v4 v4.12.1-0.20210724153913-640aa07df17c/go.mod h1:1QD0+tgSXP7iUjYm9C1NxKhny7lq6ee99u/z+IHFcgs= +github.com/jackc/pgx/v4 v4.18.2 h1:xVpYkNR5pk5bMCZGfClbO962UIqVABcAGt7ha1s/FeU= github.com/jackc/pgx/v4 v4.18.2/go.mod h1:Ey4Oru5tH5sB6tV7hDmfWFahwF15Eb7DNXlRKx2CkVw= -github.com/jackc/pgx/v5 v5.7.1 h1:x7SYsPBYDkHDksogeSmZZ5xzThcTgRz++I5E+ePFUcs= -github.com/jackc/pgx/v5 v5.7.1/go.mod h1:e7O26IywZZ+naJtWWos6i6fvWK+29etgITqrqHLfoZA= github.com/jackc/puddle v0.0.0-20190413234325-e4ced69a3a2b/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= github.com/jackc/puddle v0.0.0-20190608224051-11cab39313c9/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= github.com/jackc/puddle v1.1.3/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= github.com/jackc/puddle v1.3.0/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= +github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8= github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= github.com/jmoiron/sqlx v1.4.0 h1:1PLqN7S1UYp5t4SrVVnt4nUVNemrDAtxlulVe+Qgm3o= github.com/jmoiron/sqlx v1.4.0/go.mod h1:ZrZ7UsYB/weZdl2Bxg6jCRO9c3YHl8r3ahlKmRT4JLY= @@ -89,6 +95,7 @@ github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+o github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= @@ -112,16 +119,12 @@ github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxU github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/poy/onpar v1.1.2 h1:QaNrNiZx0+Nar5dLgTVp5mXkyoVFIbepjyEoGSnhbAY= -github.com/poy/onpar v1.1.2/go.mod h1:6X8FLNoxyr9kkmnlqpK6LSoiOtrO6MICtWwEuWkLjzg= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ= github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU= github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc= -github.com/rubenv/sql-migrate v1.7.0 h1:HtQq1xyTN2ISmQDggnh0c9U3JlP8apWh8YO2jzlXpTI= -github.com/rubenv/sql-migrate v1.7.0/go.mod h1:S4wtDEG1CKn+0ShpTtzWhFpHHI5PvCUtiGI+C+Z2THE= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= @@ -232,6 +235,8 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224= +golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190425163242-31fd60d6bfdc/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= @@ -256,6 +261,8 @@ gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/inconshreveable/log15.v2 v2.0.0-20180818164646-67afb5ed74ec/go.mod h1:aPpfJ7XW+gOuirDoZ8gHhLh3kZ1B08FtV2bbmy7Jv3s= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/httpserver/e2e_test.go b/httpserver/e2e_test.go index d709ab0..923a7aa 100644 --- a/httpserver/e2e_test.go +++ b/httpserver/e2e_test.go @@ -123,7 +123,6 @@ func TestCreateMultipleNetworkBuilders(t *testing.T) { } } }) - } func TestCreateMultipleMeasurements(t *testing.T) { @@ -240,13 +239,13 @@ func createBuilder(t *testing.T, s *Server, builderName, ip, network string) { }) t.Run("CreateBuilderConfiguration", func(t *testing.T) { - builderConf := map[string]string{"test_key_1": builderName + "_test_value_1"} + builderConf := map[string]string{} sc, _ := execRequestNoAuth(t, s.GetAdminRouter(), http.MethodPost, "/api/admin/v1/builders/configuration/"+builderName, builderConf, nil) require.Equal(t, http.StatusOK, sc) }) t.Run("SetSecrets", func(t *testing.T) { - sec := map[string]string{"test_secret_1": builderName + "_test_secret_value"} - sc, _ := execRequestNoAuth(t, s.GetAdminRouter(), http.MethodPost, "/api/admin/v1/builders/secrets/"+builderName, sec, nil) + rawJson := json.RawMessage(fmt.Sprintf(`{"test_key_1": "%s_test_value_1", "test_secret_1": "%s_test_secret_value"}`, builderName, builderName)) + sc, _ := execRequestNoAuth(t, s.GetAdminRouter(), http.MethodPost, "/api/admin/v1/builders/secrets/"+builderName, rawJson, nil) require.Equal(t, http.StatusOK, sc) }) @@ -370,7 +369,7 @@ func execRequestAuth(t *testing.T, router http.Handler, method, url string, requ if response != nil && rr.Code >= 200 && rr.Code < 300 { err := json.Unmarshal(responseBody, response) - require.NoError(t, err) + require.NoErrorf(t, err, string(responseBody)) } return rr.Code, responseBody } diff --git a/ports/admin_handler.go b/ports/admin_handler.go index 7e515de..4a80266 100644 --- a/ports/admin_handler.go +++ b/ports/admin_handler.go @@ -23,8 +23,8 @@ type AdminBuilderService interface { } type AdminSecretService interface { - SetSecretValues(builderName string, values map[string]string) error - GetSecretValues(builderName string) (map[string]string, error) + SetSecretValues(builderName string, message json.RawMessage) error + application.SecretAccessor } type AdminHandler struct { @@ -62,26 +62,20 @@ func (s *AdminHandler) GetActiveConfigForBuilder(w http.ResponseWriter, r *http. // logic gets more complicated here func (s *AdminHandler) GetFullConfigForBuilder(w http.ResponseWriter, r *http.Request) { builderName := chi.URLParam(r, "builderName") - configBts, err := s.builderService.GetActiveConfigForBuilder(r.Context(), builderName) + _, err := s.builderService.GetActiveConfigForBuilder(r.Context(), builderName) if err != nil { s.log.Error("failed to get config with secrets", "error", err) w.WriteHeader(http.StatusInternalServerError) return } - secrets, err := s.secretService.GetSecretValues(builderName) + secr, err := s.secretService.GetSecretValues(builderName) if err != nil { s.log.Error("failed to get secrets", "error", err) w.WriteHeader(http.StatusInternalServerError) return } - bts, err := application.MergeConfigSecrets(configBts, secrets) - if err != nil { - s.log.Error("failed to merge config with secrets", "error", err) - w.WriteHeader(http.StatusInternalServerError) - return - } - _, err = w.Write(bts) + _, err = w.Write(secr) if err != nil { s.log.Error("failed to write response", "error", err) } @@ -234,14 +228,7 @@ func (s *AdminHandler) SetSecrets(w http.ResponseWriter, r *http.Request) { return } - secretValues, err := application.FlattenJSONFromBytes(body) - if err != nil { - s.log.Error("Failed to flatten JSON", "err", err) - w.WriteHeader(http.StatusBadRequest) - return - } - - err = s.secretService.SetSecretValues(builderName, secretValues) + err = s.secretService.SetSecretValues(builderName, body) if err != nil { s.log.Error("failed to set secret", "error", err) w.WriteHeader(http.StatusInternalServerError)