Skip to content

Commit

Permalink
add logging example (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
fairclothjm authored Oct 20, 2023
1 parent 58a6c18 commit 0c0a98b
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cmd/vault-auth-plugin-example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,17 @@ func Backend(c *logical.BackendConfig) *backend {
}

func (b *backend) pathAuthLogin(_ context.Context, req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
b.Logger().Debug("login requested")

password := d.Get("password").(string)

if subtle.ConstantTimeCompare([]byte(password), []byte("super-secret-password")) != 1 {
b.Logger().Error("login failed", "err", logical.ErrPermissionDenied.Error())
return nil, logical.ErrPermissionDenied
}

b.Logger().Trace("login succeeded")

// Compose the response
return &logical.Response{
Auth: &logical.Auth{
Expand All @@ -107,10 +112,14 @@ func (b *backend) pathAuthLogin(_ context.Context, req *logical.Request, d *fram
}

func (b *backend) pathAuthRenew(ctx context.Context, req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
b.Logger().Debug("auth renew requested")
if req.Auth == nil {
b.Logger().Error("login failed")
return nil, errors.New("request auth was nil")
}

b.Logger().Trace("auth renew succeeded")

secretValue := req.Auth.InternalData["secret_value"].(string)
if secretValue != "abcd1234" {
return nil, errors.New("internal data does not match")
Expand Down

0 comments on commit 0c0a98b

Please sign in to comment.