
#    _____ _            _        
#   /  ___| |          | |       
#   \ `--.| | __ _  ___| | __    
#    `--. \ |/ _` |/ __| |/ /    
#   /\__/ / | (_| | (__|   <     
#   \____/|_|\__,_|\___|_|\_\    
#   ______           _   ___ _   
#   |  _  \         | | / (_) |  
#   | | | |_____   _| |/ / _| |_ 
#   | | | / _ \ \ / /    \| | __|
#   | |/ /  __/\ V /| |\  \ | |_ 
#   |___/ \___| \_/ \_| \_/_|\__|
#
# This file is the main config file for your app.
# You can always add more config options for more control.
#
# For full config options, check the docs:
#    docs.serverless.com
#
# Happy Coding!


service: slack-devkit

custom:
  # The API Gateway path
  slack_path: slack

  # The dynamodb table to store OAuth access data
  slack_table_name: Workspaces

  # Space delimited scopes
  slack_scope: "commands,conversations:read"

  # The path to redirect to after an install
  slack_redirect_uri: https://abcd123.execute-api.us-east-1.amazonaws.com/

  # Signing Secret
  slack_signing_secret: "1111111111111"
  
  # Client ID - quotes required
  slack_client_id: "22222222.33333333"
  
  # Client Secret - quotes required
  slack_client_secret: "12341234123412341234"
  
  # Log all events to CloudWatch
  slack_enable_logging: true


provider:
  name: aws
  runtime: nodejs8.10
  profile: serverless
  iamRoleStatements:
    - Effect: Allow
      Action:
        - dynamodb:DescribeTable
        - dynamodb:Query
        - dynamodb:Scan
        - dynamodb:GetItem
        - dynamodb:PutItem
        - dynamodb:UpdateItem
        - dynamodb:DeleteItem
      Resource: "arn:aws:dynamodb:us-east-1:*:*"
  environment:
    SCOPE: ${self:custom.slack_scope}
    TABLE_NAME: ${self:custom.slack_table_name}
    CLIENT_ID: ${self:custom.slack_client_id}
    CLIENT_SECRET: ${self:custom.slack_client_secret}
    SIGNING_SECRET: ${self:custom.slack_signing_secret}
    ENABLE_LOGGING: ${self:custom.slack_enable_logging}
    REDIRECT_URI: ${self:custom.slack_redirect_uri}

functions:
  slack:
    handler: examples/lambda.handler
    events:
      - http:
          path: ${self:custom.slack_path}
          method: ANY
          integration: lambda
          response:
            statusCodes:
              201:
                pattern: ''
              301:
                pattern: http.*
                headers:
                  Location: integration.response.body.errorMessage
                  Cache-Control: "'no-cache, no-store, must-revalidate'"
          request:
            template:
              application/x-www-form-urlencoded: >
                {
                  "method": "$context.httpMethod",
                  "body": "$util.escapeJavaScript($input.body).replace("\'", "'")",
                  "query": {
                    #foreach($param in $input.params().querystring.keySet())
                    "$param": "$input.params().querystring.get($param)"
                    #if($foreach.hasNext),#end
                    #end
                  },
                  "headers": {
                    #foreach($param in $input.params().header.keySet())
                    "$param": "$util.escapeJavaScript($input.params().header.get($param))"
                    #if($foreach.hasNext),#end
                    #end
                  }
                }
              application/json: >
                {
                  "method": "$context.httpMethod",
                  "body": "$util.escapeJavaScript($input.body).replace("\'", "'")",
                  "query": {
                    #foreach($param in $input.params().querystring.keySet())
                    "$param": "$input.params().querystring.get($param)"
                    #if($foreach.hasNext),#end
                    #end
                  },
                  "headers": {
                    #foreach($param in $input.params().header.keySet())
                    "$param": "$util.escapeJavaScript($input.params().header.get($param))"
                    #if($foreach.hasNext),#end
                    #end
                  }
                }


resources:
  Resources:
    TeamsDynamoDbTable:
      Type: 'AWS::DynamoDB::Table'
      DeletionPolicy: Delete
      Properties:
        AttributeDefinitions:
          -
            AttributeName: id
            AttributeType: S
        KeySchema:
          -
            AttributeName: id
            KeyType: HASH
        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1
        TableName: ${self:custom.slack_table_name}
