-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
importer-msgraph-metadata: add service workaround to add missing GET …
…method for synchronization secrets
- Loading branch information
1 parent
ff34b34
commit 6cef487
Showing
7 changed files
with
116 additions
and
6 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
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
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
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
78 changes: 78 additions & 0 deletions
78
tools/importer-msgraph-metadata/components/workarounds/workaround_synchronizationsecrets.go
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,78 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package workarounds | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/hashicorp/go-azure-helpers/lang/pointer" | ||
"github.com/hashicorp/pandora/tools/importer-msgraph-metadata/components/normalize" | ||
"github.com/hashicorp/pandora/tools/importer-msgraph-metadata/components/parser" | ||
) | ||
|
||
var _ serviceWorkaround = workaroundSynchronizationSecrets{} | ||
|
||
// workaroundSynchronizationSecrets adds a missing GET method for synchronization secrets, which is absent from upstream specs. | ||
type workaroundSynchronizationSecrets struct{} | ||
|
||
func (workaroundSynchronizationSecrets) Name() string { | ||
return "Synchronization Secrets / add missing get method" | ||
} | ||
|
||
func (workaroundSynchronizationSecrets) Process(apiVersion, serviceName string, resources parser.Resources, resourceIds parser.ResourceIds) error { | ||
serviceNamesToPaths := map[string]string{ | ||
"servicePrincipals": "/servicePrincipals/{servicePrincipal-id}/synchronization/secrets", | ||
} | ||
|
||
for serviceNameToMatch, path := range serviceNamesToPaths { | ||
if serviceNameToMatch != serviceName { | ||
return nil | ||
} | ||
|
||
resourceName := fmt.Sprintf("%sSynchronizationSecret", normalize.Singularize(normalize.CleanName(serviceName))) | ||
resource, ok := resources[resourceName] | ||
if !ok { | ||
return fmt.Errorf("%q was not found for the service %q", resourceName, serviceName) | ||
} | ||
|
||
tags := []string{serviceName + ".synchronization"} | ||
|
||
var resourceId *parser.ResourceId | ||
var uriSuffix *string | ||
|
||
parsedPath := parser.NewResourceId(path, tags) | ||
match, ok := resourceIds.MatchIdOrAncestor(parsedPath) | ||
if ok { | ||
if match.Id != nil { | ||
resourceId = match.Id | ||
} | ||
if match.Remainder != nil && len(match.Remainder.Segments) > 0 { | ||
uriSuffix = pointer.To(match.Remainder.ID()) | ||
} | ||
} else { | ||
uriSuffix = pointer.To(parsedPath.ID()) | ||
} | ||
|
||
resource.Operations = append(resource.Operations, parser.Operation{ | ||
Name: "GetSynchronizationSecret", | ||
Description: "Retrieve synchronization secrets.", | ||
Type: parser.OperationTypeRead, | ||
Method: http.MethodGet, | ||
ResourceId: resourceId, | ||
UriSuffix: uriSuffix, | ||
Responses: parser.Responses{ | ||
{ | ||
Status: http.StatusOK, | ||
ContentType: pointer.To("application/json"), | ||
ReferenceName: pointer.To("microsoft.graph.synchronizationSecret"), | ||
Type: pointer.To(parser.DataTypeReference), | ||
}, | ||
}, | ||
Tags: tags, | ||
}) | ||
} | ||
|
||
return nil | ||
} |
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
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