Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTDC-21392 updated readme doc with latest instructions. #3

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ Certificate bundle downloaded from KeyControl needs to be unpacked before it can
- secrets
providers:
- kms:
apiVersion: v2
name: KeyControlKmsPlugin
endpoint: unix:///etc/kubernetes/kmsplugin.sock
timeout: 3s
Expand Down
24 changes: 12 additions & 12 deletions utils/http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"crypto/x509"
"encoding/json"
"errors"
"fmt"
"io"
"kms-plugin/models"
"log"
"net/http"
"os"
"time"
Expand Down Expand Up @@ -51,30 +51,30 @@ func (c *KeyControlKmsHttpClient) doRequest(url string, jsonData map[string]stri

jsonVal, err := json.Marshal(jsonData)
if err != nil {
log.Fatal(err)
return nil, err
Logger.Error(err)
return nil, fmt.Errorf("failed to process request in provided kms, detail : %s", err)
}

req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonVal))
if err != nil {
log.Fatal(err)
return nil, err
Logger.Error(err)
return nil, fmt.Errorf("failed to process request in provided kms, detail : %s", err)
}
req.Header.Set("Content-Type", "application/json")

r, err := c.client.Do(req)
if err != nil {
log.Fatal(err)
return nil, err
Logger.Error(err)
return nil, fmt.Errorf("failed to process request in provided kms, detail : %s", err)
}
defer r.Body.Close()

if r.StatusCode != 200 {
return nil, errors.New("request failed")
return nil, fmt.Errorf("failed to process request in provided kms, detail : %s", errors.New("request failed"))
}
body, err := io.ReadAll(r.Body)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to process request in provided kms, detail : %s", err)
}
return body, nil
}
Expand Down Expand Up @@ -108,14 +108,14 @@ func (c *KeyControlKmsHttpClient) Decrypt(ciphertext string) (string, error) {
decryptUrl := "https://" + c.config.KmsServer + "/api/1.0/symm_keyid/op/decrypt/"
res, err := c.doRequest(decryptUrl, jsonData)
if err != nil {
log.Fatal(err)
return "", err
Logger.Error(err)
return "", fmt.Errorf("failed to process request in provided kms, detail : %s", err)
}

var data models.DecResponse
err = json.Unmarshal(res, &data)
if err != nil {
return "", err
return "", fmt.Errorf("failed to process request in provided kms, detail : %s", err)
}

return data.PlainText, nil
Expand Down