From a14a2852f06fafab6272b144ea0fc9d7f44142a6 Mon Sep 17 00:00:00 2001 From: Jakob Hahn Date: Wed, 26 Jun 2024 15:14:40 +0200 Subject: [PATCH 1/6] opensearchapi: add caches field to nodes stats Signed-off-by: Jakob Hahn --- CHANGELOG.md | 1 + opensearchapi/api_nodes-stats.go | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 850d6681..1351ff7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Adds the `Routing` field in SearchHit interface. ([#516](https://github.com/opensearch-project/opensearch-go/pull/516)) - Adds the `SearchPipelines` field to `SearchParams` ([#532](https://github.com/opensearch-project/opensearch-go/pull/532)) - Adds support for OpenSearch 2.14 ([#552](https://github.com/opensearch-project/opensearch-go/pull/552)) +- Adds the `Caches` field to Node stats ([#572](https://github.com/opensearch-project/opensearch-go/pull/572)) ### Changed diff --git a/opensearchapi/api_nodes-stats.go b/opensearchapi/api_nodes-stats.go index 9f88916b..29de816f 100644 --- a/opensearchapi/api_nodes-stats.go +++ b/opensearchapi/api_nodes-stats.go @@ -111,6 +111,7 @@ type NodesStats struct { SegmentReplicationBackpressure NodesStatsSegmentReplicationBackpressure `json:"segment_replication_backpressure"` Repositories []json.RawMessage `json:"repositories"` AdmissionControl NodesStatsAdmissionControl `json:"admission_control"` + Caches NodesStatsCaches `json:"caches"` } // NodesStatsIndices is a sub type of NodesStats representing Indices information of the node @@ -702,7 +703,7 @@ type NodesStatsSegmentReplicationBackpressure struct { TotalRejectedRequests int `json:"total_rejected_requests"` } -// NodesStatsAdmissionControl is a sub of NodesStats +// NodesStatsAdmissionControl is a sub type of NodesStats type NodesStatsAdmissionControl struct { GlobalCPUUsage struct { Transport struct { @@ -715,3 +716,15 @@ type NodesStatsAdmissionControl struct { } `json:"transport"` } `json:"global_io_usage"` } + +// NodesStatsCaches is a sub type of NodesStats +type NodesStatsCaches struct { + RequestCache struct { + SizeInBytes int `json:"size_in_bytes"` + Evictions int `json:"evictions"` + HitCount int `json:"hit_count"` + MissCount int `json:"miss_count"` + ItemCount int `json:"item_count"` + StoreName string `json:"store_name"` + } `json:"request_cache"` +} From 77333fdefe29ca95d870f3fdf27a0fbeff4fbebf Mon Sep 17 00:00:00 2001 From: Jakob Hahn Date: Wed, 26 Jun 2024 15:17:08 +0200 Subject: [PATCH 2/6] internal: fix test help json compare when object is null Signed-off-by: Jakob Hahn --- CHANGELOG.md | 1 + internal/test/helper.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1351ff7a..5ba74828 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Fixes empty request body on retry with compression enabled ([#543](https://github.com/opensearch-project/opensearch-go/pull/543)) - Fixes `Conditions` in `PolicyStateTransition` of ISM plugin ([#556](https://github.com/opensearch-project/opensearch-go/pull/556)) +- Fixes integration test response validation when response is null ([#572](https://github.com/opensearch-project/opensearch-go/pull/572)) ### Security diff --git a/internal/test/helper.go b/internal/test/helper.go index da03ca10..ebea0ad9 100644 --- a/internal/test/helper.go +++ b/internal/test/helper.go @@ -140,7 +140,7 @@ func CompareRawJSONwithParsedJSON(t *testing.T, resp any, rawResp *opensearch.Re operations := make([]jsondiff.Operation, 0) for _, operation := range patch { // different opensearch version added more field, only check if we miss some fields - if operation.Type != "add" { + if operation.Type != "add" || (operation.Type == "add" && operation.Path == "") { operations = append(operations, operation) } } From a5becda38fa8ce8634e958402790e563cdef269f Mon Sep 17 00:00:00 2001 From: Jakob Hahn Date: Wed, 26 Jun 2024 15:20:37 +0200 Subject: [PATCH 3/6] plugins: adjust role struct fls from string to slice Signed-off-by: Jakob Hahn --- CHANGELOG.md | 1 + plugins/security/api_roles.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ba74828..a891ce45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Fixes empty request body on retry with compression enabled ([#543](https://github.com/opensearch-project/opensearch-go/pull/543)) - Fixes `Conditions` in `PolicyStateTransition` of ISM plugin ([#556](https://github.com/opensearch-project/opensearch-go/pull/556)) - Fixes integration test response validation when response is null ([#572](https://github.com/opensearch-project/opensearch-go/pull/572)) +- Adjust security Role struct for FLS from string to []string ([#572](https://github.com/opensearch-project/opensearch-go/pull/572)) ### Security diff --git a/plugins/security/api_roles.go b/plugins/security/api_roles.go index 8f904e2f..8bfa5581 100644 --- a/plugins/security/api_roles.go +++ b/plugins/security/api_roles.go @@ -74,7 +74,7 @@ func (c rolesClient) Patch(ctx context.Context, req RolesPatchReq) (RolesPatchRe type RolesIndexPermission struct { IndexPatterns []string `json:"index_patterns,omitempty"` DLS string `json:"dls,omitempty"` - FLS string `json:"fls,omitempty"` + FLS []string `json:"fls,omitempty"` MaskedFields []string `json:"masked_fields,omitempty"` AllowedActions []string `json:"allowed_actions,omitempty"` } From 3559e8945bd3830f28dcfb083482a57fb8fa7a7d Mon Sep 17 00:00:00 2001 From: Jakob Hahn Date: Wed, 26 Jun 2024 15:22:08 +0200 Subject: [PATCH 4/6] opensearchapi: fixes wrong response parsing for indices mapping and recovery Signed-off-by: Jakob Hahn --- CHANGELOG.md | 1 + opensearchapi/api_indices-mapping.go | 2 +- opensearchapi/api_indices.go | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a891ce45..7d0f8170 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Fixes `Conditions` in `PolicyStateTransition` of ISM plugin ([#556](https://github.com/opensearch-project/opensearch-go/pull/556)) - Fixes integration test response validation when response is null ([#572](https://github.com/opensearch-project/opensearch-go/pull/572)) - Adjust security Role struct for FLS from string to []string ([#572](https://github.com/opensearch-project/opensearch-go/pull/572)) +- Fixes wrong response parsing for indices mapping and recovery ([#572](https://github.com/opensearch-project/opensearch-go/pull/572)) ### Security diff --git a/opensearchapi/api_indices-mapping.go b/opensearchapi/api_indices-mapping.go index 64d17a59..4b10f8aa 100644 --- a/opensearchapi/api_indices-mapping.go +++ b/opensearchapi/api_indices-mapping.go @@ -60,7 +60,7 @@ func (c mappingClient) Field(ctx context.Context, req *MappingFieldReq) (*Mappin data MappingFieldResp err error ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { + if data.response, err = c.apiClient.do(ctx, req, &data.Indices); err != nil { return &data, err } diff --git a/opensearchapi/api_indices.go b/opensearchapi/api_indices.go index 96bc8a92..bf332b04 100644 --- a/opensearchapi/api_indices.go +++ b/opensearchapi/api_indices.go @@ -215,7 +215,7 @@ func (c indicesClient) Recovery(ctx context.Context, req *IndicesRecoveryReq) (* data IndicesRecoveryResp err error ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { + if data.response, err = c.apiClient.do(ctx, req, &data.Indices); err != nil { return &data, err } From 688bbdde73cbfbc3d0be24f4bb3845da17f8de6f Mon Sep 17 00:00:00 2001 From: Jakob Hahn Date: Wed, 26 Jun 2024 15:42:42 +0200 Subject: [PATCH 5/6] plugins/security: fixes wrong response parsing for get requests Signed-off-by: Jakob Hahn --- CHANGELOG.md | 1 + plugins/security/api_actiongroups.go | 2 +- plugins/security/api_internalusers.go | 2 +- plugins/security/api_roles.go | 2 +- plugins/security/api_rolesmapping.go | 2 +- plugins/security/api_tenants.go | 2 +- 6 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d0f8170..4e47ec93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Fixes integration test response validation when response is null ([#572](https://github.com/opensearch-project/opensearch-go/pull/572)) - Adjust security Role struct for FLS from string to []string ([#572](https://github.com/opensearch-project/opensearch-go/pull/572)) - Fixes wrong response parsing for indices mapping and recovery ([#572](https://github.com/opensearch-project/opensearch-go/pull/572)) +- Fixes wrong response parsing for security get requests ([#572](https://github.com/opensearch-project/opensearch-go/pull/572)) ### Security diff --git a/plugins/security/api_actiongroups.go b/plugins/security/api_actiongroups.go index a5c5755a..28f31f5e 100644 --- a/plugins/security/api_actiongroups.go +++ b/plugins/security/api_actiongroups.go @@ -24,7 +24,7 @@ func (c actiongroupsClient) Get(ctx context.Context, req *ActionGroupsGetReq) (A data ActionGroupsGetResp err error ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { + if data.response, err = c.apiClient.do(ctx, req, &data.Groups); err != nil { return data, err } diff --git a/plugins/security/api_internalusers.go b/plugins/security/api_internalusers.go index 88399be0..5fe9f756 100644 --- a/plugins/security/api_internalusers.go +++ b/plugins/security/api_internalusers.go @@ -24,7 +24,7 @@ func (c internalusersClient) Get(ctx context.Context, req *InternalUsersGetReq) data InternalUsersGetResp err error ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { + if data.response, err = c.apiClient.do(ctx, req, &data.Users); err != nil { return data, err } diff --git a/plugins/security/api_roles.go b/plugins/security/api_roles.go index 8bfa5581..8a21c335 100644 --- a/plugins/security/api_roles.go +++ b/plugins/security/api_roles.go @@ -24,7 +24,7 @@ func (c rolesClient) Get(ctx context.Context, req *RolesGetReq) (RolesGetResp, e data RolesGetResp err error ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { + if data.response, err = c.apiClient.do(ctx, req, &data.Roles); err != nil { return data, err } diff --git a/plugins/security/api_rolesmapping.go b/plugins/security/api_rolesmapping.go index d3062a79..58341457 100644 --- a/plugins/security/api_rolesmapping.go +++ b/plugins/security/api_rolesmapping.go @@ -24,7 +24,7 @@ func (c rolesmappingClient) Get(ctx context.Context, req *RolesMappingGetReq) (R data RolesMappingGetResp err error ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { + if data.response, err = c.apiClient.do(ctx, req, &data.RolesMapping); err != nil { return data, err } diff --git a/plugins/security/api_tenants.go b/plugins/security/api_tenants.go index 2067b95a..a4d60a6a 100644 --- a/plugins/security/api_tenants.go +++ b/plugins/security/api_tenants.go @@ -24,7 +24,7 @@ func (c tenantsClient) Get(ctx context.Context, req *TenantsGetReq) (TenantsGetR data TenantsGetResp err error ) - if data.response, err = c.apiClient.do(ctx, req, &data); err != nil { + if data.response, err = c.apiClient.do(ctx, req, &data.Tenants); err != nil { return data, err } From 11eeb8089fa4f14321e94cfe30e9b1698e23fbfe Mon Sep 17 00:00:00 2001 From: Jakob Hahn Date: Thu, 27 Jun 2024 12:34:27 +0200 Subject: [PATCH 6/6] plugins/security: roles get response struct has its own sub structs without omitempty Signed-off-by: Jakob Hahn --- CHANGELOG.md | 1 + plugins/security/api_roles-get.go | 29 ++++++++++++++++++++++------- plugins/security/api_roles-put.go | 15 +++++++++++++++ plugins/security/api_roles.go | 15 --------------- 4 files changed, 38 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e47ec93..fd3f9122 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Adds the `Caches` field to Node stats ([#572](https://github.com/opensearch-project/opensearch-go/pull/572)) ### Changed +- Security roles get response struct has its own sub structs without omitempty ([#572](https://github.com/opensearch-project/opensearch-go/pull/572)) ### Deprecated diff --git a/plugins/security/api_roles-get.go b/plugins/security/api_roles-get.go index 3108d490..b208702b 100644 --- a/plugins/security/api_roles-get.go +++ b/plugins/security/api_roles-get.go @@ -52,11 +52,26 @@ func (r RolesGetResp) Inspect() Inspect { // RolesGetItem is a sub type of RolesGetResp containing information about a role type RolesGetItem struct { - Reserved bool `json:"reserved"` - Hidden bool `json:"hidden"` - Description string `json:"description"` - ClusterPermissions []string `json:"cluster_permissions"` - IndexPermissions []RolesIndexPermission `json:"index_permissions"` - TenantPermissions []RolesTenantPermission `json:"tenant_permissions"` - Statis bool `json:"static"` + Reserved bool `json:"reserved"` + Hidden bool `json:"hidden"` + Description string `json:"description"` + ClusterPermissions []string `json:"cluster_permissions"` + IndexPermissions []RolesGetIndexPermission `json:"index_permissions"` + TenantPermissions []RolesGetTenantPermission `json:"tenant_permissions"` + Statis bool `json:"static"` +} + +// RolesGetIndexPermission contains index permissions and is used for Get and Put requests +type RolesGetIndexPermission struct { + IndexPatterns []string `json:"index_patterns"` + DLS string `json:"dls"` + FLS []string `json:"fls"` + MaskedFields []string `json:"masked_fields"` + AllowedActions []string `json:"allowed_actions"` +} + +// RolesGetTenantPermission contains tenant permissions and is used for Get and Put requests +type RolesGetTenantPermission struct { + TenantPatterns []string `json:"tenant_patterns"` + AllowedActions []string `json:"allowed_actions"` } diff --git a/plugins/security/api_roles-put.go b/plugins/security/api_roles-put.go index a00fd7fd..5b9e7c1a 100644 --- a/plugins/security/api_roles-put.go +++ b/plugins/security/api_roles-put.go @@ -58,3 +58,18 @@ type RolesPutResp struct { func (r RolesPutResp) Inspect() Inspect { return Inspect{Response: r.response} } + +// RolesIndexPermission contains index permissions and is used for Get and Put requests +type RolesIndexPermission struct { + IndexPatterns []string `json:"index_patterns,omitempty"` + DLS string `json:"dls,omitempty"` + FLS []string `json:"fls,omitempty"` + MaskedFields []string `json:"masked_fields,omitempty"` + AllowedActions []string `json:"allowed_actions,omitempty"` +} + +// RolesTenantPermission contains tenant permissions and is used for Get and Put requests +type RolesTenantPermission struct { + TenantPatterns []string `json:"tenant_patterns,omitempty"` + AllowedActions []string `json:"allowed_actions,omitempty"` +} diff --git a/plugins/security/api_roles.go b/plugins/security/api_roles.go index 8a21c335..4c627bb6 100644 --- a/plugins/security/api_roles.go +++ b/plugins/security/api_roles.go @@ -69,18 +69,3 @@ func (c rolesClient) Patch(ctx context.Context, req RolesPatchReq) (RolesPatchRe return data, nil } - -// RolesIndexPermission contains index permissions and is used for Get and Put requests -type RolesIndexPermission struct { - IndexPatterns []string `json:"index_patterns,omitempty"` - DLS string `json:"dls,omitempty"` - FLS []string `json:"fls,omitempty"` - MaskedFields []string `json:"masked_fields,omitempty"` - AllowedActions []string `json:"allowed_actions,omitempty"` -} - -// RolesTenantPermission contains tenant permissions and is used for Get and Put requests -type RolesTenantPermission struct { - TenantPatterns []string `json:"tenant_patterns,omitempty"` - AllowedActions []string `json:"allowed_actions,omitempty"` -}