All files / lib/aws-operations aws-client.js

64.1% Statements 25/39
30.77% Branches 4/13
57.14% Functions 4/7
64.1% Lines 25/39

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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98                          33x   33x 33x     1x 1x 1x     1x 1x 1x     1x   1x       1x 1x 1x 1x     1x                                               1x 1x 1x 1x     1x       1x 1x   1x                   33x                  
/* 
 * Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
 * the License. A copy of the License is located at
 *
 *     http://aws.amazon.com/apache2.0/
 *
 * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
 * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
 * and limitations under the License.
*/
"use strict";
const AWS = require('aws-sdk')
 
const awsmobilejsConstant = require('../utils/awsmobilejs-constant.js')
const cliConfigManager = require('../utils/cli-config-manager.js')
 
function Mobile(awsDetails){
    AWS.config.loadFromPath(awsDetails.info.AWSConfigFilePath)
    AWS.config.update({customUserAgent: awsmobilejsConstant.CustomUserAgent})
    AWS.config.update({region: 'us-east-1'}) 
    //mobile api is only available in us-ease-1, but mobile project can be created in other regions
   
    let awsmobileAPIEndpoint = awsmobilejsConstant.AWSMobileAPIEndPoint
    let cliConfig = cliConfigManager.getAWSMobileCLIConfig()
    Iif(cliConfig && cliConfig.isInDevMode && cliConfig.awsmobileAPIEndpoint){
        awsmobileAPIEndpoint = cliConfig.awsmobileAPIEndpoint
    } 
    const ep = new AWS.Endpoint(awsmobileAPIEndpoint)
 
    return new AWS.Mobile({endpoint: ep})
}
 
function S3(awsDetails, region){
    AWS.config.loadFromPath(awsDetails.info.AWSConfigFilePath)
    AWS.config.update({customUserAgent: awsmobilejsConstant.CustomUserAgent})
    Eif(region){
        AWS.config.update({region: region})
    }
 
    return new AWS.S3()
}
 
function DynamoDB(awsDetails, region){
    AWS.config.loadFromPath(awsDetails.info.AWSConfigFilePath)
    AWS.config.update({customUserAgent: awsmobilejsConstant.CustomUserAgent})
    if(region){
        AWS.config.update({region: region})
    }
 
    return new AWS.DynamoDB()
}
 
function IAM(awsDetails, region){
    AWS.config.loadFromPath(awsDetails.info.AWSConfigFilePath)
    AWS.config.update({customUserAgent: awsmobilejsConstant.CustomUserAgent})
    if(region){
        AWS.config.update({region: region})
    }
 
    return new AWS.IAM()
}
 
function Lambda(awsDetails, region){
    AWS.config.loadFromPath(awsDetails.info.AWSConfigFilePath)
    AWS.config.update({customUserAgent: awsmobilejsConstant.CustomUserAgent})
    Eif(region){
        AWS.config.update({region: region})
    }
 
    return new AWS.Lambda()
}
 
function CloudFront(awsDetails){
    AWS.config.loadFromPath(awsDetails.info.AWSConfigFilePath)
    AWS.config.update({customUserAgent: awsmobilejsConstant.CustomUserAgent})
 
    return new AWS.CloudFront()
}
 
function AppSync(awsDetails){
    AWS.config.loadFromPath(awsDetails.info.AWSConfigFilePath)
    AWS.config.update({customUserAgent: awsmobilejsConstant.CustomUserAgent})
 
    return new AWS.AppSync()
}
 
module.exports = {
    Mobile,
    S3,
    Lambda,
    DynamoDB,
    CloudFront,
    AppSync, 
    IAM
}