storj/satellite/console/consoleauth/apikey.go
Stefan Benten 14a2050b8d pkg/auth: move package to consoleauth
To avoid further name collisions, the very broad named package gets moved into
the consoleauth package where its also mainly being used.

Change-Id: Ie563c9700adbf0553baca2b7b8ba4a1d9c29d144
2020-10-06 14:15:07 +02:00

24 lines
571 B
Go

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package consoleauth
import (
"context"
)
// The key type is unexported to prevent collisions with context keys defined in
// other packages.
type apikey struct{}
// WithAPIKey creates context with api key.
func WithAPIKey(ctx context.Context, key []byte) context.Context {
return context.WithValue(ctx, apikey{}, key)
}
// GetAPIKey returns api key from context is exists.
func GetAPIKey(ctx context.Context) ([]byte, bool) {
key, ok := ctx.Value(apikey{}).([]byte)
return key, ok
}