Repository navigation
Expand file tree
/
Copy pathfetch_workspace.go
More file actions
59 lines (45 loc) · 1.65 KB
/
Copy pathfetch_workspace.go
File metadata and controls
59 lines (45 loc) · 1.65 KB
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
package main
import (
"context"
"log"
"net/http"
"os"
_ "github.com/joho/godotenv/autoload"
"github.com/project-kessel/kessel-sdk-go/kessel/auth"
v2 "github.com/project-kessel/kessel-sdk-go/kessel/rbac/v2"
)
func fetchWorkspace() {
ctx := context.Background()
discovered, err := auth.FetchOIDCDiscovery(ctx, os.Getenv("AUTH_DISCOVERY_ISSUER_URL"), auth.FetchOIDCDiscoveryOptions{
HttpClient: nil, // Optionally specify an http client - defaults to http.DefaultClient
})
if err != nil {
panic(err)
}
oauthCredentials := auth.NewOAuth2ClientCredentials(os.Getenv("AUTH_CLIENT_ID"), os.Getenv("AUTH_CLIENT_SECRET"), discovered.TokenEndpoint)
// GET /api/rbac/v2/workspaces/?type=default&with_ancestry=true
// with_ancestry=true is sent by default so fallback workspaces are
// included even without explicit inventory permission.
defaultWorkspace, err := v2.FetchDefaultWorkspace(ctx, "http://localhost:8000", "12345", v2.FetchWorkspaceOptions{
HttpClient: http.DefaultClient,
Auth: auth.OAuth2AuthRequest(&oauthCredentials, auth.OAuth2AuthRequestOptions{
HttpClient: http.DefaultClient,
}),
})
if err != nil {
panic(err)
}
log.Printf("Found default Workspace: %+v", defaultWorkspace)
// GET /api/rbac/v2/workspaces/?type=root&with_ancestry=true
rootWorkspace, err := v2.FetchRootWorkspace(ctx, "http://localhost:8000", "12345", v2.FetchWorkspaceOptions{
HttpClient: http.DefaultClient,
Auth: auth.OAuth2AuthRequest(&oauthCredentials, auth.OAuth2AuthRequestOptions{
HttpClient: http.DefaultClient,
}),
})
if err != nil {
panic(err)
}
log.Printf("Found root Workspace: %+v", rootWorkspace)
}
func main() { fetchWorkspace() }