Skip to content

Commit

Permalink
Add awesome sdk
Browse files Browse the repository at this point in the history
Signed-off-by: Heba Elayoty <[email protected]>
  • Loading branch information
helayoty committed Jun 12, 2024
1 parent d001814 commit d0e87e2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 26 deletions.
15 changes: 7 additions & 8 deletions pkg/auth/cred.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ import (
)

const (
e2eOverlayResourceVersionKey = "AKS_E2E_OVERLAY_RESOURCE_VERSION"
E2E_RP_INGRESS_ENDPOINT_ADDRESS = "rp.e2e.ig.e2e-aks.azure.com"
E2E_SERVICE_CONFIGURATION_AUDIENCE = "https://management.core.windows.net/"
HTTPSPrefix = "https://"
E2E_RP_INGRESS_ENDPOINT = "rp.e2e.ig.e2e-aks.azure.com"
E2E_RP_INGRESS_ENDPOINT_ADDRESS = "rp.e2e.ig.e2e-aks.azure.com"
HTTPSPrefix = "https://"
RPReferer = "rp.e2e.ig.e2e-aks.azure.com"
e2eOverlayResourceVersionKey = "AKS_E2E_OVERLAY_RESOURCE_VERSION"

Check failure on line 47 in pkg/auth/cred.go

View workflow job for this annotation

GitHub Actions / build

`e2eOverlayResourceVersionKey` is unused (deadcode)
)

// CredentialAuth authenticates an application with assertions provided by a callback function.
Expand Down Expand Up @@ -158,7 +157,7 @@ func (ca *CredentialAuth) readJWTFromFS() (string, error) {
}
func getE2ETestingCert(ctx context.Context) (string, error) {
klog.Info("getE2ETestingCert")
e2eOverlayResourceVersion := "rscazghj6" //os.Getenv(e2eOverlayResourceVersionKey)
e2eOverlayResourceVersion := "rw9erfy9x" //os.Getenv(e2eOverlayResourceVersionKey)
if e2eOverlayResourceVersion == "" {
return "", fmt.Errorf("E2E overlay resource version is not set")
}
Expand Down Expand Up @@ -292,11 +291,11 @@ func SplitPEMBlock(pemBlock []byte) (certPEM []byte, keyPEM []byte) {
return certPEM, keyPEM
}

func CloneCloudConfiguration(cloudConfig *cloud.Configuration) *cloud.Configuration {
func CloneCloudConfiguration(cloudConfig *cloud.Configuration) cloud.Configuration {
clone := *cloudConfig
clone.Services = make(map[cloud.ServiceName]cloud.ServiceConfiguration)
for k, v := range cloudConfig.Services {
clone.Services[k] = v
}
return &clone
return clone
}
25 changes: 7 additions & 18 deletions pkg/providers/instance/azure_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package instance

import (
"context"
"maps"
"net/http"

"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
Expand All @@ -38,10 +37,6 @@ import (
"k8s.io/klog/v2"
)

const (
RPReferer = "rp.e2e.ig.e2e-aks.azure.com"
)

type AgentPoolsAPI interface {
BeginCreateOrUpdate(ctx context.Context, resourceGroupName string, resourceName string, agentPoolName string, parameters armcontainerservice.AgentPool, options *armcontainerservice.AgentPoolsClientBeginCreateOrUpdateOptions) (*runtime.Poller[armcontainerservice.AgentPoolsClientCreateOrUpdateResponse], error)
Get(ctx context.Context, resourceGroupName string, resourceName string, agentPoolName string, options *armcontainerservice.AgentPoolsClientGetOptions) (armcontainerservice.AgentPoolsClientGetResponse, error)
Expand Down Expand Up @@ -83,20 +78,14 @@ func NewAZClient(ctx context.Context, cfg *auth.Config) (*AZClient, error) {
// If not E2E, we use the default options
var agentPoolClient AgentPoolsAPI
if isE2E {
optionsToUse := &arm.ClientOptions{}
e2eCloudConfig := auth.CloneCloudConfiguration(&cloud.AzurePublic)
e2eCloudConfig.Services[cloud.ResourceManager] = cloud.ServiceConfiguration{
Audience: auth.E2E_SERVICE_CONFIGURATION_AUDIENCE,
Endpoint: auth.HTTPSPrefix + auth.E2E_RP_INGRESS_ENDPOINT,
}
optionsToUse.ClientOptions.Cloud = *e2eCloudConfig
optionsToUse := SetArmClientOptions()

httpClient, err := auth.BuildHTTPClient(ctx)
optionsToUse.Transport = httpClient

if err != nil {
return nil, err
}
optionsToUse.Transport = httpClient

apClient, err := awesome.NewAgentPoolsClient(cfg.SubscriptionID, &auth.DummyCredential{}, optionsToUse)
if err != nil {
return nil, err
Expand Down Expand Up @@ -133,16 +122,16 @@ func SetArmClientOptions() *arm.ClientOptions {

opt.PerCallPolicies = append(opt.PerCallPolicies,
PolicySetHeaders{
"Referer": []string{RPReferer},
"Referer": []string{auth.RPReferer},
},
PolicySetHeaders{
"x-ms-correlation-request-id": []string{uuid.New().String()},
},
)
opt.Cloud.Services = maps.Clone(opt.Cloud.Services) // we need this because map is a reference type
opt.Cloud = auth.CloneCloudConfiguration(&cloud.AzurePublic)
opt.Cloud.Services[cloud.ResourceManager] = cloud.ServiceConfiguration{
Audience: cloud.AzurePublic.Services[cloud.ResourceManager].Audience,
Endpoint: "https://" + RPReferer,
Audience: auth.E2E_RP_INGRESS_ENDPOINT_ADDRESS,
Endpoint: auth.HTTPSPrefix + auth.RPReferer,
}
return opt
}
Expand Down

0 comments on commit d0e87e2

Please sign in to comment.