-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add batching for IAM binding/member/audit config changes
Signed-off-by: Modular Magician <magic-modules@google.com>
- Loading branch information
1 parent
302d2a2
commit 87fdd97
Showing
10 changed files
with
181 additions
and
54 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package google | ||
|
||
import ( | ||
"fmt" | ||
"google.golang.org/api/cloudresourcemanager/v1" | ||
"time" | ||
) | ||
|
||
const ( | ||
batchKeyTmplModifyIamPolicy = "%s modifyIamPolicy" | ||
|
||
IamBatchingEnabled = true | ||
IamBatchingDisabled = false | ||
) | ||
|
||
func BatchRequestModifyIamPolicy(updater ResourceIamUpdater, modify iamPolicyModifyFunc, config *Config, reqDesc string) error { | ||
batchKey := fmt.Sprintf(batchKeyTmplModifyIamPolicy, updater.GetMutexKey()) | ||
|
||
request := &BatchRequest{ | ||
ResourceName: updater.GetResourceId(), | ||
Body: []iamPolicyModifyFunc{modify}, | ||
CombineF: combineBatchIamPolicyModifiers, | ||
SendF: sendBatchModifyIamPolicy(updater), | ||
DebugId: reqDesc, | ||
} | ||
|
||
_, err := config.requestBatcherIam.SendRequestWithTimeout(batchKey, request, time.Minute*30) | ||
return err | ||
} | ||
|
||
func combineBatchIamPolicyModifiers(currV interface{}, toAddV interface{}) (interface{}, error) { | ||
currModifiers, ok := currV.([]iamPolicyModifyFunc) | ||
if !ok { | ||
return nil, fmt.Errorf("provider error in batch combiner: expected data to be type []iamPolicyModifyFunc, got %v with type %T", currV, currV) | ||
} | ||
|
||
newModifiers, ok := toAddV.([]iamPolicyModifyFunc) | ||
if !ok { | ||
return nil, fmt.Errorf("provider error in batch combiner: expected data to be type []iamPolicyModifyFunc, got %v with type %T", currV, currV) | ||
} | ||
|
||
return append(currModifiers, newModifiers...), nil | ||
} | ||
|
||
func sendBatchModifyIamPolicy(updater ResourceIamUpdater) batcherSendFunc { | ||
return func(resourceName string, body interface{}) (interface{}, error) { | ||
modifiers, ok := body.([]iamPolicyModifyFunc) | ||
if !ok { | ||
return nil, fmt.Errorf("provider error: expected data to be type []iamPolicyModifyFunc, got %v with type %T", body, body) | ||
} | ||
return nil, iamPolicyReadModifyWrite(updater, func(policy *cloudresourcemanager.Policy) error { | ||
for _, modifyF := range modifiers { | ||
if err := modifyF(policy); err != nil { | ||
return err | ||
} | ||
} | ||
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
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
Oops, something went wrong.