1+ import * as ADCSDK from '@api7/adc-sdk' ;
2+ import { Option } from 'commander' ;
13import { Listr } from 'listr2' ;
24
3- import { LintTask , LoadLocalConfigurationTask } from '../tasks' ;
5+ import {
6+ FetchPluginSchemasTask ,
7+ LintTask ,
8+ LoadLocalConfigurationTask ,
9+ } from '../tasks' ;
10+ import { InitializeBackendTask } from '../tasks/init_backend' ;
411import { SignaleRenderer } from '../utils/listr' ;
512import { BaseCommand } from './helper' ;
613
714export const LintCommand = new BaseCommand ( 'lint' )
815 . description (
9- 'Lint the local configuration file(s) to ensure it meets ADC requirements.' ,
16+ 'Lint the local configuration file(s) to ensure it meets ADC requirements.\n\nOptionally, provide backend connection parameters to also validate plugin configurations against the backend\'s plugin schemas. ' ,
1017 )
1118 . summary ( 'lint the local configuration' )
1219 . option (
1320 '-f, --file <file-path>' ,
1421 'file to lint' ,
1522 ( filePath , files : Array < string > = [ ] ) => files . concat ( filePath ) ,
1623 )
24+ . addOption (
25+ new Option ( '--backend <backend>' , 'type of backend to validate plugins against' )
26+ . env ( 'ADC_BACKEND' )
27+ . choices ( [ 'apisix' , 'api7ee' ] ) ,
28+ )
29+ . addOption (
30+ new Option ( '--server <string>' , 'HTTP address of the backend' )
31+ . env ( 'ADC_SERVER' ) ,
32+ )
33+ . addOption (
34+ new Option (
35+ '--token <string>' ,
36+ 'token for ADC to connect to the backend' ,
37+ ) . env ( 'ADC_TOKEN' ) ,
38+ )
39+ . addOption (
40+ new Option (
41+ '--gateway-group <string>' ,
42+ 'gateway group to operate on (only for "api7ee" backend)' ,
43+ )
44+ . env ( 'ADC_GATEWAY_GROUP' )
45+ . default ( 'default' ) ,
46+ )
1747 . addExamples ( [
1848 {
1949 title : 'Lint the specified configuration file' ,
@@ -23,12 +53,33 @@ export const LintCommand = new BaseCommand('lint')
2353 title : 'Lint multiple configuration files' ,
2454 command : 'adc lint -f service-a.yaml -f service-b.yaml' ,
2555 } ,
56+ {
57+ title : 'Lint with plugin validation against an APISIX backend' ,
58+ command : 'adc lint -f adc.yaml --backend apisix --server http://localhost:9180 --token edd1c9f034335f136f87ad84b625c8f1' ,
59+ } ,
60+ {
61+ title : 'Lint with plugin validation against an API7 EE backend' ,
62+ command : 'adc lint -f adc.yaml --backend api7ee --server https://dashboard.example.com --token <token>' ,
63+ } ,
2664 ] )
2765 . action ( async ( ) => {
2866 const opts = LintCommand . optsWithGlobals ( ) ;
67+ const useBackend = ! ! opts . backend ;
2968
3069 const tasks = new Listr (
31- [ LoadLocalConfigurationTask ( opts . file , { } ) , LintTask ( ) ] ,
70+ [
71+ ...( useBackend
72+ ? [
73+ InitializeBackendTask ( opts . backend , {
74+ ...opts ,
75+ cacheKey : 'lint' ,
76+ } as ADCSDK . BackendOptions ) ,
77+ FetchPluginSchemasTask ( ) ,
78+ ]
79+ : [ ] ) ,
80+ LoadLocalConfigurationTask ( opts . file , { } ) ,
81+ LintTask ( ) ,
82+ ] ,
3283 {
3384 renderer : SignaleRenderer ,
3485 rendererOptions : { verbose : opts . verbose } ,
@@ -37,7 +88,7 @@ export const LintCommand = new BaseCommand('lint')
3788
3889 try {
3990 await tasks . run ( ) ;
40- } catch ( err ) {
91+ } catch {
4192 process . exit ( 1 ) ;
4293 }
4394 } ) ;
0 commit comments