Updating path for fetching 1password items to be of the op:// reference format

This commit is contained in:
jillianwilson
2021-09-06 14:23:59 -03:00
parent 49d984c6f2
commit 1590dd9b89
17 changed files with 130 additions and 117 deletions

View File

@@ -192,11 +192,11 @@ func (r *ReconcileDeployment) HandleApplyingDeployment(namespace string, annotat
secretName := annotations[op.NameAnnotation]
if len(secretName) == 0 {
reqLog.Info("No 'item-name' annotation set. 'item-path' and 'item-name' must be set as annotations to add new secret.")
reqLog.Info("No 'item-name' annotation set. 'item-reference' and 'item-name' must be set as annotations to add new secret.")
return nil
}
item, err := op.GetOnePasswordItemByPath(r.opConnectClient, annotations[op.ItemPathAnnotation])
item, err := op.GetOnePasswordItemByReference(r.opConnectClient, annotations[op.ItemReferenceAnnotation])
if err != nil {
return fmt.Errorf("Failed to retrieve item: %v", err)
}

View File

@@ -52,7 +52,7 @@ var (
"password": []byte(password),
"username": []byte(username),
}
itemPath = fmt.Sprintf("vaults/%v/items/%v", vaultId, itemId)
ItemReference = fmt.Sprintf("op://%v/%v", vaultId, itemId)
)
var (
@@ -76,8 +76,8 @@ var tests = []testReconcileItem{
finalizer,
},
Annotations: map[string]string{
op.ItemPathAnnotation: itemPath,
op.NameAnnotation: name,
op.ItemReferenceAnnotation: ItemReference,
op.NameAnnotation: name,
},
},
},
@@ -90,8 +90,8 @@ var tests = []testReconcileItem{
Name: "another-deployment",
Namespace: namespace,
Annotations: map[string]string{
op.ItemPathAnnotation: itemPath,
op.NameAnnotation: name,
op.ItemReferenceAnnotation: ItemReference,
op.NameAnnotation: name,
},
},
Spec: appsv1.DeploymentSpec{
@@ -152,8 +152,8 @@ var tests = []testReconcileItem{
finalizer,
},
Annotations: map[string]string{
op.ItemPathAnnotation: itemPath,
op.NameAnnotation: name,
op.ItemReferenceAnnotation: ItemReference,
op.NameAnnotation: name,
},
},
},
@@ -166,8 +166,8 @@ var tests = []testReconcileItem{
Name: "another-deployment",
Namespace: namespace,
Annotations: map[string]string{
op.ItemPathAnnotation: itemPath,
op.NameAnnotation: name,
op.ItemReferenceAnnotation: ItemReference,
op.NameAnnotation: name,
},
},
Spec: appsv1.DeploymentSpec{
@@ -235,8 +235,8 @@ var tests = []testReconcileItem{
finalizer,
},
Annotations: map[string]string{
op.ItemPathAnnotation: itemPath,
op.NameAnnotation: name,
op.ItemReferenceAnnotation: ItemReference,
op.NameAnnotation: name,
},
},
},
@@ -268,8 +268,8 @@ var tests = []testReconcileItem{
Name: name,
Namespace: namespace,
Annotations: map[string]string{
op.ItemPathAnnotation: itemPath,
op.NameAnnotation: name,
op.ItemReferenceAnnotation: ItemReference,
op.NameAnnotation: name,
},
},
},
@@ -310,8 +310,8 @@ var tests = []testReconcileItem{
Name: name,
Namespace: namespace,
Annotations: map[string]string{
op.ItemPathAnnotation: itemPath,
op.NameAnnotation: name,
op.ItemReferenceAnnotation: ItemReference,
op.NameAnnotation: name,
},
},
},
@@ -352,8 +352,8 @@ var tests = []testReconcileItem{
Name: name,
Namespace: namespace,
Annotations: map[string]string{
op.ItemPathAnnotation: itemPath,
op.NameAnnotation: name,
op.ItemReferenceAnnotation: ItemReference,
op.NameAnnotation: name,
},
},
},

View File

@@ -3,6 +3,7 @@ package onepassworditem
import (
"context"
"fmt"
onepasswordv1 "github.com/1Password/onepassword-operator/pkg/apis/onepassword/v1"
kubeSecrets "github.com/1Password/onepassword-operator/pkg/kubernetessecrets"
"github.com/1Password/onepassword-operator/pkg/onepassword"
@@ -145,7 +146,7 @@ func (r *ReconcileOnePasswordItem) HandleOnePasswordItem(resource *onepasswordv1
secretName := resource.GetName()
autoRestart := resource.Annotations[op.RestartDeploymentsAnnotation]
item, err := onepassword.GetOnePasswordItemByPath(r.opConnectClient, resource.Spec.ItemPath)
item, err := onepassword.GetOnePasswordItemByReference(r.opConnectClient, resource.Spec.ItemReference)
if err != nil {
return fmt.Errorf("Failed to retrieve item: %v", err)
}

View File

@@ -55,7 +55,7 @@ var (
"password": []byte(password),
"username": []byte(username),
}
itemPath = fmt.Sprintf("vaults/%v/items/%v", vaultId, itemId)
itemReference = fmt.Sprintf("op://%v/%v", vaultId, itemId)
)
var (
@@ -79,7 +79,7 @@ var tests = []testReconcileItem{
},
},
Spec: onepasswordv1.OnePasswordItemSpec{
ItemPath: itemPath,
ItemReference: itemReference,
},
},
existingSecret: &corev1.Secret{
@@ -111,7 +111,7 @@ var tests = []testReconcileItem{
Namespace: namespace,
},
Spec: onepasswordv1.OnePasswordItemSpec{
ItemPath: itemPath,
ItemReference: itemReference,
},
},
existingSecret: &corev1.Secret{
@@ -152,7 +152,7 @@ var tests = []testReconcileItem{
Namespace: namespace,
},
Spec: onepasswordv1.OnePasswordItemSpec{
ItemPath: itemPath,
ItemReference: itemReference,
},
},
existingSecret: &corev1.Secret{
@@ -193,7 +193,7 @@ var tests = []testReconcileItem{
Namespace: namespace,
},
Spec: onepasswordv1.OnePasswordItemSpec{
ItemPath: itemPath,
ItemReference: itemReference,
},
},
existingSecret: nil,
@@ -225,7 +225,7 @@ var tests = []testReconcileItem{
Namespace: namespace,
},
Spec: onepasswordv1.OnePasswordItemSpec{
ItemPath: itemPath,
ItemReference: itemReference,
},
},
existingSecret: nil,
@@ -257,7 +257,7 @@ var tests = []testReconcileItem{
Namespace: namespace,
},
Spec: onepasswordv1.OnePasswordItemSpec{
ItemPath: itemPath,
ItemReference: itemReference,
},
},
existingSecret: nil,