diff --git a/pkg/agent/run.go b/pkg/agent/run.go index 30673384..b9bffb19 100644 --- a/pkg/agent/run.go +++ b/pkg/agent/run.go @@ -98,7 +98,9 @@ var Prometheus bool // raw resource data of unstructuredList const schemaVersion string = "v2.0.0" -const inClusterNamespacePath = "/var/run/secrets/kubernetes.io/serviceaccount/namespace" +const ( + inClusterNamespacePath = "/var/run/secrets/kubernetes.io/serviceaccount/namespace" +) // Run starts the agent process func Run(cmd *cobra.Command, args []string) { diff --git a/pkg/client/client_venconn.go b/pkg/client/client_venconn.go index ae9593bb..781a1a59 100644 --- a/pkg/client/client_venconn.go +++ b/pkg/client/client_venconn.go @@ -6,11 +6,8 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" - "log" "log/slog" "net/http" - "path/filepath" "time" "github.com/go-logr/logr" @@ -122,7 +119,9 @@ func (c *VenConnClient) PostDataReadings(orgID, clusterID string, readings []*ap return err } - res, err := c.Post(filepath.Join("/api/v1/org", orgID, "datareadings", clusterID), bytes.NewBuffer(data)) + // The path parameter "no" is a dummy parameter that fills in the required + // ":uploaderID" required but not actually used by the Venafi Cloud backend. + res, err := c.Post("/v1/tlspk/upload/clusterdata/no", bytes.NewBuffer(data)) if err != nil { return err } @@ -130,7 +129,7 @@ func (c *VenConnClient) PostDataReadings(orgID, clusterID string, readings []*ap if code := res.StatusCode; code < 200 || code >= 300 { errorContent := "" - body, err := ioutil.ReadAll(res.Body) + body, err := io.ReadAll(res.Body) if err == nil { errorContent = string(body) } @@ -143,11 +142,9 @@ func (c *VenConnClient) PostDataReadings(orgID, clusterID string, readings []*ap // Post performs an HTTP POST request. func (c *VenConnClient) Post(path string, body io.Reader) (*http.Response, error) { - // The VenafiConnection must be in the same namespace as the agent. It can't - log.Printf("Getting Venafi connection details from %s/%s", c.venConnNS, c.venConnName) _, token, err := c.connHandler.Get(context.Background(), c.installNS, auth.Scope{}, types.NamespacedName{Name: c.venConnName, Namespace: c.venConnNS}) if err != nil { - return nil, err + return nil, fmt.Errorf("while loading the VenafiConnection %s/%s: %w", c.venConnNS, c.venConnName, err) } req, err := http.NewRequest(http.MethodPost, fullURL(c.baseURL, path), body)