Public/SDK Wrappers/S3/New-VSS3Object.ps1

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
function New-VSS3Object {
    <#
    .SYNOPSIS
    Uploads an object to S3
    
    .PARAMETER BucketName
    The name of the bucket to contain the object.
    
    .PARAMETER CannedACL
    The canned access control list (CACL) to apply to the object. Valid options are: "NoACL","Private","PublicRead","PublicReadWrite","AuthenticatedRead","AWSExecRead","BucketOwnerRead","BucketOwnerFullControl","LogDeliveryWrite"
    
    .PARAMETER ContentBody
    Text content to be uploaded. Use this property if you want to upload plaintext to S3. The content type will be set to 'text/plain'.
    
    .PARAMETER ContentBody
    Text content to be uploaded. Use this property if you want to upload plaintext to S3. The content type will be set to 'text/plain'.
    
    .PARAMETER FilePath
    The full path and name to a file to be uploaded. If this is set the request will upload the specified file to S3.
    
    .PARAMETER Key
    The key used to identify the object in S3.
    
    .PARAMETER KMSKeyId
    The id of the AWS Key Management Service key that Amazon S3 should use to encrypt and decrypt the object. If a key id is not specified, the default key will be used for encryption and decryption.
    
    .PARAMETER ProfileName
    The name of the configuration profile to deploy the stack with. Defaults to $env:AWS_PROFILE, if set.
    
    .FUNCTIONALITY
    Vaporshell
    #>

    [cmdletbinding()]
    Param
    (
        [parameter(Mandatory = $true,Position = 0)]
        [String]
        $BucketName,
        [parameter(Mandatory = $false)]
        [ValidateSet("NoACL","Private","PublicRead","PublicReadWrite","AuthenticatedRead","AWSExecRead","BucketOwnerRead","BucketOwnerFullControl","LogDeliveryWrite")]
        [String]
        $CannedACL,
        [parameter(Mandatory = $false)]
        [System.String]
        $ContentBody,
        [parameter(Mandatory = $false)]
        [System.String]
        $FilePath,
        [parameter(Mandatory = $false)]
        [System.String]
        $Key,
        [parameter(Mandatory = $false)]
        [System.String]
        $KMSKeyId,
        [parameter(Mandatory = $false)]
        [String]
        $ProfileName = $env:AWS_PROFILE
    )
    Process {
        $method = "PutObject"
        $requestType = "Amazon.S3.Model.$($method)Request"
        $request = New-Object $requestType
        foreach ($key in $PSBoundParameters.Keys) {
            switch ($key) {
                CannedACL {
                    $request.CannedACL = [Amazon.S3.S3CannedACL]::$CannedACL
                }
                KMSKeyId {
                    $request.ServerSideEncryptionKeyManagementServiceKeyId = $KMSKeyId
                }
                Default {
                    if ($request.PSObject.Properties.Name -contains $key) {
                        $request.$key = $PSBoundParameters[$key]
                    }
                }
            }
        }
        $results = ProcessRequest $PSCmdlet.ParameterSetName $ProfileName $method $request
        if (!$results) {
            return
        }
        elseif ($results -is 'System.Management.Automation.ErrorRecord') {
            $PSCmdlet.ThrowTerminatingError($results)
        }
        elseif ($results) {
            return $results
        }
    }
}