Skip to content

Commit

Permalink
FFM-11364 Use target-segments v2-rule parameter (#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
erdirowlands authored May 7, 2024
1 parent d73ab3e commit 5e40a85
Show file tree
Hide file tree
Showing 8 changed files with 586 additions and 110 deletions.
129 changes: 125 additions & 4 deletions api.yaml → client-v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ servers:
tags:
- name: client
- name: metrics
- name: Proxy
description: APIs used by the ff-proxy
paths:
'/client/env/{environmentUUID}/feature-configs':
get:
Expand Down Expand Up @@ -85,6 +87,7 @@ paths:
schema:
type: string
- $ref: '#/components/parameters/clusterQueryOptionalParam'
- $ref: '#/components/parameters/segmentRulesV2QueryParam'
security:
- BearerAuth: []
responses:
Expand Down Expand Up @@ -125,6 +128,7 @@ paths:
schema:
type: string
- $ref: '#/components/parameters/clusterQueryOptionalParam'
- $ref: '#/components/parameters/segmentRulesV2QueryParam'
security:
- BearerAuth: []
responses:
Expand Down Expand Up @@ -199,10 +203,7 @@ paths:
schema:
allOf:
- $ref: '#/components/schemas/Pagination'
- type: object
properties:
evaluations:
$ref: '#/components/schemas/Evaluations'
- $ref: '#/components/schemas/Evaluations'
'/client/env/{environmentUUID}/target/{target}/evaluations/{feature}':
get:
summary: Get feature evaluations for target
Expand Down Expand Up @@ -302,6 +303,84 @@ paths:
default: '*'
'503':
description: Service Unavailable
/proxy/config:
get:
summary: Gets Proxy config for multiple environments
description: >-
Gets Proxy config for multiple environments if the Key query param is
provided or gets config for a single environment if an environment query
param is provided
operationId: GetProxyConfig
tags:
- Proxy
parameters:
- $ref: '#/components/parameters/pageNumber'
- $ref: '#/components/parameters/pageSize'
- $ref: '#/components/parameters/clusterQueryOptionalParam'
- in: query
name: environment
description: >-
Accepts an EnvironmentID. If this is provided then the endpoint will
only return config for this environment. If this is left empty then
the Proxy will return config for all environments associated with
the Proxy Key.
required: false
schema:
type: string
- in: query
name: key
description: Accpets a Proxy Key.
required: true
schema:
type: string
security:
- BearerAuth: []
responses:
'200':
$ref: '#/components/responses/ProxyConfigResponse'
'400':
$ref: '#/components/responses/BadRequest'
'401':
$ref: '#/components/responses/Unauthenticated'
'403':
$ref: '#/components/responses/Unauthorized'
'404':
$ref: '#/components/responses/NotFound'
'500':
$ref: '#/components/responses/InternalServerError'
/proxy/auth:
post:
summary: Endpoint that the Proxy can use to authenticate with the client server
description: Endpoint that the Proxy can use to authenticate with the client server
operationId: AuthenticateProxyKey
tags:
- Proxy
requestBody:
content:
application/json:
schema:
type: object
properties:
proxyKey:
type: string
example: 896045f3-42ee-4e73-9154-086644768b96
required:
- proxyKey
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/AuthenticationResponse'
'401':
$ref: '#/components/responses/Unauthenticated'
'403':
$ref: '#/components/responses/Unauthorized'
'404':
$ref: '#/components/responses/NotFound'
'500':
$ref: '#/components/responses/InternalServerError'
components:
schemas:
FeatureState:
Expand Down Expand Up @@ -833,6 +912,31 @@ components:
type: array
items:
$ref: '#/components/schemas/MetricsData'
ProxyConfig:
type: object
description: TBD
allOf:
- $ref: '#/components/schemas/Pagination'
- properties:
environments:
type: array
items:
type: object
properties:
id:
type: string
apiKeys:
type: array
items:
type: string
featureConfigs:
type: array
items:
$ref: '#/components/schemas/FeatureConfig'
segments:
type: array
items:
$ref: '#/components/schemas/Segment'
securitySchemes:
ApiKeyAuth:
type: apiKey
Expand All @@ -850,6 +954,17 @@ components:
description: Unique identifier for the cluster for the account
schema:
type: string
segmentRulesV2QueryParam:
name: rules
in: query
required: false
description: >-
When set to rules=v2 will return AND rule compatible serving_rules
field. When not set or set to any other value will return old rules
field only compatible with OR rules.
allowEmptyValue: true
schema:
type: string
environmentPathParam:
name: environmentUUID
in: path
Expand Down Expand Up @@ -896,6 +1011,12 @@ components:
application/json:
schema:
$ref: '#/components/schemas/Error'
ProxyConfigResponse:
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/ProxyConfig'
BadRequest:
description: Bad request
content:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"coverage": "jest --coverage",
"test:junit": "jest --reporters=default --reporters=jest-junit",
"test:watch": "jest --watch",
"generate": "openapi-generator-cli generate -i ./api.yaml -g typescript-axios -o src/openapi"
"generate": "openapi-generator-cli generate -i client-v1.yaml -g typescript-axios -o src/openapi"
},
"author": "Enver Bisevac <enver.bisevac@harness.io>",
"license": "Apache-2.0",
Expand Down
13 changes: 11 additions & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@ import EventEmitter from 'events';
import jwt_decode from 'jwt-decode';
import axios, { AxiosInstance, AxiosRequestConfig } from 'axios';
import axiosRetry from 'axios-retry';
import { Claims, Options, StreamEvent, Target } from './types';
import {
APIConfiguration,
Claims,
Options,
StreamEvent,
Target,
} from './types';
import { Configuration, ClientApi, FeatureConfig, Variation } from './openapi';
import { VERSION } from './version';
import { PollerEvent, PollingProcessor } from './polling';
import { StreamProcessor } from './streaming';
import { Evaluator } from './evaluator';
import { defaultOptions } from './constants';
import { apiConfiguration, defaultOptions } from './constants';
import { Repository, RepositoryEvent, StorageRepository } from './repository';
import {
MetricEvent,
Expand Down Expand Up @@ -55,6 +61,7 @@ export default class Client {
private environment: string;
private configuration: Configuration;
private options: Options;
private apiConfiguration: APIConfiguration = apiConfiguration;
private cluster = '1';
private eventBus = new EventEmitter();
private pollProcessor: PollingProcessor;
Expand Down Expand Up @@ -356,6 +363,7 @@ export default class Client {
this.environment,
this.cluster,
this.api,
this.apiConfiguration,
this.options,
this.eventBus,
this.repository,
Expand All @@ -367,6 +375,7 @@ export default class Client {
this.streamProcessor = new StreamProcessor(
this.api,
this.sdkKey,
apiConfiguration,
this.environment,
this.authToken,
this.options,
Expand Down
7 changes: 6 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import LRU from 'lru-cache';
import { ConsoleLog } from './log';
import { FileStore } from './store';
import { Options } from './types';
import { APIConfiguration, Options } from './types';

export const ONE_HUNDRED = 100;

Expand Down Expand Up @@ -46,3 +46,8 @@ export const defaultOptions: Options = {
logger: new ConsoleLog(),
axiosTimeout: 30000,
};

const TARGET_SEGMENT_RULES_QUERY_PARAMETER = 'v2';
export const apiConfiguration: APIConfiguration = {
targetSegmentRulesQueryParameter: TARGET_SEGMENT_RULES_QUERY_PARAMETER,
};
Loading

0 comments on commit 5e40a85

Please sign in to comment.