Skip to content

Commit

Permalink
Whitespace and minor warnings fixed
Browse files Browse the repository at this point in the history
haf committed Jun 19, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 17c9948 commit 7b2550d
Showing 5 changed files with 42 additions and 40 deletions.
2 changes: 1 addition & 1 deletion sealedsecrets/provider.go
Original file line number Diff line number Diff line change
@@ -227,7 +227,7 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData) (interface{}
cfg.Burst = 100

// Overriding with static configuration
cfg.UserAgent = fmt.Sprintf("HashiCorp/1.0 Terraform")
cfg.UserAgent = "HashiCorp/1.0 Terraform"

if v, ok := k8sGetOk(d, "host"); ok {
cfg.Host = v.(string)
1 change: 1 addition & 0 deletions sealedsecrets/resource_secret.go
Original file line number Diff line number Diff line change
@@ -66,6 +66,7 @@ func resourceSecret() *schema.Resource {

func resourceSecretCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Printf("resourceSecretCreate")

// 1. Generate manifest
sealedSecretManifest, err := createSealedSecret(d, m.(*kubectl.KubeProvider))
if err != nil {
32 changes: 17 additions & 15 deletions utils/kubectl/kubectl.go
Original file line number Diff line number Diff line change
@@ -4,21 +4,22 @@ import (
"context"
"encoding/json"
"fmt"
"regexp"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"io/ioutil"
"k8s.io/cli-runtime/pkg/printers"
"os"
"time"
"log"
"os"
"regexp"
"strings"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"k8s.io/cli-runtime/pkg/printers"

"k8s.io/cli-runtime/pkg/genericclioptions"
k8sresource "k8s.io/cli-runtime/pkg/resource"
diskcached "k8s.io/client-go/discovery/cached/disk"
apiregistration "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1"
"k8s.io/kubectl/pkg/cmd/apply"
k8sdelete "k8s.io/kubectl/pkg/cmd/delete"
diskcached "k8s.io/client-go/discovery/cached/disk"

"github.com/icza/dyno"

@@ -29,16 +30,17 @@ import (
k8sschema "k8s.io/apimachinery/pkg/runtime/schema"
yamlWriter "sigs.k8s.io/yaml"

"path/filepath"

"github.com/mitchellh/go-homedir"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/client-go/discovery"
"k8s.io/client-go/dynamic"
aggregator "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset"
"k8s.io/client-go/rest"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/apimachinery/pkg/api/meta"
"path/filepath"
"k8s.io/client-go/restmapper"
"github.com/mitchellh/go-homedir"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/restmapper"
"k8s.io/client-go/tools/clientcmd"
aggregator "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset"
)

type KubeProvider struct {
@@ -176,7 +178,7 @@ func ResourceKubectlManifestApply(ctx context.Context, yaml string, waitForRolou

log.Printf("[DEBUG] %v fetched successfully, set id to: %v", manifest, selfLink)

return selfLink, nil
return selfLink, nil
}

func ResourceKubectlManifestRead(ctx context.Context, yaml string, meta interface{}) (bool, error) {
8 changes: 4 additions & 4 deletions utils/kubeseal/kubeseal.go
Original file line number Diff line number Diff line change
@@ -89,12 +89,12 @@ func ParseKey(r io.Reader) (*rsa.PublicKey, error) {

// ParseCertsPem returns error if len(certs) == 0, but best to be sure...
if len(certs) == 0 {
return nil, errors.New("Failed to read any certificates")
return nil, errors.New("failed to read any certificates")
}

cert, ok := certs[0].PublicKey.(*rsa.PublicKey)
if !ok {
return nil, fmt.Errorf("Expected RSA public key but found %v", certs[0].PublicKey)
return nil, fmt.Errorf("expected RSA public key but found %v", certs[0].PublicKey)
}

return cert, nil
@@ -110,11 +110,11 @@ func Seal(in io.Reader, pubKey *rsa.PublicKey, scope ssv1alpha1.SealingScope, al
}

if len(secret.Data) == 0 && len(secret.StringData) == 0 && !allowEmptyData {
return "", fmt.Errorf("Secret.data is empty in input Secret, assuming this is an error and aborting. To work with empty data, --allow-empty-data can be used.")
return "", fmt.Errorf("secret.data is empty in input Secret, assuming this is an error and aborting. To work with empty data, --allow-empty-data can be used")
}

if secret.GetName() == "" {
return "", fmt.Errorf("Missing metadata.name in input Secret")
return "", fmt.Errorf("missing metadata.name in input Secret")
}

if scope != ssv1alpha1.DefaultScope {
39 changes: 19 additions & 20 deletions utils/utils.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package utils

import (
"io"
"bytes"
"crypto/sha256"
"fmt"
"bytes"
"text/template"
"io"
"text/template"
)

var (
secretManifestTemplate = `
secretManifestTemplate = `
apiVersion: v1
data:
{{- range $key, $value := .Secrets }}
@@ -24,10 +24,10 @@ type: {{ .Type }}`
)

type SecretManifest struct {
Name string
Namespace string
Type string
Secrets map[string]interface {}
Name string
Namespace string
Type string
Secrets map[string]interface{}
}

func SHA256(src string) string {
@@ -36,23 +36,23 @@ func SHA256(src string) string {
return fmt.Sprintf("%x", h.Sum(nil))
}

func GenerateSecretManifest(name string, namespace string, _type string, secrets map[string]interface {}) (io.Reader, error) {
secretManifestYAML := new(bytes.Buffer)
func GenerateSecretManifest(name string, namespace string, _type string, secrets map[string]interface{}) (io.Reader, error) {
secretManifestYAML := new(bytes.Buffer)

secretManifest := SecretManifest{
Name: name,
Namespace: namespace,
Type: _type,
Secrets: secrets,
}
secretManifest := SecretManifest{
Name: name,
Namespace: namespace,
Type: _type,
Secrets: secrets,
}

t := template.Must(template.New("secretManifestTemplate").Parse(secretManifestTemplate))
err := t.Execute(secretManifestYAML, secretManifest)
t := template.Must(template.New("secretManifestTemplate").Parse(secretManifestTemplate))
err := t.Execute(secretManifestYAML, secretManifest)
if err != nil {
return nil, err
}

return secretManifestYAML, nil
return secretManifestYAML, nil
}

func ExpandStringSlice(s []interface{}) []string {
@@ -67,4 +67,3 @@ func ExpandStringSlice(s []interface{}) []string {
}
return result
}

0 comments on commit 7b2550d

Please sign in to comment.