-
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
6c23c8f
commit e0f41f0
Showing
6 changed files
with
175 additions
and
48 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
Oops, something went wrong.