-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Exports SignalR API Keys * updates signalr tests * updates signalr recordings: adds keys * Update v2/api/signalrservice/customizations/signal_r_extention_authorization.go Co-authored-by: Matthew Christopher <[email protected]> * Update v2/internal/controllers/crd_signalr_test.go Co-authored-by: Matthew Christopher <[email protected]> * removes comment * reverts go.mod go.sum * re-record signalr test --------- Co-authored-by: Matthew Christopher <[email protected]>
- Loading branch information
Showing
18 changed files
with
2,272 additions
and
629 deletions.
There are no files selected for viewing
109 changes: 109 additions & 0 deletions
109
v2/api/signalrservice/customizations/signal_r_extention_authorization.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
* Copyright (c) Microsoft Corporation. | ||
* Licensed under the MIT license. | ||
*/ | ||
|
||
package customizations | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/signalr/armsignalr" | ||
"github.com/go-logr/logr" | ||
"github.com/pkg/errors" | ||
v1 "k8s.io/api/core/v1" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
"sigs.k8s.io/controller-runtime/pkg/conversion" | ||
|
||
signalr "github.com/Azure/azure-service-operator/v2/api/signalrservice/v1api20211001/storage" | ||
"github.com/Azure/azure-service-operator/v2/internal/genericarmclient" | ||
. "github.com/Azure/azure-service-operator/v2/internal/logging" | ||
"github.com/Azure/azure-service-operator/v2/internal/util/to" | ||
"github.com/Azure/azure-service-operator/v2/pkg/genruntime" | ||
"github.com/Azure/azure-service-operator/v2/pkg/genruntime/secrets" | ||
) | ||
|
||
// Ensure that SignalRAuthorizationExtension implements the KubernetesExporter interface | ||
var _ genruntime.KubernetesExporter = &SignalRExtension{} | ||
|
||
// ExportKubernetesResources implements genruntime.KubernetesExporter | ||
func (*SignalRExtension) ExportKubernetesResources( | ||
ctx context.Context, | ||
obj genruntime.MetaObject, | ||
armClient *genericarmclient.GenericClient, | ||
log logr.Logger) ([]client.Object, error) { | ||
// Make sure we're working with the current hub version of the resource | ||
// This will need to be updated if the hub version changes | ||
typedObj, ok := obj.(*signalr.SignalR) | ||
if !ok { | ||
return nil, errors.Errorf( | ||
"cannot run on unknown resource type %T, expected *signalr.SignalR", obj) | ||
} | ||
|
||
// Type assert that we are the hub type. This will fail to compile if | ||
// the hub type has been changed but this extension has not | ||
var _ conversion.Hub = typedObj | ||
|
||
hasSecrets := secretsSpecified(typedObj) | ||
if !hasSecrets { | ||
log.V(Debug).Info("No secrets retrieval to perform as operatorSpec is empty") | ||
return nil, nil | ||
} | ||
|
||
id, err := genruntime.GetAndParseResourceID(typedObj) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// Using armClient.ClientOptions() here ensures we share the same HTTP connection, so this is not opening a new | ||
// connection each time through | ||
clientFactory, err := armsignalr.NewClientFactory(id.SubscriptionID, armClient.Creds(), armClient.ClientOptions()) | ||
if err != nil { | ||
return nil, errors.Wrapf(err, "failed to create ARM signalR client factory") | ||
} | ||
|
||
res, err := clientFactory.NewClient().ListKeys(ctx, id.ResourceGroupName, typedObj.AzureName(), nil) | ||
if err != nil { | ||
return nil, errors.Wrapf(err, "failed to list keys") | ||
} | ||
|
||
secretSlice, err := secretsToWrite(typedObj, res.Keys) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return secrets.SliceToClientObjectSlice(secretSlice), nil | ||
|
||
} | ||
|
||
func secretsSpecified(obj *signalr.SignalR) bool { | ||
if obj.Spec.OperatorSpec == nil || obj.Spec.OperatorSpec.Secrets == nil { | ||
return false | ||
} | ||
|
||
specSecrets := obj.Spec.OperatorSpec.Secrets | ||
hasSecrets := false | ||
if specSecrets.PrimaryKey != nil || | ||
specSecrets.SecondaryKey != nil || | ||
specSecrets.PrimaryConnectionString != nil || | ||
specSecrets.SecondaryConnectionString != nil { | ||
hasSecrets = true | ||
} | ||
|
||
return hasSecrets | ||
} | ||
|
||
func secretsToWrite(obj *signalr.SignalR, accessKeys armsignalr.Keys) ([]*v1.Secret, error) { | ||
operatorSpecSecrets := obj.Spec.OperatorSpec.Secrets | ||
if operatorSpecSecrets == nil { | ||
return nil, errors.Errorf("unexpected nil operatorspec") | ||
} | ||
|
||
collector := secrets.NewCollector(obj.Namespace) | ||
collector.AddValue(operatorSpecSecrets.PrimaryKey, to.Value(accessKeys.PrimaryKey)) | ||
collector.AddValue(operatorSpecSecrets.SecondaryKey, to.Value(accessKeys.SecondaryKey)) | ||
collector.AddValue(operatorSpecSecrets.PrimaryConnectionString, to.Value(accessKeys.PrimaryConnectionString)) | ||
collector.AddValue(operatorSpecSecrets.SecondaryConnectionString, to.Value(accessKeys.SecondaryConnectionString)) | ||
|
||
return collector.Values() | ||
} |
210 changes: 209 additions & 1 deletion
210
v2/api/signalrservice/v1api20211001/signal_r_types_gen.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.