permission-node: rename static create method to fromConfig

Signed-off-by: MT Lewis <mtlewis@users.noreply.github.com>
This commit is contained in:
MT Lewis
2021-12-21 09:46:22 +00:00
parent c829631b4a
commit 20d10b57d6
4 changed files with 20 additions and 21 deletions
+1 -2
View File
@@ -64,9 +64,8 @@ function makeCreateEnv(config: Config) {
const reader = UrlReaders.default({ logger: root, config });
const discovery = SingleHostDiscovery.fromConfig(config);
const tokenManager = ServerTokenManager.fromConfig(config, { logger: root });
const permissions = ServerPermissionClient.create({
const permissions = ServerPermissionClient.fromConfig(config, {
discovery,
config,
tokenManager,
});
+7 -5
View File
@@ -134,10 +134,12 @@ export class ServerPermissionClient implements PermissionAuthorizer {
options?: AuthorizeRequestOptions,
): Promise<AuthorizeResponse[]>;
// (undocumented)
static create(options: {
discovery: PluginEndpointDiscovery;
config: Config;
tokenManager: TokenManager;
}): ServerPermissionClient;
static fromConfig(
config: Config,
options: {
discovery: PluginEndpointDiscovery;
tokenManager: TokenManager;
},
): ServerPermissionClient;
}
```
@@ -68,9 +68,8 @@ describe('ServerPermissionClient', () => {
afterEach(() => server.resetHandlers());
it('should bypass authorization if permissions are disabled', async () => {
const client = ServerPermissionClient.create({
const client = ServerPermissionClient.fromConfig(new ConfigReader({}), {
discovery,
config: new ConfigReader({}),
tokenManager: ServerTokenManager.noop(),
});
@@ -81,9 +80,8 @@ describe('ServerPermissionClient', () => {
it('should bypass authorization if permissions are enabled and request has valid server token', async () => {
const tokenManager = ServerTokenManager.fromConfig(config, { logger });
const client = ServerPermissionClient.create({
const client = ServerPermissionClient.fromConfig(config, {
discovery,
config,
tokenManager,
});
@@ -96,9 +94,8 @@ describe('ServerPermissionClient', () => {
it('should authorize normally if permissions are enabled and request does not have valid server token', async () => {
const tokenManager = ServerTokenManager.fromConfig(config, { logger });
const client = ServerPermissionClient.create({
const client = ServerPermissionClient.fromConfig(config, {
discovery,
config,
tokenManager,
});
@@ -111,9 +108,8 @@ describe('ServerPermissionClient', () => {
it('should error if permissions are enabled but a no-op token manager is configured', async () => {
expect(() =>
ServerPermissionClient.create({
ServerPermissionClient.fromConfig(config, {
discovery,
config,
tokenManager: ServerTokenManager.noop(),
}),
).toThrowError(
@@ -39,12 +39,14 @@ export class ServerPermissionClient implements PermissionAuthorizer {
private readonly tokenManager: TokenManager;
private readonly permissionEnabled: boolean;
static create(options: {
discovery: PluginEndpointDiscovery;
config: Config;
tokenManager: TokenManager;
}) {
const { discovery, config, tokenManager } = options;
static fromConfig(
config: Config,
options: {
discovery: PluginEndpointDiscovery;
tokenManager: TokenManager;
},
) {
const { discovery, tokenManager } = options;
const permissionClient = new PermissionClient({ discovery, config });
const permissionEnabled =
config.getOptionalBoolean('permission.enabled') ?? false;