-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
appService.go
77 lines (63 loc) · 2 KB
/
appService.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package azure
import (
"context"
"testing"
"github.com/Azure/azure-sdk-for-go/services/web/mgmt/2019-08-01/web"
"github.com/stretchr/testify/require"
)
// AppExists indicates whether the specified application exists.
// This function would fail the test if there is an error.
func AppExists(t *testing.T, appName string, resourceGroupName string, subscriptionID string) bool {
exists, err := AppExistsE(appName, resourceGroupName, subscriptionID)
require.NoError(t, err)
return exists
}
// AppExistsE indicates whether the specified application exists.
func AppExistsE(appName string, resourceGroupName string, subscriptionID string) (bool, error) {
_, err := GetAppServiceE(appName, resourceGroupName, subscriptionID)
if err != nil {
if ResourceNotFoundErrorExists(err) {
return false, nil
}
return false, err
}
return true, nil
}
// GetAppService gets the App service object
// This function would fail the test if there is an error.
func GetAppService(t *testing.T, appName string, resGroupName string, subscriptionID string) *web.Site {
site, err := GetAppServiceE(appName, resGroupName, subscriptionID)
require.NoError(t, err)
return site
}
// GetAppServiceE gets the App service object
func GetAppServiceE(appName string, resGroupName string, subscriptionID string) (*web.Site, error) {
rgName, err := getTargetAzureResourceGroupName(resGroupName)
if err != nil {
return nil, err
}
client, err := GetAppServiceClientE(subscriptionID)
if err != nil {
return nil, err
}
resource, err := client.Get(context.Background(), rgName, appName)
if err != nil {
return nil, err
}
return &resource, nil
}
func GetAppServiceClientE(subscriptionID string) (*web.AppsClient, error) {
// Create an Apps client
appsClient, err := CreateAppServiceClientE(subscriptionID)
if err != nil {
return nil, err
}
// Create an authorizer
authorizer, err := NewAuthorizer()
if err != nil {
return nil, err
}
// Attach authorizer to the client
appsClient.Authorizer = *authorizer
return appsClient, nil
}