Skip to content

Commit

Permalink
Merge pull request #3151 from terraform-providers/f/api-management-en…
Browse files Browse the repository at this point in the history
…hancements

r/api_management: support for `sign_in`, `sign_up` and `policy` blocks
  • Loading branch information
tombuildsstuff authored Apr 3, 2019
2 parents 53744b8 + 7ded2e6 commit e1a8461
Show file tree
Hide file tree
Showing 7 changed files with 734 additions and 46 deletions.
15 changes: 15 additions & 0 deletions azurerm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,14 @@ type ArmClient struct {
apiManagementGroupUsersClient apimanagement.GroupUserClient
apiManagementLoggerClient apimanagement.LoggerClient
apiManagementOpenIdConnectClient apimanagement.OpenIDConnectProviderClient
apiManagementPolicyClient apimanagement.PolicyClient
apiManagementProductsClient apimanagement.ProductClient
apiManagementProductApisClient apimanagement.ProductAPIClient
apiManagementProductGroupsClient apimanagement.ProductGroupClient
apiManagementPropertyClient apimanagement.PropertyClient
apiManagementServiceClient apimanagement.ServiceClient
apiManagementSignInClient apimanagement.SignInSettingsClient
apiManagementSignUpClient apimanagement.SignUpSettingsClient
apiManagementSubscriptionsClient apimanagement.SubscriptionClient
apiManagementUsersClient apimanagement.UserClient

Expand Down Expand Up @@ -530,10 +533,22 @@ func (c *ArmClient) registerApiManagementServiceClients(endpoint, subscriptionId
c.configureClient(&loggerClient.Client, auth)
c.apiManagementLoggerClient = loggerClient

policyClient := apimanagement.NewPolicyClientWithBaseURI(endpoint, subscriptionId)
c.configureClient(&policyClient.Client, auth)
c.apiManagementPolicyClient = policyClient

serviceClient := apimanagement.NewServiceClientWithBaseURI(endpoint, subscriptionId)
c.configureClient(&serviceClient.Client, auth)
c.apiManagementServiceClient = serviceClient

signInClient := apimanagement.NewSignInSettingsClientWithBaseURI(endpoint, subscriptionId)
c.configureClient(&signInClient.Client, auth)
c.apiManagementSignInClient = signInClient

signUpClient := apimanagement.NewSignUpSettingsClientWithBaseURI(endpoint, subscriptionId)
c.configureClient(&signUpClient.Client, auth)
c.apiManagementSignUpClient = signUpClient

openIdConnectClient := apimanagement.NewOpenIDConnectProviderClientWithBaseURI(endpoint, subscriptionId)
c.configureClient(&openIdConnectClient.Client, auth)
c.apiManagementOpenIdConnectClient = openIdConnectClient
Expand Down
47 changes: 47 additions & 0 deletions azurerm/helpers/suppress/xml.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package suppress

import (
"encoding/xml"
"io"
"reflect"
"strings"

"github.com/hashicorp/terraform/helper/schema"
)

func XmlDiff(_, old, new string, _ *schema.ResourceData) bool {
oldTokens, err := expandXmlTokensFromString(old)
if err != nil {
return false
}

newTokens, err := expandXmlTokensFromString(new)
if err != nil {
return false
}

return reflect.DeepEqual(oldTokens, newTokens)
}

// This function will extract all XML tokens from a string, but ignoring all white-space tokens
func expandXmlTokensFromString(input string) ([]xml.Token, error) {
decoder := xml.NewDecoder(strings.NewReader(input))
tokens := make([]xml.Token, 0)
for {
token, err := decoder.Token()
if err != nil {
if err == io.EOF {
break
}
return nil, err
}
if chars, ok := token.(xml.CharData); ok {
text := string(chars)
if strings.TrimSpace(text) == "" {
continue
}
}
tokens = append(tokens, xml.CopyToken(token))
}
return tokens, nil
}
81 changes: 81 additions & 0 deletions azurerm/helpers/suppress/xml_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package suppress

import "testing"

func TestXmlDiff(t *testing.T) {
cases := []struct {
Name string
XmlA string
XmlB string
Suppress bool
}{
{
Name: "empty",
XmlA: "",
XmlB: "",
Suppress: true,
},
{
Name: "neither are xml",
XmlA: "this is not an xml",
XmlB: "neither is this",
Suppress: false,
},
{
Name: "identical texts",
XmlA: "this is not an xml",
XmlB: "this is not an xml",
Suppress: true,
},
{
Name: "xml vs text",
XmlA: "<r></r>",
XmlB: "this is not an xml",
Suppress: false,
},
{
Name: "text vs xml",
XmlA: "this is not an xml",
XmlB: "<r></r>",
Suppress: false,
},
{
Name: "identical xml",
XmlA: "<r><c></c></r>",
XmlB: "<r><c></c></r>",
Suppress: true,
},
{
Name: "xml with different line endings",
XmlA: "<r>\n<c>\n</c>\n</r>",
XmlB: "<r>\r\n<c>\r\n</c>\r\n</r>",
Suppress: true,
},
{
Name: "xml with different indentations",
XmlA: "<r>\n <c>\n </c>\n</r>",
XmlB: "<r>\r\n\t<c>\r\n\t</c>\r\n</r>",
Suppress: true,
},
{
Name: "xml with different quotation marks",
XmlA: "<r><c attr=\"test\"></c></r>",
XmlB: "<r>\r\n\t<c attr='test'>\r\n\t</c>\r\n</r>",
Suppress: true,
},
{
Name: "xml with different spaces",
XmlA: "<r><c attr = 'test'></c></r>",
XmlB: "<r>\r\n\t<c attr='test'>\r\n\t</c>\r\n</r>",
Suppress: true,
},
}

for _, tc := range cases {
t.Run(tc.Name, func(t *testing.T) {
if XmlDiff("test", tc.XmlA, tc.XmlB, nil) != tc.Suppress {
t.Fatalf("Expected XmlDiff to return %t for '%q' == '%q'", tc.Suppress, tc.XmlA, tc.XmlB)
}
})
}
}
Loading

0 comments on commit e1a8461

Please sign in to comment.