-
Notifications
You must be signed in to change notification settings - Fork 301
/
oidc.go
43 lines (36 loc) · 861 Bytes
/
oidc.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
package api
import (
"context"
"fmt"
)
type OIDCToken struct {
Token string `json:"token"`
}
type OIDCTokenRequest struct {
Job string
Audience string
Lifetime int
Claims []string
}
func (c *Client) OIDCToken(ctx context.Context, methodReq *OIDCTokenRequest) (*OIDCToken, *Response, error) {
m := &struct {
Audience string `json:"audience,omitempty"`
Lifetime int `json:"lifetime,omitempty"`
Claims []string `json:"claims,omitempty"`
}{
Audience: methodReq.Audience,
Lifetime: methodReq.Lifetime,
Claims: methodReq.Claims,
}
u := fmt.Sprintf("jobs/%s/oidc/tokens", railsPathEscape(methodReq.Job))
httpReq, err := c.newRequest(ctx, "POST", u, m)
if err != nil {
return nil, nil, err
}
t := &OIDCToken{}
resp, err := c.doRequest(httpReq, t)
if err != nil {
return nil, resp, err
}
return t, resp, nil
}