Skip to content

Commit

Permalink
Merge pull request #173 from gabriel-samfira/switch-to-seal-unseal
Browse files Browse the repository at this point in the history
Switch to seal unseal
  • Loading branch information
gabriel-samfira authored Aug 28, 2023
2 parents 4348999 + 4d1acdc commit f463a41
Show file tree
Hide file tree
Showing 310 changed files with 11,031 additions and 1,992 deletions.
19 changes: 13 additions & 6 deletions database/sql/enterprise.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func (s *sqlDatabase) CreateEnterprise(ctx context.Context, name, credentialsNam
if webhookSecret == "" {
return params.Enterprise{}, errors.New("creating enterprise: missing secret")
}
secret, err := util.Aes256EncodeString(webhookSecret, s.cfg.Passphrase)
secret, err := util.Seal([]byte(webhookSecret), []byte(s.cfg.Passphrase))
if err != nil {
return params.Enterprise{}, errors.Wrap(err, "encoding secret")
}
Expand Down Expand Up @@ -110,7 +110,7 @@ func (s *sqlDatabase) UpdateEnterprise(ctx context.Context, enterpriseID string,
}

if param.WebhookSecret != "" {
secret, err := util.Aes256EncodeString(param.WebhookSecret, s.cfg.Passphrase)
secret, err := util.Seal([]byte(param.WebhookSecret), []byte(s.cfg.Passphrase))
if err != nil {
return params.Enterprise{}, errors.Wrap(err, "encoding secret")
}
Expand Down Expand Up @@ -192,15 +192,15 @@ func (s *sqlDatabase) CreateEnterprisePool(ctx context.Context, enterpriseID str
return params.Pool{}, errors.Wrap(err, "fetching pool")
}

return s.sqlToCommonPool(pool), nil
return s.sqlToCommonPool(pool)
}

func (s *sqlDatabase) GetEnterprisePool(ctx context.Context, enterpriseID, poolID string) (params.Pool, error) {
pool, err := s.getEntityPool(ctx, params.EnterprisePool, enterpriseID, poolID, "Tags", "Instances")
if err != nil {
return params.Pool{}, errors.Wrap(err, "fetching pool")
}
return s.sqlToCommonPool(pool), nil
return s.sqlToCommonPool(pool)
}

func (s *sqlDatabase) DeleteEnterprisePool(ctx context.Context, enterpriseID, poolID string) error {
Expand Down Expand Up @@ -240,7 +240,10 @@ func (s *sqlDatabase) ListEnterprisePools(ctx context.Context, enterpriseID stri

ret := make([]params.Pool, len(pools))
for idx, pool := range pools {
ret[idx] = s.sqlToCommonPool(pool)
ret[idx], err = s.sqlToCommonPool(pool)
if err != nil {
return nil, errors.Wrap(err, "fetching pools")
}
}

return ret, nil
Expand All @@ -254,7 +257,11 @@ func (s *sqlDatabase) ListEnterpriseInstances(ctx context.Context, enterpriseID
ret := []params.Instance{}
for _, pool := range pools {
for _, instance := range pool.Instances {
ret = append(ret, s.sqlToParamsInstance(instance))
paramsInstance, err := s.sqlToParamsInstance(instance)
if err != nil {
return nil, errors.Wrap(err, "fetching instance")
}
ret = append(ret, paramsInstance)
}
}
return ret, nil
Expand Down
19 changes: 13 additions & 6 deletions database/sql/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (s *sqlDatabase) CreateInstance(ctx context.Context, poolID string, param p
return params.Instance{}, errors.Wrap(q.Error, "creating instance")
}

return s.sqlToParamsInstance(newInstance), nil
return s.sqlToParamsInstance(newInstance)
}

func (s *sqlDatabase) getInstanceByID(ctx context.Context, instanceID string) (Instance, error) {
Expand Down Expand Up @@ -128,7 +128,7 @@ func (s *sqlDatabase) GetPoolInstanceByName(ctx context.Context, poolID string,
return params.Instance{}, errors.Wrap(err, "fetching instance")
}

return s.sqlToParamsInstance(instance), nil
return s.sqlToParamsInstance(instance)
}

func (s *sqlDatabase) GetInstanceByName(ctx context.Context, instanceName string) (params.Instance, error) {
Expand All @@ -137,7 +137,7 @@ func (s *sqlDatabase) GetInstanceByName(ctx context.Context, instanceName string
return params.Instance{}, errors.Wrap(err, "fetching instance")
}

return s.sqlToParamsInstance(instance), nil
return s.sqlToParamsInstance(instance)
}

func (s *sqlDatabase) DeleteInstance(ctx context.Context, poolID string, instanceName string) error {
Expand Down Expand Up @@ -255,7 +255,7 @@ func (s *sqlDatabase) UpdateInstance(ctx context.Context, instanceID string, par
}
}

return s.sqlToParamsInstance(instance), nil
return s.sqlToParamsInstance(instance)
}

func (s *sqlDatabase) ListPoolInstances(ctx context.Context, poolID string) ([]params.Instance, error) {
Expand All @@ -273,7 +273,10 @@ func (s *sqlDatabase) ListPoolInstances(ctx context.Context, poolID string) ([]p

ret := make([]params.Instance, len(instances))
for idx, inst := range instances {
ret[idx] = s.sqlToParamsInstance(inst)
ret[idx], err = s.sqlToParamsInstance(inst)
if err != nil {
return nil, errors.Wrap(err, "converting instance")
}
}
return ret, nil
}
Expand All @@ -286,8 +289,12 @@ func (s *sqlDatabase) ListAllInstances(ctx context.Context) ([]params.Instance,
return nil, errors.Wrap(q.Error, "fetching instances")
}
ret := make([]params.Instance, len(instances))
var err error
for idx, instance := range instances {
ret[idx] = s.sqlToParamsInstance(instance)
ret[idx], err = s.sqlToParamsInstance(instance)
if err != nil {
return nil, errors.Wrap(err, "converting instance")
}
}
return ret, nil
}
Expand Down
19 changes: 13 additions & 6 deletions database/sql/organizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (s *sqlDatabase) CreateOrganization(ctx context.Context, name, credentialsN
if webhookSecret == "" {
return params.Organization{}, errors.New("creating org: missing secret")
}
secret, err := util.Aes256EncodeString(webhookSecret, s.cfg.Passphrase)
secret, err := util.Seal([]byte(webhookSecret), []byte(s.cfg.Passphrase))
if err != nil {
return params.Organization{}, fmt.Errorf("failed to encrypt string")
}
Expand Down Expand Up @@ -114,7 +114,7 @@ func (s *sqlDatabase) UpdateOrganization(ctx context.Context, orgID string, para
}

if param.WebhookSecret != "" {
secret, err := util.Aes256EncodeString(param.WebhookSecret, s.cfg.Passphrase)
secret, err := util.Seal([]byte(param.WebhookSecret), []byte(s.cfg.Passphrase))
if err != nil {
return params.Organization{}, fmt.Errorf("saving org: failed to encrypt string: %w", err)
}
Expand Down Expand Up @@ -209,7 +209,7 @@ func (s *sqlDatabase) CreateOrganizationPool(ctx context.Context, orgId string,
return params.Pool{}, errors.Wrap(err, "fetching pool")
}

return s.sqlToCommonPool(pool), nil
return s.sqlToCommonPool(pool)
}

func (s *sqlDatabase) ListOrgPools(ctx context.Context, orgID string) ([]params.Pool, error) {
Expand All @@ -220,7 +220,10 @@ func (s *sqlDatabase) ListOrgPools(ctx context.Context, orgID string) ([]params.

ret := make([]params.Pool, len(pools))
for idx, pool := range pools {
ret[idx] = s.sqlToCommonPool(pool)
ret[idx], err = s.sqlToCommonPool(pool)
if err != nil {
return nil, errors.Wrap(err, "fetching pool")
}
}

return ret, nil
Expand All @@ -231,7 +234,7 @@ func (s *sqlDatabase) GetOrganizationPool(ctx context.Context, orgID, poolID str
if err != nil {
return params.Pool{}, errors.Wrap(err, "fetching pool")
}
return s.sqlToCommonPool(pool), nil
return s.sqlToCommonPool(pool)
}

func (s *sqlDatabase) DeleteOrganizationPool(ctx context.Context, orgID, poolID string) error {
Expand Down Expand Up @@ -262,7 +265,11 @@ func (s *sqlDatabase) ListOrgInstances(ctx context.Context, orgID string) ([]par
ret := []params.Instance{}
for _, pool := range pools {
for _, instance := range pool.Instances {
ret = append(ret, s.sqlToParamsInstance(instance))
paramsInstance, err := s.sqlToParamsInstance(instance)
if err != nil {
return nil, errors.Wrap(err, "fetching instance")
}
ret = append(ret, paramsInstance)
}
}
return ret, nil
Expand Down
13 changes: 10 additions & 3 deletions database/sql/pools.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,12 @@ func (s *sqlDatabase) ListAllPools(ctx context.Context) ([]params.Pool, error) {
}

ret := make([]params.Pool, len(pools))
var err error
for idx, val := range pools {
ret[idx] = s.sqlToCommonPool(val)
ret[idx], err = s.sqlToCommonPool(val)
if err != nil {
return nil, errors.Wrap(err, "converting pool")
}
}
return ret, nil
}
Expand All @@ -52,7 +56,7 @@ func (s *sqlDatabase) GetPoolByID(ctx context.Context, poolID string) (params.Po
if err != nil {
return params.Pool{}, errors.Wrap(err, "fetching pool by ID")
}
return s.sqlToCommonPool(pool), nil
return s.sqlToCommonPool(pool)
}

func (s *sqlDatabase) DeletePoolByID(ctx context.Context, poolID string) error {
Expand Down Expand Up @@ -197,7 +201,10 @@ func (s *sqlDatabase) findPoolByTags(id string, poolType params.PoolType, tags [

ret := make([]params.Pool, len(pools))
for idx, val := range pools {
ret[idx] = s.sqlToCommonPool(val)
ret[idx], err = s.sqlToCommonPool(val)
if err != nil {
return nil, errors.Wrap(err, "converting pool")
}
}

return ret, nil
Expand Down
19 changes: 13 additions & 6 deletions database/sql/repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (s *sqlDatabase) CreateRepository(ctx context.Context, owner, name, credent
if webhookSecret == "" {
return params.Repository{}, errors.New("creating repo: missing secret")
}
secret, err := util.Aes256EncodeString(webhookSecret, s.cfg.Passphrase)
secret, err := util.Seal([]byte(webhookSecret), []byte(s.cfg.Passphrase))
if err != nil {
return params.Repository{}, fmt.Errorf("failed to encrypt string")
}
Expand Down Expand Up @@ -114,7 +114,7 @@ func (s *sqlDatabase) UpdateRepository(ctx context.Context, repoID string, param
}

if param.WebhookSecret != "" {
secret, err := util.Aes256EncodeString(param.WebhookSecret, s.cfg.Passphrase)
secret, err := util.Seal([]byte(param.WebhookSecret), []byte(s.cfg.Passphrase))
if err != nil {
return params.Repository{}, fmt.Errorf("saving repo: failed to encrypt string: %w", err)
}
Expand Down Expand Up @@ -209,7 +209,7 @@ func (s *sqlDatabase) CreateRepositoryPool(ctx context.Context, repoId string, p
return params.Pool{}, errors.Wrap(err, "fetching pool")
}

return s.sqlToCommonPool(pool), nil
return s.sqlToCommonPool(pool)
}

func (s *sqlDatabase) ListRepoPools(ctx context.Context, repoID string) ([]params.Pool, error) {
Expand All @@ -220,7 +220,10 @@ func (s *sqlDatabase) ListRepoPools(ctx context.Context, repoID string) ([]param

ret := make([]params.Pool, len(pools))
for idx, pool := range pools {
ret[idx] = s.sqlToCommonPool(pool)
ret[idx], err = s.sqlToCommonPool(pool)
if err != nil {
return nil, errors.Wrap(err, "fetching pool")
}
}

return ret, nil
Expand All @@ -231,7 +234,7 @@ func (s *sqlDatabase) GetRepositoryPool(ctx context.Context, repoID, poolID stri
if err != nil {
return params.Pool{}, errors.Wrap(err, "fetching pool")
}
return s.sqlToCommonPool(pool), nil
return s.sqlToCommonPool(pool)
}

func (s *sqlDatabase) DeleteRepositoryPool(ctx context.Context, repoID, poolID string) error {
Expand Down Expand Up @@ -263,7 +266,11 @@ func (s *sqlDatabase) ListRepoInstances(ctx context.Context, repoID string) ([]p
ret := []params.Instance{}
for _, pool := range pools {
for _, instance := range pool.Instances {
ret = append(ret, s.sqlToParamsInstance(instance))
paramsInstance, err := s.sqlToParamsInstance(instance)
if err != nil {
return nil, errors.Wrap(err, "fetching instance")
}
ret = append(ret, paramsInstance)
}
}
return ret, nil
Expand Down
Loading

0 comments on commit f463a41

Please sign in to comment.