-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
app_configuration_feature.go
74 lines (59 loc) · 2.27 KB
/
app_configuration_feature.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
package parse
import (
"fmt"
"net/url"
"regexp"
"strings"
"github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids"
)
var _ resourceids.Id = AppConfigurationFeatureId{}
type AppConfigurationFeatureId struct {
ConfigurationStoreId string
Name string
Label string
}
func (id AppConfigurationFeatureId) ID() string {
return fmt.Sprintf("%s/AppConfigurationFeature/%s/Label/%s", id.ConfigurationStoreId, id.Name, id.Label)
}
func (id AppConfigurationFeatureId) String() string {
components := []string{
fmt.Sprintf("Configuration Store Id %q", id.ConfigurationStoreId),
fmt.Sprintf("Label %q", id.Label),
fmt.Sprintf("Name %q", id.Name),
}
return fmt.Sprintf("Feature: %s", strings.Join(components, " / "))
}
func FeatureId(input string) (*AppConfigurationFeatureId, error) {
resourceID, err := parseAzureResourceID(handleSlashInIdForFeature(input))
if err != nil {
return nil, fmt.Errorf("while parsing resource ID: %+v", err)
}
keyName := resourceID.Path["AppConfigurationFeature"]
label := resourceID.Path["Label"]
appcfgID := AppConfigurationFeatureId{
Name: keyName,
Label: label,
}
// Golang's URL parser will translate %00 to \000 (NUL). This will only happen if we're dealing with an empty
// label, so we set the label to the expected value (empty string) and trim the input string, so we can properly
// extract the configuration store ID out of it.
if label == "\000" {
appcfgID.Label = ""
input = strings.TrimSuffix(input, "%00")
}
appcfgID.ConfigurationStoreId = strings.TrimSuffix(input, fmt.Sprintf("/AppConfigurationFeature/%s/Label/%s", appcfgID.Name, appcfgID.Label))
return &appcfgID, nil
}
// a workaround to support "/" in id
func handleSlashInIdForFeature(input string) string {
oldNames := regexp.MustCompile(`AppConfigurationFeature\/(.+)\/Label`).FindStringSubmatch(input)
if len(oldNames) == 2 {
input = strings.Replace(input, oldNames[1], url.QueryEscape(oldNames[1]), 1)
}
oldNames = regexp.MustCompile(`AppConfigurationFeature\/.+\/Label\/(.+)`).FindStringSubmatch(input)
// Label will have a "%00" placeholder if we're dealing with an empty label,
if len(oldNames) == 2 && oldNames[1] != "%00" {
input = strings.Replace(input, oldNames[1], url.QueryEscape(oldNames[1]), 1)
}
return input
}