All files / src/aws names.ts

100% Statements 19/19
96.43% Branches 27/28
100% Functions 8/8
100% Lines 19/19
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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78  5x 5x 5x   46x   5x   46x   5x   10x   5x   3x   5x   6x   5x   12x   5x   6x   5x   10x   5x                                                                                    
import * as md5 from 'md5'
import * as util from 'util'
 
export function clean(input: string): string {
  return truncate(input.replace(/[^a-z0-9+]+/gi, ''))
}
 
export function truncate(input: string): string {
  return input.length <= 64 ? input : input.substr(0, 32) + md5(input)
}
 
export function policyScale(service: string, table: string, read: boolean, index?: string, stage?: string): string {
  return clean(
    util.format(
      '%sTable%sScalingPolicy-%s%s%s',
      service,
      read ? 'Read' : 'Write',
      table,
      index || '',
      stage || ''
    )
  )
}
 
export function policyRole(service: string, table: string, index?: string, stage?: string): string {
  return clean(
    util.format(
      '%sDynamoDBAutoscalePolicy-%s%s%s',
      service,
      table,
      index || '',
      stage || ''
    )
  )
}
 
export function dimension(read: boolean, index: boolean): string {
  return util.format(
    'dynamodb:%s:%sCapacityUnits',
    index ? 'index' : 'table',
    read ? 'Read' : 'Write'
  )
}
 
export function target(service: string, table: string, read: boolean, index?: string, stage?: string): string {
  return clean(
    util.format(
      '%sAutoScalingTarget%s-%s%s%s',
      service,
      read ? 'Read' : 'Write',
      table,
      index || '',
      stage || ''
    )
  )
}
 
export function metric(read: boolean): string {
  return clean(
    util.format(
      'DynamoDB%sCapacityUtilization',
      read ? 'Read' : 'Write'
    )
  )
}
 
export function role(service: string, table: string, index?: string, stage?: string): string {
  return clean(
    util.format(
      '%sDynamoDBAutoscaleRole-%s%s%s',
      service,
      table,
      index || '',
      stage || ''
    )
  )
}