Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
Signed-off-by: Kawika Avilla <[email protected]>
  • Loading branch information
kavilla committed May 2, 2024
1 parent e3b9e8f commit 0b166e8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/core/server/opensearch/client/client_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export function parseClientOptions(config: OpenSearchClientConfig, scoped: boole
}

if (config.compression) {
clientOptions.compression = 'gzip';
clientOptions.compression = config.compression;

Check warning on line 125 in src/core/server/opensearch/client/client_config.ts

View check run for this annotation

Codecov / codecov/patch

src/core/server/opensearch/client/client_config.ts#L125

Added line #L125 was not covered by tests
}

return clientOptions;
Expand Down
15 changes: 12 additions & 3 deletions src/core/server/opensearch/opensearch_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ import { schema, TypeOf } from '@osd/config-schema';
import { Duration } from 'moment';
import { readFileSync } from 'fs';
import { ConfigDeprecationProvider } from 'src/core/server';
import { ClientOptions } from '@opensearch-project/opensearch';
import { readPkcs12Keystore, readPkcs12Truststore } from '../utils';
import { ServiceConfigDescriptor } from '../internal_types';

const hostURISchema = schema.uri({ scheme: ['http', 'https'] });

export const DEFAULT_API_VERSION = '7.x';
export const DEFAULT_COMPRESSION = 'gzip';

export type OpenSearchConfigType = TypeOf<typeof configSchema>;
type SslConfigSchema = OpenSearchConfigType['ssl'];
Expand Down Expand Up @@ -131,7 +133,9 @@ export const configSchema = schema.object({
healthCheck: schema.object({ delay: schema.duration({ defaultValue: 2500 }) }),
ignoreVersionMismatch: schema.boolean({ defaultValue: false }),
disablePrototypePoisoningProtection: schema.maybe(schema.boolean({ defaultValue: false })),
compression: schema.maybe(schema.boolean({ defaultValue: false })),
compression: schema.maybe(
schema.oneOf([schema.literal(DEFAULT_COMPRESSION), schema.boolean({ defaultValue: false })])
),
});

const deprecations: ConfigDeprecationProvider = ({ renameFromRoot, renameFromRootWithoutMap }) => [
Expand Down Expand Up @@ -318,7 +322,7 @@ export class OpenSearchConfig {
* Specifies whether the client should use compression to engine
* or not.
*/
public readonly compression?: boolean;
public readonly compression?: ClientOptions['compression'];

constructor(rawConfig: OpenSearchConfigType) {
this.ignoreVersionMismatch = rawConfig.ignoreVersionMismatch;
Expand All @@ -341,7 +345,12 @@ export class OpenSearchConfig {
this.password = rawConfig.password;
this.customHeaders = rawConfig.customHeaders;
this.disablePrototypePoisoningProtection = rawConfig.disablePrototypePoisoningProtection;
this.compression = rawConfig.compression;
this.compression =
typeof rawConfig.compression === 'boolean' && rawConfig.compression
? DEFAULT_COMPRESSION
: typeof rawConfig.compression === 'string'
? rawConfig.compression
: undefined;

const { alwaysPresentCertificate, verificationMode } = rawConfig.ssl;
const { key, keyPassphrase, certificate, certificateAuthorities } = readKeyAndCerts(rawConfig);
Expand Down

0 comments on commit 0b166e8

Please sign in to comment.