-
Notifications
You must be signed in to change notification settings - Fork 8
/
config.go
88 lines (74 loc) · 2.23 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright (C) 2020 Storj Labs, Inc.
// See LICENSE for copying information.
package main
// #include "uplink_definitions.h"
import "C"
import (
"context"
"time"
"storj.io/uplink"
)
// uplink_config_request_access_with_passphrase requests satellite for a new access grant using a passhprase.
//
//export uplink_config_request_access_with_passphrase
func uplink_config_request_access_with_passphrase(config C.UplinkConfig, satellite_address, api_key, passphrase *C.uplink_const_char) C.UplinkAccessResult { //nolint:golint
if satellite_address == nil {
return C.UplinkAccessResult{
error: mallocError(ErrNull.New("satellite_address")),
}
}
if api_key == nil {
return C.UplinkAccessResult{
error: mallocError(ErrNull.New("api_key")),
}
}
if passphrase == nil {
return C.UplinkAccessResult{
error: mallocError(ErrNull.New("passphrase")),
}
}
ctx := context.Background()
cfg := uplinkConfig(config)
access, err := cfg.RequestAccessWithPassphrase(ctx, C.GoString(satellite_address), C.GoString(api_key), C.GoString(passphrase))
if err != nil {
return C.UplinkAccessResult{
error: mallocError(err),
}
}
return C.UplinkAccessResult{
access: (*C.UplinkAccess)(mallocHandle(universe.Add(&Access{access}))),
}
}
// uplink_config_open_project opens project using access grant.
//
//export uplink_config_open_project
func uplink_config_open_project(config C.UplinkConfig, access *C.UplinkAccess) C.UplinkProjectResult {
if access == nil {
return C.UplinkProjectResult{
error: mallocError(ErrNull.New("access")),
}
}
acc, ok := universe.Get(access._handle).(*Access)
if !ok {
return C.UplinkProjectResult{
error: mallocError(ErrInvalidHandle.New("Access")),
}
}
scope := rootScope(C.GoString(config.temp_directory))
cfg := uplinkConfig(config)
proj, err := cfg.OpenProject(scope.ctx, acc.Access)
if err != nil {
return C.UplinkProjectResult{
error: mallocError(err),
}
}
return C.UplinkProjectResult{
project: (*C.UplinkProject)(mallocHandle(universe.Add(&Project{scope, proj}))),
}
}
func uplinkConfig(config C.UplinkConfig) uplink.Config {
return uplink.Config{
UserAgent: C.GoString(config.user_agent),
DialTimeout: time.Duration(config.dial_timeout_milliseconds) * time.Millisecond,
}
}