-
Notifications
You must be signed in to change notification settings - Fork 7
/
config.go
69 lines (57 loc) · 2.91 KB
/
config.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
// Package cells_sdk provides a ready to use SDK to use the Cells REST API in Go language.
// It also provides some patterns that ease implementation of Go programs that use the SDK.
package cells_sdk
import (
"time"
)
// SdkConfig stores parameters to talk to a running Cells instance REST API via the Go SDK.
type SdkConfig struct {
// Url stores domain name or IP & port to the server.
Url string `json:"url"`
// Username (login) for the currenly configured Pydio Account
User string `json:"user"`
// IdToken might be a personal access Token (generated on your server) or an OAuth2 Token retrieved via the OIDC code flow
IdToken string `json:"idToken,omitempty"`
// OIDC Code Flow additional info
RefreshToken string `json:"refreshToken,omitempty"`
TokenExpiresAt int `json:"tokenExpiresAt,omitempty"`
// Password for client credential authentification (Legacy, less secure)
Password string `json:"password,omitempty"`
// SkipVerify tells the transport to ignore expired or self-signed TLS certificates
SkipVerify bool `json:"skipVerify"`
// UseTokenCache flags wether we should rely on a local cache to avoid retrieving a new JWT token at each request.
// It is useful to *not* use the cache when running connection tests for instance.
UseTokenCache bool `json:"useTokenCache"`
// Optional list of headers to override in requests, typically User-Agent
CustomHeaders map[string]string
}
// Make SdkConfig implement the TokenProvider interface
// Retrieve simply returns the ID token that is currently held in the conf.
func (s *SdkConfig) Retrieve() (string, error) {
// fmt.Println("[Debug] Retrieving token: [", s.IdToken, "], Expires at:", time.Unix(int64(s.TokenExpiresAt), 0), "\n ")
return s.IdToken, nil
}
// Expired checks if expiration time is in less than 10 seconds or already passed.
func (s *SdkConfig) Expired() bool {
isExpired := time.Now().After(time.Unix(int64(s.TokenExpiresAt), 0).Add(-10 * time.Second))
// fmt.Println("[Debug] Checking validity of [", s.IdToken, "], expired =", isExpired, "\n ")
return isExpired
}
// S3Config stores connection parameters to a running Cells instance S3 gateway via the AWS SDK for Go.
type S3Config struct {
// Bucket name, usually io.
Bucket string `json:"bucket"`
// Endpoint overrides the default URL generated by the S3 SDK from the bucket name.
Endpoint string `json:"enpoint"`
// Region param, usually us-east-1
Region string `json:"region"`
// ApiKey is used by the Cells SDK to transmit the JWT token.
ApiKey string `json:"apiKey"`
// ApiSecret identifies this client.
ApiSecret string `json:"apiSecret"`
// Set to true to rather use legacy mode (JWT Auth is transmitted via custom 'X-Pydio-Bearer' header).
UsePydioSpecificHeader bool `json:"usePydioSpecificHeader"`
// IsDebug is a convenience legacy flag to add some logging to this S3 client.
// Should be cleaned as soon as we defined the logging strategy for this repo.
IsDebug bool `json:"isDebug"`
}