diff --git a/CHANGELOG.md b/CHANGELOG.md index 850d6681c..fd3f9122c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,8 +8,10 @@ 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 +- Security roles get response struct has its own sub structs without omitempty ([#572](https://github.com/opensearch-project/opensearch-go/pull/572)) ### Deprecated @@ -19,6 +21,10 @@ 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)) +- 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/internal/test/helper.go b/internal/test/helper.go index da03ca106..ebea0ad98 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) } } diff --git a/opensearchapi/api_indices-mapping.go b/opensearchapi/api_indices-mapping.go index 64d17a597..4b10f8aab 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 96bc8a928..bf332b04c 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 } diff --git a/opensearchapi/api_nodes-stats.go b/opensearchapi/api_nodes-stats.go index 9f88916bf..29de816f0 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"` +} diff --git a/plugins/security/api_actiongroups.go b/plugins/security/api_actiongroups.go index a5c5755a6..28f31f5ee 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 88399be0f..5fe9f756a 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-get.go b/plugins/security/api_roles-get.go index 3108d4902..b208702b5 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 a00fd7fd1..5b9e7c1a6 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 8f904e2f5..4c627bb6c 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 } @@ -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"` -} diff --git a/plugins/security/api_rolesmapping.go b/plugins/security/api_rolesmapping.go index d3062a79e..583414571 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 2067b95a3..a4d60a6a4 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 }