-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathresource_ssh.go
73 lines (61 loc) · 1.5 KB
/
resource_ssh.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
package fly
import (
"context"
"crypto/ed25519"
"strings"
"golang.org/x/crypto/ssh"
)
func (c *Client) GetLoggedCertificates(ctx context.Context, slug string) ([]LoggedCertificate, error) {
req := c.NewRequest(`
query($slug: String!) {
organization(slug: $slug) {
loggedCertificates {
nodes {
root
cert
}
}
}
}
`)
req.Var("slug", slug)
ctx = ctxWithAction(ctx, "get_logged_certificates")
data, err := c.RunWithContext(ctx, req)
if err != nil {
return nil, err
}
return data.Organization.LoggedCertificates.Nodes, nil
}
func (c *Client) IssueSSHCertificate(ctx context.Context, org OrganizationImpl, principals []string, appNames []string, valid_hours *int, publicKey ed25519.PublicKey) (*IssuedCertificate, error) {
req := c.NewRequest(`
mutation($input: IssueCertificateInput!) {
issueCertificate(input: $input) {
certificate, key
}
}
`)
var pubStr string
if len(publicKey) > 0 {
sshPub, err := ssh.NewPublicKey(publicKey)
if err != nil {
return nil, err
}
pubStr = strings.TrimSpace(string(ssh.MarshalAuthorizedKey(sshPub)))
}
inputs := map[string]interface{}{
"organizationId": org.GetID(),
"principals": principals,
"appNames": appNames,
"publicKey": pubStr,
}
if valid_hours != nil {
inputs["validHours"] = *valid_hours
}
req.Var("input", inputs)
ctx = ctxWithAction(ctx, "issue_ssh_certificates")
data, err := c.RunWithContext(ctx, req)
if err != nil {
return nil, err
}
return &data.IssueCertificate, nil
}