-
Notifications
You must be signed in to change notification settings - Fork 284
Expand file tree
/
Copy pathcompute_resolver.go
More file actions
40 lines (33 loc) · 1.25 KB
/
compute_resolver.go
File metadata and controls
40 lines (33 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package service
import (
"context"
"fmt"
"azure.ai.customtraining/pkg/client"
)
// DefaultComputeResolver resolves a compute name to a full ARM resource ID
// by calling the ARM control plane API via the Client.
//
// When compute GET moves to the data plane, this resolver can be swapped out
// for a DataPlaneComputeResolver without changing any other code.
type DefaultComputeResolver struct {
client *client.Client
}
// NewDefaultComputeResolver creates a compute resolver that calls the ARM API
// via the given Client. The client must have ARM context set via SetARMContext.
func NewDefaultComputeResolver(apiClient *client.Client) *DefaultComputeResolver {
return &DefaultComputeResolver{
client: apiClient,
}
}
// ResolveCompute calls the ARM API to resolve a compute name to its full ARM resource ID.
// Returns a helpful error message if the user lacks permissions (401/403).
func (r *DefaultComputeResolver) ResolveCompute(ctx context.Context, computeName string) (string, error) {
result, err := r.client.GetCompute(ctx, computeName)
if err != nil {
return "", err
}
fmt.Printf(" ✓ Compute resolved: %s\n", computeName)
return result.ID, nil
}