mirror of
https://github.com/hanzoai/cd.git
synced 2026-10-30 14:56:45 +00:00
Drops the Argo/ArgoCD prefix from our own const, type and field names (ArgoCDConfigMapName -> ConfigMapName, ArgoCDSettings -> Settings, ArgoCDServer -> Server, HeaderArgoCD* -> HeaderCD*, the argocd-manager RBAC names, the CLI-facing Env* aliases, and the three separately scoped ArgoCDNamespace test/CLI defaults) and reflows the surrounding comments and log/help text from Argo CD to Hanzo CD. Runtime string values are untouched (still hanzocd-*, argo-cd-cli, argo-cd, etc.) — renaming those is a live ConfigMap/Secret/service-name and OAuth-client-ID change that has to land with the manifests and Hanzo IAM/dex registration together, not silently inside a naming pass. argoproj.io, other real upstream API groups, GitHub issue/PR citations, and external URLs are untouched throughout. Verified with go build ./... and go vet ./... (both clean); go test ./util/... ./controller/... ./server/... has the identical 26/26 pre-existing failing packages before and after (root cause: an unrelated redis-removal regression, not this change — see report).
59 lines
1.4 KiB
Go
59 lines
1.4 KiB
Go
package fixture
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"crypto/tls"
|
|
"encoding/json"
|
|
"io"
|
|
"net/http"
|
|
"net/url"
|
|
|
|
"github.com/hanzoai/cd/common"
|
|
)
|
|
|
|
// DoHttpRequest executes a http request against the Hanzo CD API server
|
|
func DoHttpRequest(method string, path string, host string, data ...byte) (*http.Response, error) { //nolint:revive //FIXME(var-naming)
|
|
reqURL, err := url.Parse(path)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
reqURL.Scheme = "http"
|
|
if host != "" {
|
|
reqURL.Host = host
|
|
} else {
|
|
reqURL.Host = apiServerAddress
|
|
}
|
|
var body io.Reader
|
|
if data != nil {
|
|
body = bytes.NewReader(data)
|
|
}
|
|
req, err := http.NewRequestWithContext(context.Background(), method, reqURL.String(), body)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
req.AddCookie(&http.Cookie{Name: common.AuthCookieName, Value: token})
|
|
req.Header.Set("Content-Type", "application/json")
|
|
|
|
httpClient := &http.Client{
|
|
Transport: &http.Transport{
|
|
TLSClientConfig: &tls.Config{InsecureSkipVerify: IsRemote()},
|
|
},
|
|
}
|
|
|
|
return httpClient.Do(req)
|
|
}
|
|
|
|
// DoHttpJsonRequest executes a http request against the Hanzo CD API server and unmarshals the response body as JSON
|
|
func DoHttpJsonRequest(method string, path string, result any, data ...byte) error { //nolint:revive //FIXME(var-naming)
|
|
resp, err := DoHttpRequest(method, path, "", data...)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
responseData, err := io.ReadAll(resp.Body)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return json.Unmarshal(responseData, result)
|
|
}
|