mirror of
https://github.com/mainflux/mainflux.git
synced 2025-05-02 22:17:10 +08:00

* initial commit Signed-off-by: rodneyosodo <socials@rodneyosodo.com> * Fix CI Test Errors Signed-off-by: rodneyosodo <blackd0t@protonmail.com> --------- Signed-off-by: rodneyosodo <socials@rodneyosodo.com> Signed-off-by: rodneyosodo <blackd0t@protonmail.com> Co-authored-by: rodneyosodo <socials@rodneyosodo.com> Co-authored-by: Drasko DRASKOVIC <drasko.draskovic@gmail.com>
69 lines
1.1 KiB
Go
69 lines
1.1 KiB
Go
// Copyright (c) Mainflux
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package keys
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/mainflux/mainflux/auth"
|
|
"github.com/mainflux/mainflux/internal/apiutil"
|
|
)
|
|
|
|
type issueKeyReq struct {
|
|
token string
|
|
Type uint32 `json:"type,omitempty"`
|
|
Duration time.Duration `json:"duration,omitempty"`
|
|
}
|
|
|
|
// It is not possible to issue Reset key using HTTP API.
|
|
func (req issueKeyReq) validate() error {
|
|
if req.token == "" {
|
|
return apiutil.ErrBearerToken
|
|
}
|
|
|
|
if req.Type != auth.LoginKey &&
|
|
req.Type != auth.RecoveryKey &&
|
|
req.Type != auth.APIKey {
|
|
return apiutil.ErrInvalidAPIKey
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type keyReq struct {
|
|
token string
|
|
id string
|
|
}
|
|
|
|
func (req keyReq) validate() error {
|
|
if req.token == "" {
|
|
return apiutil.ErrBearerToken
|
|
}
|
|
|
|
if req.id == "" {
|
|
return apiutil.ErrMissingID
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type listKeysReq struct {
|
|
token string
|
|
subject string
|
|
keyType uint32
|
|
offset uint64
|
|
limit uint64
|
|
}
|
|
|
|
func (req listKeysReq) validate() error {
|
|
if req.token == "" {
|
|
return apiutil.ErrBearerToken
|
|
}
|
|
|
|
if req.limit < 1 {
|
|
return apiutil.ErrLimitSize
|
|
}
|
|
|
|
return nil
|
|
}
|