forked from influxdata/influxdb
-
Notifications
You must be signed in to change notification settings - Fork 2
/
onboarding.go
68 lines (58 loc) · 1.83 KB
/
onboarding.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package influxdb
import (
"context"
"time"
"github.com/influxdata/influxdb/v2/kit/platform/errors"
)
// OnboardingService represents a service for the first run.
type OnboardingService interface {
// IsOnboarding determine if onboarding request is allowed.
IsOnboarding(ctx context.Context) (bool, error)
// OnboardInitialUser creates the initial org/user/bucket in the DB.
OnboardInitialUser(ctx context.Context, req *OnboardingRequest) (*OnboardingResults, error)
}
// OnboardingResults is a group of elements required for first run.
type OnboardingResults struct {
User *User `json:"user"`
Org *Organization `json:"org"`
Bucket *Bucket `json:"bucket"`
Auth *Authorization `json:"auth"`
}
// OnboardingRequest is the request
// to setup defaults.
type OnboardingRequest struct {
User string `json:"username"`
Password string `json:"password"`
Org string `json:"org"`
Bucket string `json:"bucket"`
RetentionPeriodSeconds int64 `json:"retentionPeriodSeconds,omitempty"`
RetentionPeriodDeprecated time.Duration `json:"retentionPeriodHrs,omitempty"`
Token string `json:"token,omitempty"`
}
func (r *OnboardingRequest) Valid() error {
if r.User == "" {
return &errors.Error{
Code: errors.EEmptyValue,
Msg: "username is empty",
}
}
if r.Org == "" {
return &errors.Error{
Code: errors.EEmptyValue,
Msg: "org name is empty",
}
}
if r.Bucket == "" {
return &errors.Error{
Code: errors.EEmptyValue,
Msg: "bucket name is empty",
}
}
return nil
}
func (r *OnboardingRequest) RetentionPeriod() time.Duration {
if r.RetentionPeriodSeconds > 0 {
return time.Duration(r.RetentionPeriodSeconds) * time.Second
}
return r.RetentionPeriodDeprecated
}