-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6b4eb86
commit d9ebc2b
Showing
17 changed files
with
545 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { GatewayService } from '../../../../services/keystone/types'; | ||
import { ReportOfNamespaces } from '../namespaces'; | ||
|
||
export function has_feature_api_directory( | ||
ns: ReportOfNamespaces, | ||
service: GatewayService, | ||
routeName: string | ||
): Boolean { | ||
return Boolean(service?.environment?.active); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { GatewayService } from '../../../keystone/types'; | ||
import { ReportOfNamespaces } from '../namespaces'; | ||
|
||
export function has_feature_consumer_mgmt( | ||
ns: ReportOfNamespaces, | ||
service: GatewayService, | ||
routeName: string | ||
): Boolean { | ||
return ( | ||
['client-credentials', 'kong-api-key-acl'].indexOf( | ||
service.environment?.flow | ||
) >= 0 | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { | ||
GatewayPlugin, | ||
GatewayService, | ||
} from '../../../../services/keystone/types'; | ||
import { ReportOfNamespaces } from '../namespaces'; | ||
import { has_feature_api_directory } from './api_directory'; | ||
import { has_feature_consumer_mgmt } from './consumer_mgmt'; | ||
import { is_production } from './production'; | ||
import { has_feature_protected } from './protected'; | ||
import { has_feature_protected_externally } from './protected_externally'; | ||
import { has_feature_shared_idp } from './shared_idp'; | ||
import { has_feature_two_tiered_access } from './two_tiered_access'; | ||
|
||
export const FeatureList: { [key: string]: Function } = { | ||
api_directory: has_feature_api_directory, | ||
shared_idp: has_feature_shared_idp, | ||
consumer_mgmt: has_feature_consumer_mgmt, | ||
protected: has_feature_protected, | ||
protected_externally: has_feature_protected_externally, | ||
two_tiered_access: has_feature_two_tiered_access, | ||
production: is_production, | ||
}; | ||
|
||
export function getFeatures( | ||
ns: ReportOfNamespaces, | ||
services: GatewayService[], | ||
routeName: string | ||
): string[] { | ||
const service = findService(services, routeName); | ||
const features: string[] = []; | ||
Object.entries(FeatureList).forEach((func) => { | ||
if (func[1](ns, service, routeName)) { | ||
features.push(func[0]); | ||
} | ||
}); | ||
return features; | ||
} | ||
|
||
export function getPlugins( | ||
ns: ReportOfNamespaces, | ||
services: GatewayService[], | ||
routeName: string | ||
): string[] { | ||
const plugins: string[] = []; | ||
const service = findService(services, routeName); | ||
|
||
plugins.push.apply(plugins, getPluginNames(service.plugins)); | ||
service.routes.forEach((route) => { | ||
plugins.push.apply(plugins, getPluginNames(route.plugins)); | ||
}); | ||
return [...new Set(plugins)].sort(); | ||
} | ||
|
||
function findService( | ||
services: GatewayService[], | ||
routeName: string | ||
): GatewayService { | ||
return services | ||
.filter((s) => s.routes.filter((r) => r.name == routeName).length > 0) | ||
.pop(); | ||
} | ||
|
||
function getPluginNames(plugins: GatewayPlugin[]): string[] { | ||
return plugins?.map((p) => p.name); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { GatewayService } from '../../../keystone/types'; | ||
import { ReportOfNamespaces } from '../namespaces'; | ||
|
||
const re = /(dev.|test.|tst.|dlv.|delivery.|-dev|-test|-d.|-t.).*$/; | ||
|
||
export function is_production( | ||
ns: ReportOfNamespaces, | ||
service: GatewayService, | ||
routeName: string | ||
): Boolean { | ||
return ( | ||
service.routes.filter( | ||
(r) => | ||
r.name == routeName && | ||
(r.hosts as any).filter((h: string) => checkNonProd(h) == false) | ||
.length > 0 | ||
).length > 0 | ||
); | ||
} | ||
|
||
function checkNonProd(host: string) { | ||
return re.test(host); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { GatewayPlugin, GatewayService } from '../../../keystone/types'; | ||
import { ReportOfNamespaces } from '../namespaces'; | ||
|
||
export function has_feature_protected( | ||
ns: ReportOfNamespaces, | ||
service: GatewayService, | ||
routeName: string | ||
): Boolean { | ||
return ( | ||
// check either a `jwt-keycloak`, `oidc` or `acl` | ||
// plugins exists and is active | ||
check(service.plugins) || | ||
service.routes.filter((r) => r.name == routeName && check(r.plugins)) | ||
.length > 0 | ||
); | ||
} | ||
|
||
function check(plugins: GatewayPlugin[]): boolean { | ||
return ( | ||
plugins | ||
// .filter((p: any) => p.enabled) | ||
.filter((p: any) => ['jwt-keycloak', 'oidc', 'acl'].indexOf(p.name) >= 0) | ||
.length > 0 | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { GatewayService } from '../../../keystone/types'; | ||
import { ReportOfNamespaces } from '../namespaces'; | ||
|
||
// The reality is that this is not a real scenario | ||
// by definition "protected externally" means there is no use | ||
// of the gateway and therefore should not have Gateway Services | ||
export function has_feature_protected_externally( | ||
ns: ReportOfNamespaces, | ||
service: GatewayService, | ||
routeName: string | ||
): Boolean { | ||
return service.environment?.flow == 'protected-externally'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { GatewayService } from '../../../keystone/types'; | ||
import { ReportOfNamespaces } from '../namespaces'; | ||
|
||
export function has_feature_shared_idp( | ||
ns: ReportOfNamespaces, | ||
service: GatewayService, | ||
routeName: string | ||
): Boolean { | ||
return Boolean(service.environment?.credentialIssuer?.inheritFrom?.name); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { GatewayPlugin, GatewayService } from '../../../keystone/types'; | ||
import { ReportOfNamespaces } from '../namespaces'; | ||
|
||
export function has_feature_two_tiered_access( | ||
ns: ReportOfNamespaces, | ||
service: GatewayService, | ||
routeName: string | ||
): Boolean { | ||
return ( | ||
// check either service or route plugin | ||
// has the "config.anonymous" | ||
check(service.plugins) || | ||
service.routes.filter((r) => r.name == routeName && check(r.plugins)) | ||
.length > 0 | ||
); | ||
} | ||
|
||
function check(plugins: GatewayPlugin[]): boolean { | ||
return plugins.filter((p) => (p.config as any).anonymous).length > 0; | ||
} |
Oops, something went wrong.