func checkConnection()

in controllers/integrationsecret/integrationsecret_controller.go [138:182]


func checkConnection(ctx context.Context, secret *corev1.Secret) error {
	var (
		path string
		req  *resty.Request
	)

	switch secret.GetLabels()[integrationSecretTypeLabel] {
	case "sonar":
		path = "/api/system/ping"
		req = newRequest(ctx, string(secret.Data["url"])).SetBasicAuth(string(secret.Data["token"]), "")
	case "nexus":
		path = "/service/rest/v1/status"
		req = newRequestWithAuth(ctx, secret)
	case "dependency-track":
		path = "/api/v1/team/self"
		req = newRequest(ctx, string(secret.Data["url"])).SetHeader("X-Api-Key", string(secret.Data["token"]))
	case "defectdojo":
		path = "/api/v2/user_profile"
		req = newRequest(ctx, string(secret.Data["url"])).SetHeader("Authorization", "Token "+string(secret.Data["token"]))
	case "registry":
		return checkRegistry(ctx, secret)
	case "argocd":
		path = "/api/v1/projects"
		req = newRequest(ctx, string(secret.Data["url"])).SetHeader("Authorization", "Bearer "+string(secret.Data["token"]))
	case "chat-assistant":
		return checkCodemie(ctx, secret)
	default:
		path = "/"
		req = newRequest(ctx, string(secret.Data["url"]))
	}

	log := ctrl.LoggerFrom(ctx).WithValues(logKeyUrl, req.URL+path)
	log.Info("Making request")

	resp, err := req.Get(path)
	if err != nil {
		return fmt.Errorf("%w", err)
	}

	if !resp.IsSuccess() {
		return fmt.Errorf("http status code %s", resp.Status())
	}

	return nil
}