Update primary error functions to take a context, deprecate old functions (#1358)

* add new error funcs which take a ctx and deprecate existing funcs

* use context where available when writing error events

* remove circular internal/errors pkg dep

* suppress some chatty errors using errors.WithoutEvent()

* convert auth oidc funcs to take context where needed to write events

Co-authored-by: Jim <jlambert@hashicorp.com>
This commit is contained in:
s-christoffandJim authored and GitHub committed 2021-07-29 20:52:56 -04:00
1 parent 02ff2db66e
commit 6b78108ecf
227 files changed
+3945 -3736

No files matched your search

+8 -8
View File
@@ -74,7 +74,7 @@ func (at *AuthToken) encrypt(ctx context.Context, cipher wrapping.Wrapper) error
const op = "authtoken.(writableAuthToken).encrypt"
// structwrapping doesn't support embedding, so we'll pass in the store.Entry directly
if err := structwrapping.WrapStruct(ctx, cipher, at.AuthToken, nil); err != nil {
return errors.Wrap(err, op, errors.WithCode(errors.Encrypt))
return errors.WrapDeprecated(err, op, errors.WithCode(errors.Encrypt))
}
at.KeyId = cipher.KeyID()
return nil
@@ -85,7 +85,7 @@ func (at *AuthToken) decrypt(ctx context.Context, cipher wrapping.Wrapper) error
const op = "authtoken.(AuthToken).decrypt"
// structwrapping doesn't support embedding, so we'll pass in the store.Entry directly
if err := structwrapping.UnwrapStruct(ctx, cipher, at.AuthToken, nil); err != nil {
return errors.Wrap(err, op, errors.WithCode(errors.Decrypt))
return errors.WrapDeprecated(err, op, errors.WithCode(errors.Decrypt))
}
return nil
}
@@ -102,7 +102,7 @@ func NewAuthTokenId() (string, error) {
const op = "authtoken.newAuthTokenId"
id, err := db.NewPublicId(AuthTokenPrefix)
if err != nil {
return "", errors.Wrap(err, op)
return "", errors.WrapDeprecated(err, op)
}
return id, nil
}
@@ -113,7 +113,7 @@ func newAuthToken(opt ...Option) (*AuthToken, error) {
const op = "authtoken.newAuthToken"
token, err := base62.Random(tokenLength)
if err != nil {
return nil, errors.Wrap(err, op, errors.WithCode(errors.Io))
return nil, errors.WrapDeprecated(err, op, errors.WithCode(errors.Io))
}
opts := getOpts(opt...)
@@ -139,22 +139,22 @@ func EncryptToken(ctx context.Context, kmsCache *kms.Kms, scopeId, publicId, tok
marshaledS1Info, err := proto.Marshal(s1Info)
if err != nil {
return "", errors.Wrap(err, op, errors.WithMsg("marshaling encrypted token"), errors.WithCode(errors.Encode))
return "", errors.WrapDeprecated(err, op, errors.WithMsg("marshaling encrypted token"), errors.WithCode(errors.Encode))
}
tokenWrapper, err := kmsCache.GetWrapper(ctx, scopeId, kms.KeyPurposeTokens)
if err != nil {
return "", errors.Wrap(err, op, errors.WithMsg("unable to get wrapper"))
return "", errors.WrapDeprecated(err, op, errors.WithMsg("unable to get wrapper"))
}
blobInfo, err := tokenWrapper.Encrypt(ctx, []byte(marshaledS1Info), []byte(publicId))
if err != nil {
return "", errors.Wrap(err, op, errors.WithMsg("marshaling token info"), errors.WithCode(errors.Encrypt))
return "", errors.WrapDeprecated(err, op, errors.WithMsg("marshaling token info"), errors.WithCode(errors.Encrypt))
}
marshaledBlob, err := proto.Marshal(blobInfo)
if err != nil {
return "", errors.Wrap(err, op, errors.WithMsg("marshaling encrypted token"), errors.WithCode(errors.Encode))
return "", errors.WrapDeprecated(err, op, errors.WithMsg("marshaling encrypted token"), errors.WithCode(errors.Encode))
}
encoded := base58.FastBase58Encoding(marshaledBlob)