mirror of
https://github.com/getsops/sops.git
synced 2026-02-05 12:45:21 +01:00
Fix golint issues
This commit is contained in:
@@ -20,11 +20,11 @@ import (
|
||||
"strconv"
|
||||
|
||||
"go.mozilla.org/sops/aes"
|
||||
"go.mozilla.org/sops/gcpkms"
|
||||
"go.mozilla.org/sops/cmd/sops/codes"
|
||||
"go.mozilla.org/sops/cmd/sops/subcommand/groups"
|
||||
keyservicecmd "go.mozilla.org/sops/cmd/sops/subcommand/keyservice"
|
||||
"go.mozilla.org/sops/config"
|
||||
"go.mozilla.org/sops/gcpkms"
|
||||
"go.mozilla.org/sops/keys"
|
||||
"go.mozilla.org/sops/keyservice"
|
||||
"go.mozilla.org/sops/kms"
|
||||
@@ -371,7 +371,7 @@ func main() {
|
||||
for _, k := range pgp.MasterKeysFromFingerprintString(c.String("add-pgp")) {
|
||||
addMasterKeys = append(addMasterKeys, k)
|
||||
}
|
||||
for _, k := range gcpkms.MasterKeysFromResourceIdString(c.String("add-gcp-kms")) {
|
||||
for _, k := range gcpkms.MasterKeysFromResourceIDString(c.String("add-gcp-kms")) {
|
||||
addMasterKeys = append(addMasterKeys, k)
|
||||
}
|
||||
|
||||
@@ -382,7 +382,7 @@ func main() {
|
||||
for _, k := range pgp.MasterKeysFromFingerprintString(c.String("rm-pgp")) {
|
||||
rmMasterKeys = append(rmMasterKeys, k)
|
||||
}
|
||||
for _, k := range gcpkms.MasterKeysFromResourceIdString(c.String("rm-gcp-kms")) {
|
||||
for _, k := range gcpkms.MasterKeysFromResourceIDString(c.String("rm-gcp-kms")) {
|
||||
rmMasterKeys = append(rmMasterKeys, k)
|
||||
}
|
||||
output, err = rotate(rotateOpts{
|
||||
@@ -578,7 +578,7 @@ func keyGroups(c *cli.Context, file string) ([]sops.KeyGroup, error) {
|
||||
}
|
||||
}
|
||||
if c.String("gcp-kms") != "" {
|
||||
for _, k := range gcpkms.MasterKeysFromResourceIdString(c.String("gcp-kms")) {
|
||||
for _, k := range gcpkms.MasterKeysFromResourceIDString(c.String("gcp-kms")) {
|
||||
cloudKmsKeys = append(cloudKmsKeys, k)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,9 +12,9 @@ import (
|
||||
|
||||
"github.com/mozilla-services/yaml"
|
||||
"go.mozilla.org/sops"
|
||||
"go.mozilla.org/sops/gcpkms"
|
||||
"go.mozilla.org/sops/kms"
|
||||
"go.mozilla.org/sops/pgp"
|
||||
"go.mozilla.org/sops/gcpkms"
|
||||
)
|
||||
|
||||
type fileSystem interface {
|
||||
@@ -119,7 +119,7 @@ func loadForFileFromBytes(confBytes []byte, filePath string, kmsEncryptionContex
|
||||
keyGroup = append(keyGroup, kms.NewMasterKey(k.Arn, k.Role, k.Context))
|
||||
}
|
||||
for _, k := range group.GCPKMS {
|
||||
keyGroup = append(keyGroup, gcpkms.NewMasterKeyFromResourceId(k.ResourceID))
|
||||
keyGroup = append(keyGroup, gcpkms.NewMasterKeyFromResourceID(k.ResourceID))
|
||||
}
|
||||
groups = append(groups, keyGroup)
|
||||
}
|
||||
@@ -131,7 +131,7 @@ func loadForFileFromBytes(confBytes []byte, filePath string, kmsEncryptionContex
|
||||
for _, k := range kms.MasterKeysFromArnString(rule.KMS, kmsEncryptionContext) {
|
||||
keyGroup = append(keyGroup, k)
|
||||
}
|
||||
for _, k := range gcpkms.MasterKeysFromResourceIdString(rule.GCPKMS) {
|
||||
for _, k := range gcpkms.MasterKeysFromResourceIDString(rule.GCPKMS) {
|
||||
keyGroup = append(keyGroup, k)
|
||||
}
|
||||
groups = append(groups, keyGroup)
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
|
||||
// MasterKey is a GCP KMS key used to encrypt and decrypt sops' data key.
|
||||
type MasterKey struct {
|
||||
ResourceId string
|
||||
ResourceID string
|
||||
EncryptedKey string
|
||||
CreationDate time.Time
|
||||
}
|
||||
@@ -39,7 +39,7 @@ func (key *MasterKey) Encrypt(dataKey []byte) error {
|
||||
req := &cloudkms.EncryptRequest{
|
||||
Plaintext: base64.StdEncoding.EncodeToString(dataKey),
|
||||
}
|
||||
resp, err := cloudkmsService.Projects.Locations.KeyRings.CryptoKeys.Encrypt(key.ResourceId, req).Do()
|
||||
resp, err := cloudkmsService.Projects.Locations.KeyRings.CryptoKeys.Encrypt(key.ResourceID, req).Do()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to call GCP KMS encryption service: %v", err)
|
||||
}
|
||||
@@ -66,7 +66,7 @@ func (key *MasterKey) Decrypt() ([]byte, error) {
|
||||
req := &cloudkms.DecryptRequest{
|
||||
Ciphertext: key.EncryptedKey,
|
||||
}
|
||||
resp, err := cloudkmsService.Projects.Locations.KeyRings.CryptoKeys.Decrypt(key.ResourceId, req).Do()
|
||||
resp, err := cloudkmsService.Projects.Locations.KeyRings.CryptoKeys.Decrypt(key.ResourceID, req).Do()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Error decrypting key: %v", err)
|
||||
}
|
||||
@@ -80,35 +80,35 @@ func (key *MasterKey) NeedsRotation() bool {
|
||||
|
||||
// ToString converts the key to a string representation
|
||||
func (key *MasterKey) ToString() string {
|
||||
return key.ResourceId
|
||||
return key.ResourceID
|
||||
}
|
||||
|
||||
// NewMasterKeyFromResourceId takes a GCP KMS resource ID string and returns a new MasterKey for that
|
||||
func NewMasterKeyFromResourceId(resourceId string) *MasterKey {
|
||||
// NewMasterKeyFromResourceID takes a GCP KMS resource ID string and returns a new MasterKey for that
|
||||
func NewMasterKeyFromResourceID(resourceID string) *MasterKey {
|
||||
k := &MasterKey{}
|
||||
resourceId = strings.Replace(resourceId, " ", "", -1)
|
||||
k.ResourceId = resourceId
|
||||
resourceID = strings.Replace(resourceID, " ", "", -1)
|
||||
k.ResourceID = resourceID
|
||||
k.CreationDate = time.Now().UTC()
|
||||
return k
|
||||
}
|
||||
|
||||
// MasterKeysFromResourceIdString takes a comma separated list of GCP KMS resourece IDs and returns a slice of new MasterKeys for them
|
||||
func MasterKeysFromResourceIdString(resourceId string) []*MasterKey {
|
||||
// MasterKeysFromResourceIDString takes a comma separated list of GCP KMS resourece IDs and returns a slice of new MasterKeys for them
|
||||
func MasterKeysFromResourceIDString(resourceID string) []*MasterKey {
|
||||
var keys []*MasterKey
|
||||
if resourceId == "" {
|
||||
if resourceID == "" {
|
||||
return keys
|
||||
}
|
||||
for _, s := range strings.Split(resourceId, ",") {
|
||||
keys = append(keys, NewMasterKeyFromResourceId(s))
|
||||
for _, s := range strings.Split(resourceID, ",") {
|
||||
keys = append(keys, NewMasterKeyFromResourceID(s))
|
||||
}
|
||||
return keys
|
||||
}
|
||||
|
||||
func (key MasterKey) createCloudKMSService() (*cloudkms.Service, error) {
|
||||
re := regexp.MustCompile(`^projects/[^/]+/locations/[^/]+/keyRings/[^/]+/cryptoKeys/[^/]+$`)
|
||||
matches := re.FindStringSubmatch(key.ResourceId)
|
||||
matches := re.FindStringSubmatch(key.ResourceID)
|
||||
if matches == nil {
|
||||
return nil, fmt.Errorf("No valid resoureceId found in %q", key.ResourceId)
|
||||
return nil, fmt.Errorf("No valid resoureceId found in %q", key.ResourceID)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
@@ -127,7 +127,7 @@ func (key MasterKey) createCloudKMSService() (*cloudkms.Service, error) {
|
||||
// ToMap converts the MasterKey to a map for serialization purposes
|
||||
func (key MasterKey) ToMap() map[string]interface{} {
|
||||
out := make(map[string]interface{})
|
||||
out["resource_id"] = key.ResourceId
|
||||
out["resource_id"] = key.ResourceID
|
||||
out["enc"] = key.EncryptedKey
|
||||
out["created_at"] = key.CreationDate.UTC().Format(time.RFC3339)
|
||||
return out
|
||||
|
||||
@@ -9,23 +9,23 @@ import (
|
||||
|
||||
func TestGCPKMSKeySourceFromString(t *testing.T) {
|
||||
s := "projects/sops-testing1/locations/global/keyRings/creds/cryptoKeys/key1, projects/sops-testing2/locations/global/keyRings/creds/cryptoKeys/key2"
|
||||
ks := MasterKeysFromResourceIdString(s)
|
||||
ks := MasterKeysFromResourceIDString(s)
|
||||
k1 := ks[0]
|
||||
k2 := ks[1]
|
||||
expectedResourceId1 := "projects/sops-testing1/locations/global/keyRings/creds/cryptoKeys/key1"
|
||||
expectedResourceId2 := "projects/sops-testing2/locations/global/keyRings/creds/cryptoKeys/key2"
|
||||
if k1.ResourceId != expectedResourceId1 {
|
||||
t.Errorf("ResourceId mismatch. Expected %s, found %s", expectedResourceId1, k1.ResourceId)
|
||||
expectedResourceID1 := "projects/sops-testing1/locations/global/keyRings/creds/cryptoKeys/key1"
|
||||
expectedResourceID2 := "projects/sops-testing2/locations/global/keyRings/creds/cryptoKeys/key2"
|
||||
if k1.ResourceID != expectedResourceID1 {
|
||||
t.Errorf("ResourceID mismatch. Expected %s, found %s", expectedResourceID1, k1.ResourceID)
|
||||
}
|
||||
if k2.ResourceId != expectedResourceId2 {
|
||||
t.Errorf("ResourceId mismatch. Expected %s, found %s", expectedResourceId2, k2.ResourceId)
|
||||
if k2.ResourceID != expectedResourceID2 {
|
||||
t.Errorf("ResourceID mismatch. Expected %s, found %s", expectedResourceID2, k2.ResourceID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestKeyToMap(t *testing.T) {
|
||||
key := MasterKey{
|
||||
CreationDate: time.Date(2016, time.October, 31, 10, 0, 0, 0, time.UTC),
|
||||
ResourceId: "foo",
|
||||
ResourceID: "foo",
|
||||
EncryptedKey: "this is encrypted",
|
||||
}
|
||||
assert.Equal(t, map[string]interface{}{
|
||||
|
||||
Reference in New Issue
Block a user