Skip to content

Commit

Permalink
user info (#22)
Browse files Browse the repository at this point in the history
* user info send whole object to SM
  • Loading branch information
pavelmaliy authored Mar 7, 2021
1 parent 52d96cd commit 297628a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
16 changes: 16 additions & 0 deletions controllers/controller_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package controllers
import (
"encoding/json"
"strings"

"github.com/go-logr/logr"
v1 "k8s.io/api/authentication/v1"
)

func normalizeCredentials(credentialsJSON json.RawMessage) (map[string][]byte, error) {
Expand All @@ -27,3 +30,16 @@ func normalizeCredentials(credentialsJSON json.RawMessage) (map[string][]byte, e
}
return normalized, nil
}

func buildUserInfo(userInfo *v1.UserInfo, log logr.Logger) string {
if userInfo == nil {
return ""
}
userInfoStr, err := json.Marshal(userInfo)
if err != nil {
log.Error(err, "failed to prepare user info")
return ""
}

return string(userInfoStr)
}
4 changes: 2 additions & 2 deletions controllers/servicebinding_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func (r *ServiceBindingReconciler) createBinding(ctx context.Context, smClient s
},
ServiceInstanceID: serviceInstance.Status.InstanceID,
Parameters: bindingParameters,
}, nil, serviceBinding.Spec.UserInfo.Username)
}, nil, buildUserInfo(serviceBinding.Spec.UserInfo, log))

if bindErr != nil {
log.Error(err, "failed to create service binding", "serviceInstanceID", serviceInstance.Status.InstanceID)
Expand Down Expand Up @@ -273,7 +273,7 @@ func (r *ServiceBindingReconciler) delete(ctx context.Context, smClient sm.Clien
}

log.Info(fmt.Sprintf("Deleting binding with id %v from SM", serviceBinding.Status.BindingID))
operationURL, unbindErr := smClient.Unbind(serviceBinding.Status.BindingID, nil, serviceBinding.Spec.UserInfo.Username)
operationURL, unbindErr := smClient.Unbind(serviceBinding.Status.BindingID, nil, buildUserInfo(serviceBinding.Spec.UserInfo, log))
if unbindErr != nil {
log.Error(unbindErr, "failed to delete binding")
if isTransientError(unbindErr, log) {
Expand Down
6 changes: 3 additions & 3 deletions controllers/serviceinstance_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func (r *ServiceInstanceReconciler) createInstance(ctx context.Context, smClient
k8sNameLabel: []string{serviceInstance.Name},
clusterIDLabel: []string{r.Config.ClusterID},
},
}, serviceInstance.Spec.ServiceOfferingName, serviceInstance.Spec.ServicePlanName, nil, serviceInstance.Spec.UserInfo.Username)
}, serviceInstance.Spec.ServiceOfferingName, serviceInstance.Spec.ServicePlanName, nil, buildUserInfo(serviceInstance.Spec.UserInfo, log))

if provisionErr != nil {
log.Error(provisionErr, "failed to create service instance", "serviceOfferingName", serviceInstance.Spec.ServiceOfferingName,
Expand Down Expand Up @@ -235,7 +235,7 @@ func (r *ServiceInstanceReconciler) updateInstance(ctx context.Context, smClient
Name: serviceInstance.Spec.ExternalName,
ServicePlanID: serviceInstance.Spec.ServicePlanID,
Parameters: instanceParameters,
}, serviceInstance.Spec.ServiceOfferingName, serviceInstance.Spec.ServicePlanName, nil, serviceInstance.Spec.UserInfo.Username)
}, serviceInstance.Spec.ServiceOfferingName, serviceInstance.Spec.ServicePlanName, nil, buildUserInfo(serviceInstance.Spec.UserInfo, log))
if err != nil {
log.Error(err, fmt.Sprintf("failed to update service instance with ID %s", serviceInstance.Status.InstanceID))
if isTransientError(err, log) {
Expand Down Expand Up @@ -281,7 +281,7 @@ func (r *ServiceInstanceReconciler) deleteInstance(ctx context.Context, smClient
}

log.Info(fmt.Sprintf("Deleting instance with id %v from SM", serviceInstance.Status.InstanceID))
operationURL, deprovisionErr := smClient.Deprovision(serviceInstance.Status.InstanceID, nil, serviceInstance.Spec.UserInfo.Username)
operationURL, deprovisionErr := smClient.Deprovision(serviceInstance.Status.InstanceID, nil, buildUserInfo(serviceInstance.Spec.UserInfo, log))
if deprovisionErr != nil {
if isTransientError(deprovisionErr, log) {
return r.markAsTransientError(ctx, smTypes.DELETE, deprovisionErr.Error(), serviceInstance, log)
Expand Down

0 comments on commit 297628a

Please sign in to comment.