Skip to content

Commit c22fe4a

Browse files
authored
feat: support public api go-dvls (#11)
1 parent aaad819 commit c22fe4a

File tree

6 files changed

+21
-27
lines changed

6 files changed

+21
-27
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# To re-generate a bundle for another specific version without changing the standard setup, you can:
44
# - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2)
55
# - use environment variables to overwrite this value (e.g export VERSION=0.0.2)
6-
VERSION ?= 0.1.0
6+
VERSION ?= 0.2.0
77

88
# CHANNELS define the bundle channels used in the bundle.
99
# Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable")

api/v1alpha1/dvlssecret_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type DvlsSecretSpec struct {
2929
// Important: Run "make" to regenerate code after modifying this file
3030

3131
EntryID string `json:"entryId"` // entry id on dvls
32+
VaultID string `json:"vaultId"` // vault id on dvls
3233
}
3334

3435
// DvlsSecretStatus defines the observed state of DvlsSecret

controllers/dvlssecret_controller.go

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func (r *DvlsSecretReconciler) Reconcile(ctx context.Context, req ctrl.Request)
9292
}
9393
}
9494

95-
entry, err := DvlsClient.GetEntry(dvlsSecret.Spec.EntryID)
95+
entry, err := DvlsClient.Entries.Credential.GetById(dvlsSecret.Spec.VaultID, dvlsSecret.Spec.EntryID)
9696
if err != nil {
9797
log.Error(err, "unable to fetch dvls entry", "entryId", dvlsSecret.Spec.EntryID)
9898
meta.SetStatusCondition(&dvlsSecret.Status.Conditions, v1.Condition{Type: statusDegradedDvlsSecret, Status: v1.ConditionTrue, Reason: "Reconciling", Message: "Unable to fetch entry on DVLS instance"})
@@ -102,8 +102,8 @@ func (r *DvlsSecretReconciler) Reconcile(ctx context.Context, req ctrl.Request)
102102
return ctrl.Result{}, nil
103103
}
104104

105-
if entry.ConnectionType != dvls.ServerConnectionCredential || entry.ConnectionSubType != dvls.ServerConnectionSubTypeDefault {
106-
log.Error(err, "entry type not supported, only username/password entries are supported", "entryId", dvlsSecret.Spec.EntryID, "entryType", entry.ConnectionType, "entrySubType", entry.ConnectionSubType)
105+
if entry.Type != string(dvls.ServerConnectionCredential) || entry.SubType != string(dvls.ServerConnectionSubTypeDefault) {
106+
log.Error(err, "entry type not supported, only username/password entries are supported", "entryId", dvlsSecret.Spec.EntryID, "entryType", entry.Type, "entrySubType", entry.SubType)
107107
meta.SetStatusCondition(&dvlsSecret.Status.Conditions, v1.Condition{Type: statusDegradedDvlsSecret, Status: v1.ConditionTrue, Reason: "Reconciling", Message: "Entry type not supported, only username/password entries are supported"})
108108
if err := r.Status().Update(ctx, dvlsSecret); err != nil {
109109
log.Error(err, "Failed to update DvlsSecret status")
@@ -119,9 +119,9 @@ func (r *DvlsSecretReconciler) Reconcile(ctx context.Context, req ctrl.Request)
119119
kSecretNotFound := apierrors.IsNotFound(err)
120120

121121
var entryTime, secretTime time.Time
122-
if !dvlsSecret.Status.EntryModifiedDate.IsZero() && entry.ModifiedDate != nil {
122+
if !dvlsSecret.Status.EntryModifiedDate.IsZero() && entry.ModifiedOn != nil {
123123
secretTime = dvlsSecret.Status.EntryModifiedDate.Time
124-
entryTime = entry.ModifiedDate.Time
124+
entryTime = entry.ModifiedOn.Time
125125
}
126126

127127
if entryTime.Equal(secretTime) && !kSecretNotFound {
@@ -130,21 +130,19 @@ func (r *DvlsSecretReconciler) Reconcile(ctx context.Context, req ctrl.Request)
130130
}, nil
131131
}
132132

133-
secret, err := DvlsClient.GetEntryCredentialsPassword(entry)
134-
if err != nil {
135-
log.Error(err, "unable to fetch dvls secret", "entryId", dvlsSecret.Spec.EntryID)
136-
meta.SetStatusCondition(&dvlsSecret.Status.Conditions, v1.Condition{Type: statusDegradedDvlsSecret, Status: v1.ConditionTrue, Reason: "Reconciling", Message: "Unable to fetch secret on DVLS instance"})
137-
if err := r.Status().Update(ctx, dvlsSecret); err != nil {
138-
log.Error(err, "Failed to update DvlsSecret status")
139-
}
140-
return ctrl.Result{}, nil
133+
defaultData, ok := entry.GetCredentialDefaultData()
134+
if !ok {
135+
return ctrl.Result{}, fmt.Errorf(
136+
"failed to extract credential data for entry ID %s: unsupported or unexpected entry type (type: %s, subtype: %s)",
137+
dvlsSecret.Spec.EntryID, entry.Type, entry.SubType)
141138
}
139+
142140
secretMap := make(map[string]string)
143-
secretMap["entry-id"] = secret.ID
144-
secretMap["entry-name"] = secret.EntryName
145-
secretMap["username"] = secret.Credentials.Username
146-
if secret.Credentials.Password != nil {
147-
secretMap["password"] = *secret.Credentials.Password
141+
secretMap["entry-id"] = entry.Id
142+
secretMap["entry-name"] = entry.Name
143+
secretMap["username"] = defaultData.Username
144+
if defaultData.Password != "" {
145+
secretMap["password"] = defaultData.Password
148146
}
149147

150148
if kSecretNotFound {

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.21
55
toolchain go1.21.4
66

77
require (
8-
github.com/Devolutions/go-dvls v0.4.1
8+
github.com/Devolutions/go-dvls v0.12.2
99
github.com/onsi/ginkgo/v2 v2.14.0
1010
github.com/onsi/gomega v1.30.0
1111
k8s.io/api v0.29.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
github.com/Devolutions/go-dvls v0.4.1 h1:2euUdRYFF54/VJRiGZ/toSXhwursngsJvkwbbp/Groc=
2-
github.com/Devolutions/go-dvls v0.4.1/go.mod h1:LWmMkJugG1/aUH5oXwHN13EvJC+YhvyKH/11pPecPtw=
1+
github.com/Devolutions/go-dvls v0.12.2 h1:7qptA5gw8JVtEJuTBmfDHOFfkGY6XMRobvg6InIEa+4=
2+
github.com/Devolutions/go-dvls v0.12.2/go.mod h1:4O3lb/RK1P1cDwU5auVi7CM4gRER7EuwyLwMVuEZjgg=
33
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
44
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
55
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=

main.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,6 @@ func main() {
128128
os.Exit(1)
129129
}
130130

131-
if dvlsClient.ClientUser.UserType != dvls.UserAuthenticationApplication {
132-
setupLog.Error(nil, "provided credentials are not for an Application user type", "userType", dvlsClient.ClientUser.UserType)
133-
os.Exit(1)
134-
}
135-
136131
requeueDurationString := os.Getenv("DEVO_OPERATOR_REQUEUE_DURATION")
137132
if requeueDurationString != "" {
138133
requeueDuration, err := time.ParseDuration(requeueDurationString)

0 commit comments

Comments
 (0)