Skip to content

Commit 3836111

Browse files
feat: tools create_collection and create_endpoints from configuration_to_save
2 parents 5b55344 + fb642a5 commit 3836111

File tree

4 files changed

+959
-634
lines changed

4 files changed

+959
-634
lines changed

src/apis/client.ts

Lines changed: 311 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import {
2222
ConfigMaps,
2323
ConfigServiceSecrets,
2424
constants,
25+
CrudEndpoint,
26+
CustomEndpoint,
2527
CustomService,
2628
EnvironmentVariablesTypes,
2729
ICatalogExample,
@@ -53,7 +55,7 @@ import { PostProject, Template } from './types/governance'
5355

5456
export const DEFAULT_DOCUMENTATION_PATH = '/documentation/json'
5557
const ENABLE_ENVIRONMENT_BASED_CONFIGURATION_MANAGEMENT = 'ENABLE_ENVIRONMENT_BASED_CONFIGURATION_MANAGEMENT'
56-
const { DOCKER_IMAGE_NAME_SUGGESTION_TYPES, ServiceTypes } = constants
58+
const { DOCKER_IMAGE_NAME_SUGGESTION_TYPES, ServiceTypes, EndpointTypes, Verbs } = constants
5759

5860
interface AISettings {
5961
enableAgenticFeatures?: boolean
@@ -102,6 +104,13 @@ export interface IAPIClient {
102104
marketplaceItemVersion?: string,
103105
description?: string,
104106
): Promise<SaveResponse>
107+
createEndpoints(
108+
projectID: string,
109+
refID: string,
110+
endpointType: 'custom' | 'crud',
111+
endpointName: string,
112+
endpointTarget: string,
113+
): Promise<SaveResponse>
105114
// #endregion
106115

107116
// #region Deploy Methods
@@ -264,6 +273,24 @@ export class APIClient implements IAPIClient {
264273
})
265274
}
266275

276+
async createEndpoints (
277+
projectID: string,
278+
refID: string,
279+
endpointType: 'custom' | 'crud',
280+
endpointName: string,
281+
endpointTarget: string,
282+
): Promise<SaveResponse> {
283+
const endpointStructure = this.#buildEndpointStructure(endpointType, endpointName, endpointTarget)
284+
285+
const resourcesToCreate: ResourcesToCreate = {
286+
endpoints: {
287+
[endpointName]: endpointStructure,
288+
},
289+
}
290+
291+
return await this.saveConfiguration(projectID, refID, resourcesToCreate)
292+
}
293+
267294
async getConfiguration (prjID: string, refID: string): Promise<RetrievedConfiguration> {
268295
const ft = await this.#featureFlagsClient.getToggles(prjID, [ ENABLE_ENVIRONMENT_BASED_CONFIGURATION_MANAGEMENT ])
269296
if (ft[ENABLE_ENVIRONMENT_BASED_CONFIGURATION_MANAGEMENT] || false) {
@@ -409,6 +436,274 @@ export class APIClient implements IAPIClient {
409436
return resourcesToCreate
410437
}
411438

439+
#buildEndpointStructure (
440+
endpointType: 'custom' | 'crud',
441+
endpointName: string,
442+
endpointTarget: string,
443+
): CrudEndpoint | CustomEndpoint {
444+
if (endpointType === 'custom') {
445+
return {
446+
basePath: `/${endpointName}`,
447+
type: EndpointTypes.CUSTOM,
448+
public: false,
449+
showInDocumentation: true,
450+
secreted: false,
451+
acl: 'true',
452+
service: endpointTarget,
453+
port: '80',
454+
pathRewrite: '/',
455+
description: `Endpoint /${endpointName}`,
456+
tags: [ endpointTarget ],
457+
backofficeAcl: {
458+
inherited: true,
459+
},
460+
allowUnknownRequestContentType: false,
461+
allowUnknownResponseContentType: false,
462+
forceMicroserviceGatewayProxy: false,
463+
listeners: {
464+
frontend: true,
465+
},
466+
useDownstreamProtocol: true,
467+
}
468+
} else {
469+
// CRUD endpoint
470+
return {
471+
basePath: `/${endpointName}`,
472+
pathName: '/',
473+
pathRewrite: `/${endpointName}`,
474+
type: EndpointTypes.CRUD,
475+
tags: [ 'crud' ],
476+
description: `Endpoint /${endpointTarget}`,
477+
collectionId: endpointTarget,
478+
public: true,
479+
secreted: false,
480+
showInDocumentation: true,
481+
acl: 'true',
482+
backofficeAcl: {
483+
inherited: true,
484+
},
485+
allowUnknownRequestContentType: false,
486+
allowUnknownResponseContentType: false,
487+
forceMicroserviceGatewayProxy: false,
488+
routes: {
489+
'GET/': {
490+
id: 'GET/',
491+
verb: Verbs.METHOD_GET,
492+
path: '/',
493+
public: { inherited: true },
494+
secreted: { inherited: true },
495+
showInDocumentation: { inherited: true },
496+
acl: { inherited: true },
497+
backofficeAcl: { inherited: true },
498+
rateLimit: { inherited: true },
499+
allowUnknownRequestContentType: { inherited: true },
500+
allowUnknownResponseContentType: { inherited: true },
501+
preDecorators: [],
502+
postDecorators: [],
503+
},
504+
'POST/': {
505+
id: 'POST/',
506+
verb: Verbs.METHOD_POST,
507+
path: '/',
508+
public: { inherited: true },
509+
secreted: { inherited: true },
510+
showInDocumentation: { inherited: true },
511+
acl: { inherited: true },
512+
backofficeAcl: { inherited: true },
513+
rateLimit: { inherited: true },
514+
allowUnknownRequestContentType: { inherited: true },
515+
allowUnknownResponseContentType: { inherited: true },
516+
preDecorators: [],
517+
postDecorators: [],
518+
},
519+
'GET/export': {
520+
id: 'GET/export',
521+
verb: Verbs.METHOD_GET,
522+
path: '/export',
523+
public: { inherited: true },
524+
secreted: { inherited: true },
525+
showInDocumentation: { inherited: true },
526+
acl: { inherited: true },
527+
backofficeAcl: { inherited: true },
528+
rateLimit: { inherited: true },
529+
allowUnknownRequestContentType: { inherited: true },
530+
allowUnknownResponseContentType: { inherited: false, value: true },
531+
preDecorators: [],
532+
postDecorators: [],
533+
},
534+
'GET/:id': {
535+
id: 'GET/:id',
536+
verb: Verbs.METHOD_GET,
537+
path: '/:id',
538+
public: { inherited: true },
539+
secreted: { inherited: true },
540+
showInDocumentation: { inherited: true },
541+
acl: { inherited: true },
542+
backofficeAcl: { inherited: true },
543+
rateLimit: { inherited: true },
544+
allowUnknownRequestContentType: { inherited: true },
545+
allowUnknownResponseContentType: { inherited: true },
546+
preDecorators: [],
547+
postDecorators: [],
548+
},
549+
'DELETE/:id': {
550+
id: 'DELETE/:id',
551+
verb: Verbs.METHOD_DELETE,
552+
path: '/:id',
553+
public: { inherited: true },
554+
secreted: { inherited: true },
555+
showInDocumentation: { inherited: true },
556+
acl: { inherited: true },
557+
backofficeAcl: { inherited: true },
558+
rateLimit: { inherited: true },
559+
allowUnknownRequestContentType: { inherited: true },
560+
allowUnknownResponseContentType: { inherited: true },
561+
preDecorators: [],
562+
postDecorators: [],
563+
},
564+
'DELETE/': {
565+
id: 'DELETE/',
566+
verb: Verbs.METHOD_DELETE,
567+
path: '/',
568+
public: { inherited: true },
569+
secreted: { inherited: true },
570+
showInDocumentation: { inherited: true },
571+
acl: { inherited: true },
572+
backofficeAcl: { inherited: true },
573+
rateLimit: { inherited: true },
574+
allowUnknownRequestContentType: { inherited: true },
575+
allowUnknownResponseContentType: { inherited: true },
576+
preDecorators: [],
577+
postDecorators: [],
578+
},
579+
'PATCH/:id': {
580+
id: 'PATCH/:id',
581+
verb: Verbs.METHOD_PATCH,
582+
path: '/:id',
583+
public: { inherited: true },
584+
secreted: { inherited: true },
585+
showInDocumentation: { inherited: true },
586+
acl: { inherited: true },
587+
backofficeAcl: { inherited: true },
588+
rateLimit: { inherited: true },
589+
allowUnknownRequestContentType: { inherited: true },
590+
allowUnknownResponseContentType: { inherited: true },
591+
preDecorators: [],
592+
postDecorators: [],
593+
},
594+
'PATCH/': {
595+
id: 'PATCH/',
596+
verb: Verbs.METHOD_PATCH,
597+
path: '/',
598+
public: { inherited: true },
599+
secreted: { inherited: true },
600+
showInDocumentation: { inherited: true },
601+
acl: { inherited: true },
602+
backofficeAcl: { inherited: true },
603+
rateLimit: { inherited: true },
604+
allowUnknownRequestContentType: { inherited: true },
605+
allowUnknownResponseContentType: { inherited: true },
606+
preDecorators: [],
607+
postDecorators: [],
608+
},
609+
'GET/count': {
610+
id: 'GET/count',
611+
verb: Verbs.METHOD_GET,
612+
path: '/count',
613+
public: { inherited: true },
614+
secreted: { inherited: true },
615+
showInDocumentation: { inherited: true },
616+
acl: { inherited: true },
617+
backofficeAcl: { inherited: true },
618+
rateLimit: { inherited: true },
619+
allowUnknownRequestContentType: { inherited: true },
620+
allowUnknownResponseContentType: { inherited: true },
621+
preDecorators: [],
622+
postDecorators: [],
623+
},
624+
'POST/bulk': {
625+
id: 'POST/bulk',
626+
verb: Verbs.METHOD_POST,
627+
path: '/bulk',
628+
public: { inherited: true },
629+
secreted: { inherited: true },
630+
showInDocumentation: { inherited: true },
631+
acl: { inherited: true },
632+
backofficeAcl: { inherited: true },
633+
rateLimit: { inherited: true },
634+
allowUnknownRequestContentType: { inherited: true },
635+
allowUnknownResponseContentType: { inherited: true },
636+
preDecorators: [],
637+
postDecorators: [],
638+
},
639+
'POST/upsert-one': {
640+
id: 'POST/upsert-one',
641+
verb: Verbs.METHOD_POST,
642+
path: '/upsert-one',
643+
public: { inherited: true },
644+
secreted: { inherited: true },
645+
showInDocumentation: { inherited: true },
646+
acl: { inherited: true },
647+
backofficeAcl: { inherited: true },
648+
rateLimit: { inherited: true },
649+
allowUnknownRequestContentType: { inherited: true },
650+
allowUnknownResponseContentType: { inherited: true },
651+
preDecorators: [],
652+
postDecorators: [],
653+
},
654+
'PATCH/bulk': {
655+
id: 'PATCH/bulk',
656+
verb: Verbs.METHOD_PATCH,
657+
path: '/bulk',
658+
public: { inherited: true },
659+
secreted: { inherited: true },
660+
showInDocumentation: { inherited: true },
661+
acl: { inherited: true },
662+
backofficeAcl: { inherited: true },
663+
rateLimit: { inherited: true },
664+
allowUnknownRequestContentType: { inherited: true },
665+
allowUnknownResponseContentType: { inherited: true },
666+
preDecorators: [],
667+
postDecorators: [],
668+
},
669+
'POST/:id/state': {
670+
id: 'POST/:id/state',
671+
verb: Verbs.METHOD_POST,
672+
path: '/:id/state',
673+
public: { inherited: true },
674+
secreted: { inherited: true },
675+
showInDocumentation: { inherited: true },
676+
acl: { inherited: true },
677+
backofficeAcl: { inherited: true },
678+
rateLimit: { inherited: true },
679+
allowUnknownRequestContentType: { inherited: true },
680+
allowUnknownResponseContentType: { inherited: true },
681+
preDecorators: [],
682+
postDecorators: [],
683+
},
684+
'POST/state': {
685+
id: 'POST/state',
686+
verb: Verbs.METHOD_POST,
687+
path: '/state',
688+
public: { inherited: true },
689+
secreted: { inherited: true },
690+
showInDocumentation: { inherited: true },
691+
acl: { inherited: true },
692+
backofficeAcl: { inherited: true },
693+
rateLimit: { inherited: true },
694+
allowUnknownRequestContentType: { inherited: true },
695+
allowUnknownResponseContentType: { inherited: true },
696+
preDecorators: [],
697+
postDecorators: [],
698+
},
699+
},
700+
listeners: {
701+
frontend: true,
702+
},
703+
}
704+
}
705+
}
706+
412707
async #serviceGitGroupPath (projectID: string, projectGitPath: string): Promise<string> {
413708
const projectGroups = await this.#backendClient.projectGitProviderGroups(projectID, path.dirname(projectGitPath))
414709
let groupName: string | undefined
@@ -505,6 +800,7 @@ export interface APIClientMockFunctions {
505800
getConfigurationMockFn?: (projectId: string, refId: string) => Promise<RetrievedConfiguration>
506801
saveConfigurationMockFn?: (projectId: string) => Promise<SaveResponse>
507802
createServiceFromMarketplaceItemMockFn?: (projectID: string) => Promise<SaveResponse>
803+
createEndpointsMockFn?: (projectID: string) => Promise<SaveResponse>
508804
// #endregion
509805

510806
// #region Deploy Methods
@@ -673,6 +969,20 @@ export class APIClientMock implements IAPIClient {
673969
return this.mocks.createServiceFromMarketplaceItemMockFn(projectID)
674970
}
675971

972+
async createEndpoints (
973+
projectID: string,
974+
_refID: string,
975+
_endpointType: 'custom' | 'crud',
976+
_endpointName: string,
977+
_endpointTarget: string,
978+
): Promise<SaveResponse> {
979+
if (!this.mocks.createEndpointsMockFn) {
980+
throw new Error('createEndpointsMockFn not mocked')
981+
}
982+
983+
return this.mocks.createEndpointsMockFn(projectID)
984+
}
985+
676986
// #endregion
677987

678988
// #region Deploy Methods

0 commit comments

Comments
 (0)