Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r/api_management: support for sign_in, sign_up and policy blocks #3151

Merged
merged 4 commits into from
Apr 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
tombuildsstuff marked this conversation as resolved.
Show resolved Hide resolved
}

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