service: footprint-reboot-api
# Create an optimized package for our functions
package:
  individually: true

plugins:
  - serverless-bundle # Package our functions with Webpack
  - serverless-offline
  - serverless-dotenv-plugin # Load .env as environment variables

provider:
  name: aws
  runtime: nodejs12.x
  stage: prod
  region: eu-west-1
  profile: evolvqa
  vpc:
    securityGroupIds:
      - ${env:SECURITYGROUPIDS}
    subnetIds:
      - ${env:SUBNETIDS1}
      - ${env:SUBNETIDS2}
  memorySize: 512

  # These environment variables are made available to our functions
  # under process.env.
  environment:
    tableName: footprint-log
    databaseHost: ${env:DBHOST}
    databaseUser: ${env:DBUSERNAME}
    databasePass: ${env:DBPASSWORD}
    databaseName: ${env:DBNAME}

  # 'iamRoleStatements' defines the permission policy for the Lambda function.
  # In this case Lambda functions are granted with permissions to access DynamoDB.
  iamRoleStatements:
    - Effect: Allow
      Action:
        - dynamodb:DescribeTable
        - dynamodb:Query
        - dynamodb:Scan
        - dynamodb:GetItem
        - dynamodb:PutItem
        - dynamodb:UpdateItem
        - dynamodb:DeleteItem
      Resource: "arn:aws:dynamodb:eu-west-1:*:*"

functions:
  # Defines an HTTP API endpoint that calls the main function in create.js
  # - path: url path is /notes
  # - method: POST request
  # - cors: enabled CORS (Cross-Origin Resource Sharing) for browser cross
  #     domain api call
  # - authorizer: authenticate using the AWS IAM role
  create:
    handler: create.main
    events:
      - http:
          path: footprint
          method: post
          cors: true
          authorizer: aws_iam
  getfilteredusers:
    handler: getfilteredusers.main
    events:
      - http:
          path: footprint/members
          method: post
          cors: true
          authorizer: aws_iam
  get:
    # Defines an HTTP API endpoint that calls the main function in get.js
    # - path: url path is /footprint/{id}
    # - method: GET request
    handler: get.main
    events:
      - http:
          path: footprint/{id}
          method: get
          cors: true
          authorizer: aws_iam
  getuser:
    # Defines an HTTP API endpoint that calls the main function in get.js
    # - path: url path is /footprint/{id}
    # - method: GET request
    handler: getuser.main
    events:
      - http:
          path: footprint/user/{id}
          method: get
          cors: true
          authorizer: aws_iam
  getpermissionmodules:
    # Defines an HTTP API endpoint that calls the main function in get.js
    # - path: url path is /footprint/{id}
    # - method: GET request
    handler: getpermissionmodules.main
    events:
      - http:
          path: footprint/getpermissionmodules/{id}
          method: get
          cors: true
          authorizer: aws_iam
  getuserpermissions:
    # Defines an HTTP API endpoint that calls the main function in get.js
    # - path: url path is /footprint/{id}
    # - method: GET request
    handler: getuserpermissions.main
    events:
      - http:
          path: footprint/userpermissions
          method: post
          cors: true
          authorizer: aws_iam        
  getuseruuid:
    # Defines an HTTP API endpoint that calls the main function in get.js
    # - path: url path is /footprint/{id}
    # - method: GET request
    handler: getuseruuid.main
    events:
      - http:
          path: footprint/useruuid/{id}
          method: get
          cors: true
          authorizer: aws_iam        
  getbyemail:
    # Defines an HTTP API endpoint that calls the main function in get.js
    # - path: url path is /footprint/{id}
    # - method: GET request
    handler: getbyemail.main
    events:
      - http:
          path: footprint/email/{id}
          method: get
          cors: true
          authorizer: aws_iam
  getallusers:
    # Defines an HTTP API endpoint that calls the main function in get.js
    # - path: url path is /footprint/users
    # - method: GET request
    handler: getallusers.main
    events:
      - http:
          path: footprint/users
          method: get
          cors: true
          authorizer: aws_iam 
  getpermissions:
    # Defines an HTTP API endpoint that calls the main function in get.js
    # - path: url path is /footprint/users
    # - method: GET request
    handler: getpermissions.main
    events:
      - http:
          path: footprint/permissions
          method: post
          cors: true
          authorizer: aws_iam
  getmoduledetails:
    # Defines an HTTP API endpoint that calls the main function in get.js
    # - path: url path is /footprint/users
    # - method: GET request
    handler: getmoduledetails.main
    events:
      - http:
          path: footprint/getmoduledetails
          method: post
          cors: true
          authorizer: aws_iam
  updatepermissions:
    # Defines an HTTP API endpoint that calls the main function in get.js
    # - path: url path is /footprint/users
    # - method: GET request
    handler: updatepermissions.main
    events:
      - http:
          path: footprint/updatepermissions
          method: post
          cors: true
          authorizer: aws_iam    
  updatememberactive:
    # Defines an HTTP API endpoint that calls the main function in get.js
    # - path: url path is /footprint/users
    # - method: GET request
    handler: updatememberactive.main
    events:
      - http:
          path: footprint/updatememberactive
          method: post
          cors: true
          authorizer: aws_iam         
  updatecustompermissions:
    # Defines an HTTP API endpoint that calls the main function in get.js
    # - path: url path is /footprint/users
    # - method: GET request
    handler: updatecustompermissions.main
    events:
      - http:
          path: footprint/updatecustompermissions
          method: post
          cors: true
          authorizer: aws_iam        
  updateemail:
    # Defines an HTTP API endpoint that calls the main function in get.js
    # - path: url path is /footprint/users
    # - method: GET request
    handler: updateemail.main
    events:
      - http:
          path: footprint/updateemail
          method: post
          cors: true
          authorizer: aws_iam
  updateuuid:
    # Defines an HTTP API endpoint that calls the main function in get.js
    # - path: url path is /footprint/users
    # - method: GET request
    handler: updateuuid.main
    events:
      - http:
          path: footprint/updateuuid
          method: post
          cors: true
          authorizer: aws_iam
  updateusergeneral:
    # Defines an HTTP API endpoint that updates the user general section - updateusergeneral.js
    # - path: url path is /footprint/updateusergeneral
    # - method: GET request
    handler: updateusergeneral.main
    events:
      - http:
          path: footprint/updateusergeneral
          method: post
          cors: true
          authorizer: aws_iam
  updateuseridentity:
    # Defines an HTTP API endpoint that updates the user identity section - updateuseridentity.js
    # - path: url path is /footprint/updateuseridentity
    # - method: GET request
    handler: updateuseridentity.main
    events:
      - http:
          path: footprint/updateuseridentity
          method: post
          cors: true
          authorizer: aws_iam
  updateuserother:
    # Defines an HTTP API endpoint that updates the user other section - updateuserother.js
    # - path: url path is /footprint/updateuserother
    # - method: GET request
    handler: updateuserother.main
    events:
      - http:
          path: footprint/updateuserother
          method: post
          cors: true
          authorizer: aws_iam
  updateuseraddress:
    # Defines an HTTP API endpoint that updates the user address section - updateuseraddress.js
    # - path: url path is /footprint/updateuseraddress
    # - method: GET request
    handler: updateuseraddress.main
    events:
      - http:
          path: footprint/updateuseraddress
          method: post
          cors: true
          authorizer: aws_iam
  updateusernextofkin:
    # Defines an HTTP API endpoint that updates the user next of kin section - updateusernextofkin.js
    # - path: url path is /footprint/updateusernextofkin
    # - method: GET request
    handler: updateusernextofkin.main
    events:
      - http:
          path: footprint/updateusernextofkin
          method: post
          cors: true
          authorizer: aws_iam
  getalltypes:
    # Defines an HTTP API endpoint that calls the main function in get.js
    # - path: url path is /footprint/types
    # - method: GET request
    handler: getalltypes.main
    events:
      - http:
          path: footprint/types/{id}
          method: get
          cors: true
          authorizer: aws_iam
  getallcardpermissions:
    # Defines an HTTP API endpoint that calls the main function in get.js
    # - path: url path is /footprint/types
    # - method: GET request
    handler: getallcardpermissions.main
    events:
      - http:
          path: footprint/getallcardpermissions
          method: get
          cors: true
          authorizer: aws_iam        
  deletepermission:
    # Defines an HTTP API endpoint that calls the main function in get.js
    # - path: url path is /footprint/types
    # - method: GET request
    handler: deletepermission.main
    events:
      - http:
          path: footprint/deletepermission/{id}
          method: get
          cors: true
          authorizer: aws_iam        
  getrole:
    # Defines an HTTP API endpoint that calls the main function in get.js
    # - path: url path is /footprint/types
    # - method: GET request
    handler: getrole.main
    events:
      - http:
          path: footprint/roles/{id}
          method: get
          cors: true
          authorizer: aws_iam
  getallgroups:
    # Defines an HTTP API endpoint that calls the main function in get.js
    # - path: url path is /footprint/types
    # - method: GET request
    # - created : jaco brits
    handler: getallgroups.main
    events:
      - http:
          path: footprint/groups
          method: get
          cors: true
          authorizer: aws_iam
  # grouptomembercustom:
  #   # Defines an HTTP API endpoint that calls the main function in get.js
  #   # - path: url path is /footprint/types
  #   # - method: GET request
  #   # - created : jaco brits
  #   handler: grouptomembercustom.main
  #   events:
  #     - http:
  #         path: footprint/grouptomembercustom
  #         method: get
  #         cors: true
  #         authorizer: aws_iam        

# Create our resources with separate CloudFormation templates
resources:
  # API Gateway Errors
  - ${file(resources/api-gateway-errors.yml)}