This repository has been archived by the owner on Jul 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 100
/
utils.go
55 lines (49 loc) · 1.93 KB
/
utils.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
package storage
import (
"github.com/Azure/azure-sdk-for-go/storage"
"github.com/Azure/open-service-broker-azure/pkg/schemas"
"github.com/Azure/open-service-broker-azure/pkg/service"
)
func buildGoTemplate(
instance service.Instance,
parameter service.ProvisioningParameters,
) map[string]interface{} {
dt := instance.Details.(*instanceDetails)
location := parameter.GetString("location")
nonHTTPSEnabled := parameter.GetString("enableNonHttpsTraffic")
goTemplateParams := map[string]interface{}{
"name": dt.StorageAccountName,
"location": location,
"supportHttpsTrafficOnly": nonHTTPSEnabled == schemas.DisabledParamString,
"accountType": parameter.GetString("accountType"),
}
serviceName := instance.Service.GetName()
switch serviceName {
case serviceGeneralPurposeV1:
goTemplateParams["kind"] = "Storage"
case serviceGeneralPurposeV2:
goTemplateParams["kind"] = "StorageV2"
goTemplateParams["accessTier"] = parameter.GetString("accessTier")
case serviceBlobAccount, serviceBlobAllInOne:
goTemplateParams["kind"] = "BlobStorage"
goTemplateParams["accessTier"] = parameter.GetString("accessTier")
}
return goTemplateParams
}
func createBlobContainer(storageAccountName, accessKey, containerName string) error { // nolint: lll
client, _ := storage.NewBasicClient(storageAccountName, accessKey)
blobCli := client.GetBlobService()
container := blobCli.GetContainerReference(containerName)
options := storage.CreateContainerOptions{
Access: storage.ContainerAccessTypePrivate,
}
return container.Create(&options)
}
func deleteBlobContainer(storageAccountName, accessKey, containerName string) error { // nolint: lll
client, _ := storage.NewBasicClient(storageAccountName, accessKey)
blobCli := client.GetBlobService()
container := blobCli.GetContainerReference(containerName)
options := storage.DeleteContainerOptions{}
_, err := container.DeleteIfExists(&options)
return err
}