-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.go
33 lines (28 loc) · 986 Bytes
/
auth.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
// Copyright 2024 cloudeng llc. All rights reserved.
// Use of this source code is governed by the Apache-2.0
// license that can be found in the LICENSE file.
package crawlindex
import (
"cloudeng.io/webapi/operations/apitokens"
)
type AuthFileFlag struct {
AuthFile string `subcmd:"glean-auth,$HOME/.glean-auth.yaml,'file containing authentication tokens for glean instances'"`
}
type Auth []struct {
Name string `yaml:"name" cmd:"name of the glean token instance"`
Auth struct {
BearerToken string `yaml:"indexing_token" cmd:"indexing token for the glean instance"`
ClientBearerToken string `yaml:"client_token" cmd:"client bearer token for the glean instance"`
}
}
func (a Auth) TokensForName(name, domain string) (indexingToken, clientToken *apitokens.T) {
if len(name) == 0 {
name = domain
}
for _, cfg := range a {
if cfg.Name == name {
return apitokens.New(cfg.Auth.BearerToken), apitokens.New(cfg.Auth.ClientBearerToken)
}
}
return nil, nil
}