Skip to content

Commit

Permalink
venconn: ignore config's venafi-cloud.upload_path and uploader_id
Browse files Browse the repository at this point in the history
  • Loading branch information
maelvls committed Jul 25, 2024
1 parent a186af3 commit 1deb969
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
4 changes: 3 additions & 1 deletion pkg/agent/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
13 changes: 5 additions & 8 deletions pkg/client/client_venconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"log"
"log/slog"
"net/http"
"path/filepath"
"time"

"github.com/go-logr/logr"
Expand Down Expand Up @@ -122,15 +119,17 @@ 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
}
defer res.Body.Close()

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)
}
Expand All @@ -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)
Expand Down

0 comments on commit 1deb969

Please sign in to comment.