All files / src/activemq/usermanagement activemq-broker-user-management.ts

73.33% Statements 44/60
100% Branches 3/3
66.66% Functions 2/3
73.33% Lines 44/60

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 611x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 1x 1x                                 1x  
/*
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
import { CfnBroker } from 'aws-cdk-lib/aws-amazonmq';
import { ActiveMqLdapAuthorization } from './activemq-authoriztion';
import { ActiveMqUser } from './activemq-user';
import { ActiveMqAuthenticationStrategy } from '../activemq-authentication-strategy';
 
export interface IActiveMqBrokerUserManagement {
  render(): ActiveMqBrokerDeploymentUserManagementDefinition;
}
 
export interface ActiveMqBrokerDeploymentUserManagementDefinition {
  readonly users: CfnBroker.UserProperty[];
  readonly ldapServerMetadata?: CfnBroker.LdapServerMetadataProperty;
  readonly authenticationStrategy?: ActiveMqAuthenticationStrategy;
}
 
export interface LdapUserStoreOptions extends ActiveMqLdapAuthorization {
}
 
export interface SimpleAuthenticationUserManagementOptions {
  readonly users: ActiveMqUser[];
}
 
export class ActiveMqBrokerUserManagement {
  public static simple(options: SimpleAuthenticationUserManagementOptions): IActiveMqBrokerUserManagement {
    return {
      render(): ActiveMqBrokerDeploymentUserManagementDefinition {
        return {
          users: options.users.map(u => ({
            username: u.username,
            password: u.password.unsafeUnwrap(),
            groups: u.groups,
            consoleAccess: u.hasConsoleAccess,
          })),
        };
      },
    };
  }
 
  public static ldap(options: LdapUserStoreOptions): IActiveMqBrokerUserManagement {

    return {
      render(): ActiveMqBrokerDeploymentUserManagementDefinition {
        return {
          ldapServerMetadata: {
            ...options,
            serviceAccountUsername: options.serviceAccountUsername.unsafeUnwrap(),
            serviceAccountPassword: options.serviceAccountPassword.unsafeUnwrap(),

          },
          users: [],
          authenticationStrategy: ActiveMqAuthenticationStrategy.LDAP,
        };
      },
    };
  }
}