From 5243f0d1d8dea1055d125bd45a5010c17fc73187 Mon Sep 17 00:00:00 2001 From: Sam Sheffield Date: Sun, 19 Feb 2023 19:36:59 -0500 Subject: [PATCH] fix bulk patch --- opensearchapi/api._.go | 24 ++++----- .../api.security.patch.rule_mappings.go | 52 +++++++++---------- 2 files changed, 37 insertions(+), 39 deletions(-) diff --git a/opensearchapi/api._.go b/opensearchapi/api._.go index 50249d4..5931332 100755 --- a/opensearchapi/api._.go +++ b/opensearchapi/api._.go @@ -202,12 +202,12 @@ type Remote struct { // Security contains the Security APIs type Security struct { - Create CreateSecurityRoleMapping - BulkUpsert BulkUpsertSecurityRoleMapping - Patch PatchSecurityRoleMapping - Delete DeleteSecurityRoleMapping - Get GetSecurityRoleMapping - List ListSecurityRoleMapping + Create CreateSecurityRoleMapping + BulkPatch BulkPatchSecurityRoleMapping + Patch PatchSecurityRoleMapping + Delete DeleteSecurityRoleMapping + Get GetSecurityRoleMapping + List ListSecurityRoleMapping } // Snapshot contains the Snapshot APIs @@ -381,12 +381,12 @@ func New(t Transport) *API { }, Remote: &Remote{}, Security: &Security{ - Create: newCreateSecurityRoleMappingFunc(t), - BulkUpsert: newBulkUpsertSecurityRoleMappingFunc(t), - Patch: newPatchSecurityRoleMappingFunc(t), - Delete: newDeleteSecurityRoleMappingFunc(t), - Get: newGetSecurityRoleMappingFunc(t), - List: newListSecurityRoleMappingFunc(t), + Create: newCreateSecurityRoleMappingFunc(t), + BulkPatch: newBulkPatchSecurityRoleMappingFunc(t), + Patch: newPatchSecurityRoleMappingFunc(t), + Delete: newDeleteSecurityRoleMappingFunc(t), + Get: newGetSecurityRoleMappingFunc(t), + List: newListSecurityRoleMappingFunc(t), }, Snapshot: &Snapshot{ CleanupRepository: newSnapshotCleanupRepositoryFunc(t), diff --git a/opensearchapi/api.security.patch.rule_mappings.go b/opensearchapi/api.security.patch.rule_mappings.go index e7a5329..cc50e9d 100644 --- a/opensearchapi/api.security.patch.rule_mappings.go +++ b/opensearchapi/api.security.patch.rule_mappings.go @@ -7,9 +7,9 @@ import ( "strings" ) -func newBulkUpsertSecurityRoleMappingFunc(t Transport) BulkUpsertSecurityRoleMapping { - return func(name string, body io.Reader, o ...func(*BulkUpsertSecurityRoleMappingRequest)) (*Response, error) { - var r = BulkUpsertSecurityRoleMappingRequest{Name: name, Body: body} +func newBulkPatchSecurityRoleMappingFunc(t Transport) BulkPatchSecurityRoleMapping { + return func(body io.Reader, o ...func(*BulkPatchSecurityRoleMappingRequest)) (*Response, error) { + var r = BulkPatchSecurityRoleMappingRequest{Body: body} for _, f := range o { f(&r) } @@ -19,16 +19,14 @@ func newBulkUpsertSecurityRoleMappingFunc(t Transport) BulkUpsertSecurityRoleMap // ----- API Definition ------------------------------------------------------- -// BulkUpsertSecurityRoleMapping Bulk Upsert multiple role mappings +// BulkPatchSecurityRoleMapping Bulk Patch multiple role mappings // // To use this API, you must have at least the manage_security cluster privilege. -// https://opensearch.org/docs/2.3/security/access-control/api/#BulkUpsert-role-mapping -type BulkUpsertSecurityRoleMapping func(name string, body io.Reader, o ...func(*BulkUpsertSecurityRoleMappingRequest)) (*Response, error) - -// BulkUpsertSecurityRoleMappingRequest configures the BulkUpsert Security Rule Mapping API request. -type BulkUpsertSecurityRoleMappingRequest struct { - Name string +// https://opensearch.org/docs/2.3/security/access-control/api/#BulkPatch-role-mapping +type BulkPatchSecurityRoleMapping func(body io.Reader, o ...func(*BulkPatchSecurityRoleMappingRequest)) (*Response, error) +// BulkPatchSecurityRoleMappingRequest configures the BulkPatch Security Rule Mapping API request. +type BulkPatchSecurityRoleMappingRequest struct { Body io.Reader Pretty bool @@ -42,7 +40,7 @@ type BulkUpsertSecurityRoleMappingRequest struct { } // Do will execute the request and returns response or error. -func (r BulkUpsertSecurityRoleMappingRequest) Do(ctx context.Context, transport Transport) (*Response, error) { +func (r BulkPatchSecurityRoleMappingRequest) Do(ctx context.Context, transport Transport) (*Response, error) { var ( method string path strings.Builder @@ -51,8 +49,8 @@ func (r BulkUpsertSecurityRoleMappingRequest) Do(ctx context.Context, transport method = http.MethodPatch - path.Grow(len("/_plugins/_security/api/rolesmapping/")) - path.WriteString("/_plugins/_security/api/rolesmapping/") + path.Grow(len("/_plugins/_security/api/rolesmapping")) + path.WriteString("/_plugins/_security/api/rolesmapping") params = make(map[string]string) if r.Pretty { @@ -115,43 +113,43 @@ func (r BulkUpsertSecurityRoleMappingRequest) Do(ctx context.Context, transport } // WithContext sets the request context. -func (f BulkUpsertSecurityRoleMapping) WithContext(v context.Context) func(*BulkUpsertSecurityRoleMappingRequest) { - return func(r *BulkUpsertSecurityRoleMappingRequest) { +func (f BulkPatchSecurityRoleMapping) WithContext(v context.Context) func(*BulkPatchSecurityRoleMappingRequest) { + return func(r *BulkPatchSecurityRoleMappingRequest) { r.ctx = v } } // WithPretty makes the response body pretty-printed. -func (f BulkUpsertSecurityRoleMapping) WithPretty() func(*BulkUpsertSecurityRoleMappingRequest) { - return func(r *BulkUpsertSecurityRoleMappingRequest) { +func (f BulkPatchSecurityRoleMapping) WithPretty() func(*BulkPatchSecurityRoleMappingRequest) { + return func(r *BulkPatchSecurityRoleMappingRequest) { r.Pretty = true } } // WithHuman makes statistical values human-readable. -func (f BulkUpsertSecurityRoleMapping) WithHuman() func(*BulkUpsertSecurityRoleMappingRequest) { - return func(r *BulkUpsertSecurityRoleMappingRequest) { +func (f BulkPatchSecurityRoleMapping) WithHuman() func(*BulkPatchSecurityRoleMappingRequest) { + return func(r *BulkPatchSecurityRoleMappingRequest) { r.Human = true } } // WithErrorTrace includes the stack trace for errors in the response body. -func (f BulkUpsertSecurityRoleMapping) WithErrorTrace() func(*BulkUpsertSecurityRoleMappingRequest) { - return func(r *BulkUpsertSecurityRoleMappingRequest) { +func (f BulkPatchSecurityRoleMapping) WithErrorTrace() func(*BulkPatchSecurityRoleMappingRequest) { + return func(r *BulkPatchSecurityRoleMappingRequest) { r.ErrorTrace = true } } // WithFilterPath filters the properties of the response body. -func (f BulkUpsertSecurityRoleMapping) WithFilterPath(v ...string) func(*BulkUpsertSecurityRoleMappingRequest) { - return func(r *BulkUpsertSecurityRoleMappingRequest) { +func (f BulkPatchSecurityRoleMapping) WithFilterPath(v ...string) func(*BulkPatchSecurityRoleMappingRequest) { + return func(r *BulkPatchSecurityRoleMappingRequest) { r.FilterPath = v } } // WithHeader adds the headers to the HTTP request. -func (f BulkUpsertSecurityRoleMapping) WithHeader(h map[string]string) func(*BulkUpsertSecurityRoleMappingRequest) { - return func(r *BulkUpsertSecurityRoleMappingRequest) { +func (f BulkPatchSecurityRoleMapping) WithHeader(h map[string]string) func(*BulkPatchSecurityRoleMappingRequest) { + return func(r *BulkPatchSecurityRoleMappingRequest) { if r.Header == nil { r.Header = make(http.Header) } @@ -162,8 +160,8 @@ func (f BulkUpsertSecurityRoleMapping) WithHeader(h map[string]string) func(*Bul } // WithOpaqueID adds the X-Opaque-Id header to the HTTP request. -func (f BulkUpsertSecurityRoleMapping) WithOpaqueID(s string) func(*BulkUpsertSecurityRoleMappingRequest) { - return func(r *BulkUpsertSecurityRoleMappingRequest) { +func (f BulkPatchSecurityRoleMapping) WithOpaqueID(s string) func(*BulkPatchSecurityRoleMappingRequest) { + return func(r *BulkPatchSecurityRoleMappingRequest) { if r.Header == nil { r.Header = make(http.Header) }