forked from theopenlane/core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstallation.go
More file actions
38 lines (30 loc) · 1.04 KB
/
Copy pathinstallation.go
File metadata and controls
38 lines (30 loc) · 1.04 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
package authentik
import (
"context"
"github.com/theopenlane/core/internal/integrations/types"
authentikSDK "goauthentik.io/api/v3"
)
// resolveInstallationMetadata derives Authentik instance metadata from the persisted credential
func resolveInstallationMetadata(ctx context.Context, req types.InstallationRequest) (InstallationMetadata, bool, error) {
cred, err := resolveCredential(req.Credentials)
if err != nil {
return InstallationMetadata{}, false, ErrCredentialDecode
}
if cred.Token == "" || cred.BaseURL == "" {
return InstallationMetadata{}, false, nil
}
client, err := Client{}.Build(ctx, types.ClientBuildRequest{Credentials: req.Credentials})
if err != nil {
return InstallationMetadata{}, false, err
}
apiClient := client.(*authentikSDK.APIClient)
info, _, err := apiClient.AdminApi.AdminSystemRetrieve(ctx).Execute()
if err != nil {
return InstallationMetadata{}, false, ErrHealthCheckFailed
}
return InstallationMetadata{
Brand: info.GetBrand(),
Host: info.GetHttpHost(),
BaseURL: cred.BaseURL,
}, true, nil
}