Files
threshold/internal/iam/repository_scope_storage_policy.go
T
429247f407 [COMPLIANCE] Update Copyright Headers (#6282)
* [COMPLIANCE] Update Copyright and License Headers

* chore: make gen to generate files with copyright headers

* chore: update missed copyright headers

---------

Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
Co-authored-by: Justin Nguyen <justin.nguyen@hashicorp.com>
2026-01-28 11:05:07 -06:00

29 lines
977 B
Go

// Copyright IBM Corp. 2020, 2025
// SPDX-License-Identifier: BUSL-1.1
package iam
import (
"context"
"fmt"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/errors"
)
// setScopeStoragePolicyId fetches the storage policy associated with the given
// scope and sets its StoragePolicyId field if an association does exist. If no
// record is found, a RecordNotFound error is returned.
func setScopeStoragePolicyId(ctx context.Context, r db.Reader, scope *Scope) error {
const op = "iam.setScopeStoragePolicyId"
var policy *ScopePolicyStoragePolicy
if err := r.SearchWhere(ctx, &policy, "scope_id = ?", []any{scope.PublicId}); err != nil {
return errors.Wrap(ctx, err, op)
}
if policy.ScopePolicyStoragePolicy == nil {
return errors.New(ctx, errors.RecordNotFound, op, fmt.Sprintf("%s scope storage policy not found", scope.PublicId), errors.WithoutEvent())
}
scope.StoragePolicyId = policy.GetStoragePolicyId()
return nil
}