2020-10-19 12:11:25 +01:00
|
|
|
// Copyright (C) 2020 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2020-11-09 15:22:30 +00:00
|
|
|
package apikeys
|
2020-10-19 12:11:25 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/zeebo/errs"
|
2020-12-26 01:16:43 +00:00
|
|
|
|
|
|
|
"storj.io/storj/private/multinodeauth"
|
2020-10-19 12:11:25 +01:00
|
|
|
)
|
|
|
|
|
2020-12-26 01:16:43 +00:00
|
|
|
// ErrNoAPIKey represents no api key error.
|
2021-04-28 09:06:17 +01:00
|
|
|
var ErrNoAPIKey = errs.Class("no api key")
|
2020-10-19 12:11:25 +01:00
|
|
|
|
2020-12-26 01:16:43 +00:00
|
|
|
// DB is interface for working with api keys.
|
2020-10-19 12:11:25 +01:00
|
|
|
//
|
|
|
|
// architecture: Database
|
|
|
|
type DB interface {
|
2020-12-26 01:16:43 +00:00
|
|
|
// Store stores api key into db.
|
|
|
|
Store(ctx context.Context, apiKey APIKey) error
|
2020-10-19 12:11:25 +01:00
|
|
|
|
2020-12-26 01:16:43 +00:00
|
|
|
// Check checks if api key exists in db by secret.
|
|
|
|
Check(ctx context.Context, secret multinodeauth.Secret) error
|
2020-10-19 12:11:25 +01:00
|
|
|
|
2020-12-26 01:16:43 +00:00
|
|
|
// Revoke removes api key from db.
|
|
|
|
Revoke(ctx context.Context, secret multinodeauth.Secret) error
|
2020-10-19 12:11:25 +01:00
|
|
|
}
|
|
|
|
|
2020-12-26 01:16:43 +00:00
|
|
|
// APIKey describing api key in the database.
|
2020-10-19 12:11:25 +01:00
|
|
|
type APIKey struct {
|
2020-12-26 01:16:43 +00:00
|
|
|
// APIKeys is PK of the table and keeps unique value sno api key.
|
|
|
|
Secret multinodeauth.Secret
|
2020-10-19 12:11:25 +01:00
|
|
|
|
|
|
|
CreatedAt time.Time `json:"createdAt"`
|
|
|
|
}
|