Skip to content

Commit

Permalink
key pair and venafi connection modes now use gzip compression
Browse files Browse the repository at this point in the history
  • Loading branch information
maelvls committed Oct 15, 2024
1 parent 64a9255 commit 27cf43e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
10 changes: 9 additions & 1 deletion pkg/client/client_venafi_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package client

import (
"bytes"
"compress/gzip"
"crypto"
"crypto/ecdsa"
"crypto/ed25519"
Expand Down Expand Up @@ -260,13 +261,20 @@ func (c *VenafiCloudClient) Post(path string, body io.Reader) (*http.Response, e
return nil, err
}

req, err := http.NewRequest(http.MethodPost, fullURL(c.baseURL, path), body)
encodedBody := &bytes.Buffer{}
gz := gzip.NewWriter(encodedBody)
if _, err := io.Copy(gz, body); err != nil {
return nil, err
}

req, err := http.NewRequest(http.MethodPost, fullURL(c.baseURL, path), encodedBody)
if err != nil {
return nil, err
}

req.Header.Set("Accept", "application/json")
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Content-Encoding", "gzip")

if len(token.accessToken) > 0 {
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token.accessToken))
Expand Down
8 changes: 6 additions & 2 deletions pkg/client/client_venconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package client

import (
"bytes"
"compress/gzip"
"context"
"crypto/x509"
"encoding/base64"
Expand Down Expand Up @@ -157,15 +158,18 @@ func (c *VenConnClient) PostDataReadingsWithOptions(readings []*api.DataReading,
DataGatherTime: time.Now().UTC(),
DataReadings: readings,
}
data, err := json.Marshal(payload)

encodedBody := &bytes.Buffer{}
gz := gzip.NewWriter(encodedBody)
err = json.NewEncoder(gz).Encode(payload)
if err != nil {
return err
}

// The path parameter "no" is a dummy parameter to make the Venafi Cloud
// backend happy. This parameter, named `uploaderID` in the backend, is not
// actually used by the backend.
req, err := http.NewRequest(http.MethodPost, fullURL(token.BaseURL, "/v1/tlspk/upload/clusterdata/no"), bytes.NewBuffer(data))
req, err := http.NewRequest(http.MethodPost, fullURL(token.BaseURL, "/v1/tlspk/upload/clusterdata/no"), encodedBody)
if err != nil {
return err
}
Expand Down

0 comments on commit 27cf43e

Please sign in to comment.