forked from gruntwork-io/terratest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
actiongroup.go
62 lines (49 loc) · 1.97 KB
/
actiongroup.go
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package azure
import (
"context"
"testing"
"github.com/Azure/azure-sdk-for-go/profiles/preview/preview/monitor/mgmt/insights"
"github.com/stretchr/testify/require"
)
// GetActionGroupResource gets the ActionGroupResource.
// ruleName - required to find the ActionGroupResource.
// resGroupName - use an empty string if you have the AZURE_RES_GROUP_NAME environment variable set
// subscriptionId - use an empty string if you have the ARM_SUBSCRIPTION_ID environment variable set
func GetActionGroupResource(t *testing.T, ruleName string, resGroupName string, subscriptionID string) *insights.ActionGroupResource {
actionGroupResource, err := GetActionGroupResourceE(ruleName, resGroupName, subscriptionID)
require.NoError(t, err)
return actionGroupResource
}
// GetActionGroupResourceE gets the ActionGroupResource with Error details on error.
// ruleName - required to find the ActionGroupResource.
// resGroupName - use an empty string if you have the AZURE_RES_GROUP_NAME environment variable set
// subscriptionId - use an empty string if you have the ARM_SUBSCRIPTION_ID environment variable set
func GetActionGroupResourceE(ruleName string, resGroupName string, subscriptionID string) (*insights.ActionGroupResource, error) {
rgName, err := getTargetAzureResourceGroupName(resGroupName)
if err != nil {
return nil, err
}
client, err := CreateActionGroupClient(subscriptionID)
if err != nil {
return nil, err
}
actionGroup, err := client.Get(context.Background(), rgName, ruleName)
if err != nil {
return nil, err
}
return &actionGroup, nil
}
// TODO: remove in next version
func getActionGroupClient(subscriptionID string) (*insights.ActionGroupsClient, error) {
subID, err := getTargetAzureSubscription(subscriptionID)
if err != nil {
return nil, err
}
metricAlertsClient := insights.NewActionGroupsClient(subID)
authorizer, err := NewAuthorizer()
if err != nil {
return nil, err
}
metricAlertsClient.Authorizer = *authorizer
return &metricAlertsClient, nil
}