-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcape.go
56 lines (44 loc) · 1.14 KB
/
cape.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
package cli
import (
"encoding/json"
"io"
"os"
"golang.org/x/oauth2"
"github.com/capeprivacy/attest/attest"
)
type Checksums struct {
Input []byte `json:"input"`
Function []byte `json:"function"`
Output []byte `json:"output"`
}
type RunResult struct {
Type string `json:"type"`
Message []byte `json:"message"`
Checksums Checksums `json:"checksums"`
SignedChecksums []byte `json:"signed_checksums"`
DecodedAttestationDocument *attest.AttestationDoc `json:"decoded_attestation_document"`
RawAttestationDocument []byte `json:"raw_attestation_document"`
}
func TokenFromFile(path string) (*oauth2.Token, error) {
f, err := os.Open(path)
if err != nil {
return nil, err
}
defer f.Close()
return TokenFromReader(f)
}
func TokenFromReader(r io.Reader) (*oauth2.Token, error) {
bytes, err := io.ReadAll(r)
if err != nil {
return nil, err
}
var tok *oauth2.Token
if err := json.Unmarshal(bytes, &tok); err != nil {
return nil, err
}
var raw map[string]interface{}
if err := json.Unmarshal(bytes, &raw); err != nil {
return nil, err
}
return tok.WithExtra(raw), nil
}