sync: migrate ai-operator to Gitea (2026-08-10)
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package ari
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
const resourcesPath = "api-docs/resources.json"
|
||||
|
||||
func (c *Client) HealthCheck(ctx context.Context) HealthStatus {
|
||||
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
defer cancel()
|
||||
|
||||
status := HealthStatus{ResourcesEndpoint: c.endpoint(resourcesPath)}
|
||||
|
||||
authResp, err := c.AuthenticatedGET(ctx, resourcesPath)
|
||||
if err != nil {
|
||||
status.Error = "authenticated ARI request failed: " + err.Error()
|
||||
return status
|
||||
}
|
||||
drainAndClose(authResp)
|
||||
if authResp.StatusCode == 200 {
|
||||
status.AuthenticatedOK = true
|
||||
} else {
|
||||
status.Error = statusError("authenticated ARI request", authResp.StatusCode, 200)
|
||||
return status
|
||||
}
|
||||
|
||||
unauthResp, err := c.UnauthenticatedGET(ctx, resourcesPath)
|
||||
if err != nil {
|
||||
status.Error = "unauthenticated ARI request failed: " + err.Error()
|
||||
return status
|
||||
}
|
||||
drainAndClose(unauthResp)
|
||||
if unauthResp.StatusCode == 401 {
|
||||
status.UnauthenticatedReturns401 = true
|
||||
} else {
|
||||
status.Error = statusError("unauthenticated ARI request", unauthResp.StatusCode, 401)
|
||||
}
|
||||
status.ResourcesEndpoint = strings.Replace(status.ResourcesEndpoint, "///", "//", 1)
|
||||
return status
|
||||
}
|
||||
Reference in New Issue
Block a user