@@ -38,6 +38,7 @@ import { DeveloperConnectionPluginFactory } from "./plugins/dev/developer_connec
3838import { ConnectionPluginFactory } from "./plugin_factory" ;
3939import { LimitlessConnectionPluginFactory } from "./plugins/limitless/limitless_connection_plugin_factory" ;
4040import { FastestResponseStrategyPluginFactory } from "./plugins/strategy/fastest_response/fastest_respose_strategy_plugin_factory" ;
41+ import { ConfigurationProfile } from "./profile/configuration_profile" ;
4142
4243/*
4344 Type alias used for plugin factory sorting. It holds a reference to a plugin
@@ -69,58 +70,90 @@ export class ConnectionPluginChainBuilder {
6970 [ "executeTime" , { factory : ExecuteTimePluginFactory , weight : ConnectionPluginChainBuilder . WEIGHT_RELATIVE_TO_PRIOR_PLUGIN } ]
7071 ] ) ;
7172
73+ static readonly PLUGIN_WEIGHTS = new Map < typeof ConnectionPluginFactory , number > ( [
74+ [ AuroraInitialConnectionStrategyFactory , 390 ] ,
75+ [ AuroraConnectionTrackerPluginFactory , 400 ] ,
76+ [ StaleDnsPluginFactory , 500 ] ,
77+ [ ReadWriteSplittingPluginFactory , 600 ] ,
78+ [ FailoverPluginFactory , 700 ] ,
79+ [ HostMonitoringPluginFactory , 800 ] ,
80+ [ LimitlessConnectionPluginFactory , 950 ] ,
81+ [ IamAuthenticationPluginFactory , 1000 ] ,
82+ [ AwsSecretsManagerPluginFactory , 1100 ] ,
83+ [ FederatedAuthPluginFactory , 1200 ] ,
84+ [ OktaAuthPluginFactory , 1300 ] ,
85+ [ DeveloperConnectionPluginFactory , 1400 ] ,
86+ [ ConnectTimePluginFactory , ConnectionPluginChainBuilder . WEIGHT_RELATIVE_TO_PRIOR_PLUGIN ] ,
87+ [ ExecuteTimePluginFactory , ConnectionPluginChainBuilder . WEIGHT_RELATIVE_TO_PRIOR_PLUGIN ]
88+ ] ) ;
89+
7290 static async getPlugins (
7391 pluginService : PluginService ,
7492 props : Map < string , any > ,
75- connectionProviderManager : ConnectionProviderManager
93+ connectionProviderManager : ConnectionProviderManager ,
94+ configurationProfile : ConfigurationProfile | null
7695 ) : Promise < ConnectionPlugin [ ] > {
96+ let pluginFactoryInfoList : PluginFactoryInfo [ ] = [ ] ;
7797 const plugins : ConnectionPlugin [ ] = [ ] ;
78- let pluginCodes : string = props . get ( WrapperProperties . PLUGINS . name ) ;
79- if ( pluginCodes == null ) {
80- pluginCodes = WrapperProperties . DEFAULT_PLUGINS ;
81- }
82-
83- const usingDefault = pluginCodes === WrapperProperties . DEFAULT_PLUGINS ;
98+ let usingDefault : boolean = false ;
8499
85- pluginCodes = pluginCodes . trim ( ) ;
86-
87- if ( pluginCodes !== "" ) {
88- const pluginCodeList = pluginCodes . split ( "," ) . map ( ( pluginCode ) => pluginCode . trim ( ) ) ;
89- let pluginFactoryInfoList : PluginFactoryInfo [ ] = [ ] ;
90- let lastWeight = 0 ;
91- pluginCodeList . forEach ( ( p ) => {
92- if ( ! ConnectionPluginChainBuilder . PLUGIN_FACTORIES . has ( p ) ) {
93- throw new AwsWrapperError ( Messages . get ( "PluginManager.unknownPluginCode" , p ) ) ;
94- }
95-
96- const factoryInfo = ConnectionPluginChainBuilder . PLUGIN_FACTORIES . get ( p ) ;
97- if ( factoryInfo ) {
98- if ( factoryInfo . weight === ConnectionPluginChainBuilder . WEIGHT_RELATIVE_TO_PRIOR_PLUGIN ) {
99- lastWeight ++ ;
100- } else {
101- lastWeight = factoryInfo . weight ;
100+ if ( configurationProfile ) {
101+ const profilePluginFactories = configurationProfile . getPluginFactories ( ) ;
102+ if ( profilePluginFactories ) {
103+ for ( const factory of profilePluginFactories ) {
104+ const weight = ConnectionPluginChainBuilder . PLUGIN_WEIGHTS . get ( factory ) ;
105+ if ( ! weight ) {
106+ throw new AwsWrapperError ( Messages . get ( "PluginManager.unknownPluginWeight" , factory . prototype . constructor . name ) ) ;
102107 }
103- pluginFactoryInfoList . push ( { factory : factoryInfo . factory , weight : lastWeight } ) ;
108+ pluginFactoryInfoList . push ( { factory : factory , weight : weight } ) ;
104109 }
105- } ) ;
110+ usingDefault = true ; // We assume that plugin factories in configuration profile is presorted.
111+ }
112+ } else {
113+ let pluginCodes : string = props . get ( WrapperProperties . PLUGINS . name ) ;
114+ if ( pluginCodes == null ) {
115+ pluginCodes = WrapperProperties . DEFAULT_PLUGINS ;
116+ }
117+ usingDefault = pluginCodes === WrapperProperties . DEFAULT_PLUGINS ;
106118
107- if ( ! usingDefault && pluginFactoryInfoList . length > 1 && WrapperProperties . AUTO_SORT_PLUGIN_ORDER . get ( props ) ) {
108- pluginFactoryInfoList = pluginFactoryInfoList . sort ( ( a , b ) => a . weight - b . weight ) ;
119+ pluginCodes = pluginCodes . trim ( ) ;
120+ if ( pluginCodes !== "" ) {
121+ const pluginCodeList = pluginCodes . split ( "," ) . map ( ( pluginCode ) => pluginCode . trim ( ) ) ;
122+ let lastWeight = 0 ;
123+ pluginCodeList . forEach ( ( p ) => {
124+ if ( ! ConnectionPluginChainBuilder . PLUGIN_FACTORIES . has ( p ) ) {
125+ throw new AwsWrapperError ( Messages . get ( "PluginManager.unknownPluginCode" , p ) ) ;
126+ }
109127
110- if ( ! usingDefault ) {
111- logger . info (
112- "Plugins order has been rearranged. The following order is in effect: " +
113- pluginFactoryInfoList . map ( ( pluginFactoryInfo ) => pluginFactoryInfo . factory . name . split ( "Factory" ) [ 0 ] ) . join ( ", " )
114- ) ;
115- }
128+ const factoryInfo = ConnectionPluginChainBuilder . PLUGIN_FACTORIES . get ( p ) ;
129+ if ( factoryInfo ) {
130+ if ( factoryInfo . weight === ConnectionPluginChainBuilder . WEIGHT_RELATIVE_TO_PRIOR_PLUGIN ) {
131+ lastWeight ++ ;
132+ } else {
133+ lastWeight = factoryInfo . weight ;
134+ }
135+ pluginFactoryInfoList . push ( { factory : factoryInfo . factory , weight : lastWeight } ) ;
136+ }
137+ } ) ;
116138 }
139+ }
140+
141+ if ( ! usingDefault && pluginFactoryInfoList . length > 1 && WrapperProperties . AUTO_SORT_PLUGIN_ORDER . get ( props ) ) {
142+ pluginFactoryInfoList = pluginFactoryInfoList . sort ( ( a , b ) => a . weight - b . weight ) ;
117143
118- for ( const pluginFactoryInfo of pluginFactoryInfoList ) {
119- const factoryObj = new pluginFactoryInfo . factory ( ) ;
120- plugins . push ( await factoryObj . getInstance ( pluginService , props ) ) ;
144+ if ( ! usingDefault ) {
145+ logger . info (
146+ "Plugins order has been rearranged. The following order is in effect: " +
147+ pluginFactoryInfoList . map ( ( pluginFactoryInfo ) => pluginFactoryInfo . factory . name . split ( "Factory" ) [ 0 ] ) . join ( ", " )
148+ ) ;
121149 }
122150 }
123151
152+ for ( const pluginFactoryInfo of pluginFactoryInfoList ) {
153+ const factoryObj = new pluginFactoryInfo . factory ( ) ;
154+ plugins . push ( await factoryObj . getInstance ( pluginService , props ) ) ;
155+ }
156+
124157 plugins . push ( new DefaultPlugin ( pluginService , connectionProviderManager ) ) ;
125158
126159 return plugins ;
0 commit comments