-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
75 lines (61 loc) · 1.47 KB
/
main.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
69
70
71
72
73
74
75
package main
import (
"context"
"flag"
"fmt"
"os"
"strings"
internal_auth "github.com/bloqs-sites/bloqsenjin/internal/auth"
"github.com/bloqs-sites/bloqsenjin/internal/db"
"github.com/bloqs-sites/bloqsenjin/pkg/auth"
"github.com/bloqs-sites/bloqsenjin/pkg/conf"
"github.com/bloqs-sites/bloqsenjin/proto"
"github.com/santhosh-tekuri/jsonschema/v5"
)
var (
email = flag.String("email", "", "")
password = flag.String("password", "", "")
)
func init() {
flag.Parse()
if email == nil || *email == "" {
panic("no email specified")
}
if password == nil || *password == "" {
panic("no email specified")
}
if err := conf.Compile(); err != nil {
switch err := err.(type) {
case jsonschema.InvalidJSONTypeError:
panic(err)
}
}
}
func main() {
ctx := context.Background()
a, err := authSrv(ctx)
if err != nil {
panic(err)
}
user := &proto.Credentials_Basic{
Basic: &proto.Credentials_BasicCredentials{
Email: *email,
Password: *password,
},
}
creds := &proto.Credentials{Credentials: user}
if err = a.SignInBasic(ctx, user); err != nil {
panic(err)
}
if err = a.GrantSuper(ctx, creds); err != nil {
a.SignOutBasic(ctx, user)
panic(err)
}
}
func authSrv(ctx context.Context) (auth.Auther, error) {
creds, err := db.NewMySQL(ctx, strings.TrimSpace(os.Getenv("BLOQS_AUTH_MYSQL_DSN")))
if err != nil {
return nil, fmt.Errorf("error creating DB instance of type `%T`:\t%s", creds, err)
}
return internal_auth.NewBloqsAuther(ctx, creds)
}