Skip to content

Commit

Permalink
fix bulk patch
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Sheffield committed Feb 20, 2023
1 parent 8dc9462 commit 5243f0d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 39 deletions.
24 changes: 12 additions & 12 deletions opensearchapi/api._.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down
52 changes: 25 additions & 27 deletions opensearchapi/api.security.patch.rule_mappings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down

0 comments on commit 5243f0d

Please sign in to comment.