-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add logic app ID for differentiation in app service
- Loading branch information
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package commonids | ||
|
||
import "fmt" | ||
|
||
// NOTE: A Logic App is just an App Service instance - but to allow for potential differentiation in the future | ||
// we're wrapping this to provide a unique Type, Parse and Validation functions. | ||
|
||
type LogicAppId = AppServiceId | ||
|
||
// ParseLogicAppId parses 'input' into a LogicAppId | ||
func ParseLogicAppId(input string) (*LogicAppId, error) { | ||
parsed, err := ParseAppServiceID(input) | ||
if err != nil { | ||
return nil, fmt.Errorf("parsing %q as a Logic App ID: %+v", input, err) | ||
} | ||
|
||
return &LogicAppId{ | ||
SubscriptionId: parsed.SubscriptionId, | ||
ResourceGroupName: parsed.ResourceGroupName, | ||
SiteName: parsed.SiteName, | ||
}, nil | ||
} | ||
|
||
// ParseLogicAppIdInsensitively parses 'input' case-insensitively into a LogicAppId | ||
// note: this method should only be used for API response data and not user input | ||
func ParseLogicAppIdInsensitively(input string) (*LogicAppId, error) { | ||
parsed, err := ParseAppServiceIDInsensitively(input) | ||
if err != nil { | ||
return nil, fmt.Errorf("parsing %q as a Logic App ID: %+v", input, err) | ||
} | ||
|
||
return &LogicAppId{ | ||
SubscriptionId: parsed.SubscriptionId, | ||
ResourceGroupName: parsed.ResourceGroupName, | ||
SiteName: parsed.SiteName, | ||
}, nil | ||
} | ||
|
||
// ValidateLogicAppId checks that 'input' can be parsed as a Logic App ID | ||
func ValidateLogicAppId(input interface{}, key string) (warnings []string, errors []error) { | ||
v, ok := input.(string) | ||
if !ok { | ||
errors = append(errors, fmt.Errorf("expected %q to be a string", key)) | ||
return | ||
} | ||
|
||
if _, err := ParseLogicAppId(v); err != nil { | ||
errors = append(errors, err) | ||
} | ||
|
||
return | ||
} |