-
Notifications
You must be signed in to change notification settings - Fork 8
/
edge_access.go
94 lines (81 loc) · 2.44 KB
/
edge_access.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
89
90
91
92
93
94
// Copyright (C) 2021 Storj Labs, Inc.
// See LICENSE for copying information.
// in uplink "edge" is a separate package but it's unclear if that is possible in uplink-c
package main
// #include "uplink_definitions.h"
import "C"
import (
"context"
"unsafe"
"storj.io/uplink/edge"
)
// edge_register_access gets credentials for the Storj-hosted Gateway-mt and linkshare service.
// All files uploaded under the Access are then accessible via those services.
//
//export edge_register_access
func edge_register_access(
config C.EdgeConfig,
access *C.UplinkAccess,
options *C.EdgeRegisterAccessOptions,
) C.EdgeCredentialsResult {
goConfig := edge.Config{
AuthServiceAddress: C.GoString(config.auth_service_address),
CertificatePEM: []byte(C.GoString(config.certificate_pem)),
InsecureUnencryptedConnection: bool(config.insecure_unencrypted_connection),
}
if options == nil {
options = &C.EdgeRegisterAccessOptions{}
}
goOptions := edge.RegisterAccessOptions{
Public: bool(options.is_public),
}
goAccess, ok := universe.Get(access._handle).(*Access)
if !ok {
return C.EdgeCredentialsResult{
error: mallocError(ErrInvalidHandle.New("access")),
}
}
ctx := context.Background()
goCredentials, err := goConfig.RegisterAccess(
ctx,
goAccess.Access,
&goOptions,
)
return C.EdgeCredentialsResult{
error: mallocError(err),
credentials: mallocEdgeCredentials(goCredentials),
}
}
//export edge_free_credentials_result
func edge_free_credentials_result(result C.EdgeCredentialsResult) {
uplink_free_error(result.error)
edge_free_credentials(result.credentials)
}
//export edge_free_credentials
func edge_free_credentials(credentials *C.EdgeCredentials) {
if credentials == nil {
return
}
defer C.free(unsafe.Pointer(credentials))
if credentials.access_key_id != nil {
C.free(unsafe.Pointer(credentials.access_key_id))
}
if credentials.secret_key != nil {
C.free(unsafe.Pointer(credentials.secret_key))
}
if credentials.endpoint != nil {
C.free(unsafe.Pointer(credentials.endpoint))
}
}
func mallocEdgeCredentials(credentials *edge.Credentials) *C.EdgeCredentials {
if credentials == nil {
return nil
}
cCredentials := (*C.EdgeCredentials)(calloc(1, C.sizeof_EdgeCredentials))
*cCredentials = C.EdgeCredentials{
access_key_id: C.CString(credentials.AccessKeyID),
secret_key: C.CString(credentials.SecretKey),
endpoint: C.CString(credentials.Endpoint),
}
return cCredentials
}