Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import (
"fmt"
"os"

"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2022-08-01/compute" //nolint:staticcheck
"github.com/Azure/go-autorest/autorest/azure/auth"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v7"

"github.com/Azure/skewer"
"github.com/Azure/skewer/v2"
)

const (
Expand All @@ -35,12 +35,19 @@ func main() {
os.Setenv(ClientID, "AAD Client ID or AppID")
os.Setenv(ClientSecret, "AADClientSecretHere")
sub := os.Getenv(SubscriptionID)
authorizer, err := auth.NewAuthorizerFromEnvironment()
// Create a skus client
client := compute.NewResourceSkusClient(sub)
client.Authorizer = authorizer
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
fmt.Printf("failed to get credential: %s", err)
os.Exit(1)
}

client, err := armcompute.NewResourceSKUsClient(sub, cred, nil)
if err != nil {
fmt.Printf("failed to get client: %s", err)
os.Exit(1)
}

cache, err := skewer.NewCache(context.Background(), skewer.WithLocation("southcentralus"), skewer.WithResourceClient(client))
cache, err := skewer.NewCache(context.Background(), skewer.WithLocation("eastus"), skewer.WithResourceSKUsClient(client))
if err != nil {
fmt.Printf("failed to instantiate sku cache: %s", err)
os.Exit(1)
Expand All @@ -54,9 +61,9 @@ func main() {

Once we have a cache, we can query against its contents:
```go
sku, found := cache.Get(context.Background, "standard_d4s_v3", skewer.VirtualMachines, "eastus")
if !found {
return fmt.Errorf("expected to find virtual machine sku standard_d4s_v3")
sku, err := cache.Get(context.Background(), "standard_d4s_v3", skewer.VirtualMachines, "eastus")
if err != nil {
return fmt.Errorf("failed to find virtual machine sku standard_d4s_v3: %s", err)
}

// Check for capabilities
Expand Down
24 changes: 6 additions & 18 deletions cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,27 +70,14 @@ func WithClient(client client) Option {
}
}

// WithResourceClient is a functional option to use a cache
// backed by a ResourceClient.
func WithResourceClient(client ResourceClient) Option {
// WithResourceSKUsClient is a functional option to use a cache
// backed by a ResourceSKUsClient.
func WithResourceSKUsClient(client ResourceSKUsClient) Option {
return func(c *Config) (*Config, error) {
if c.client != nil {
return nil, &ErrClientNotNil{}
}
c.client = newWrappedResourceClient(client)
return c, nil
}
}

// WithResourceProviderClient is a functional option to use a cache
// backed by a ResourceProviderClient.
func WithResourceProviderClient(client ResourceProviderClient) Option {
return func(c *Config) (*Config, error) {
if c.client != nil {
return nil, &ErrClientNotNil{}
}
resourceClient := newWrappedResourceProviderClient(client)
c.client = newWrappedResourceClient(resourceClient)
c.client = newWrappedResourceSKUsClient(client)
return c, nil
}
}
Expand Down Expand Up @@ -283,7 +270,8 @@ func (c *Cache) Equal(other *Cache) bool {
return false
}
for i := range c.data {
if c.data[i] != other.data[i] {
// only compare location, type and name
if !c.data[i].Equal(&other.data[i]) {
return false
}
}
Expand Down
Loading