<commit_before>#!powershell
# This file is part of Ansible
#
# Copyright 2014, <NAME> <<EMAIL>>
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible.  If not, see <http://www.gnu.org/licenses/>.

# WANT_JSON
# POWERSHELL_COMMON

$url = "http://sdk-for-net.amazonwebservices.com/latest/AWSToolsAndSDKForNet.msi"
$sdkdest = "C:\AWSPowerShell.msi"

# Global flags
$isLeaf = $false
$isContainer = $false

$params = Parse-Args $args;

$result = New-Object psobject @{
    win_s3 = New-Object psobject
    changed = $false
}

# Check if AWS SDK is installed
$list = Get-Module -ListAvailable
# If not download it and install
If (-Not ($list -match "AWSPowerShell")){
    Try{
        $client = New-Object System.Net.WebClient
        $client.DownloadFile($url, $sdkdest)
    }
    Catch {
        Fail-Json $result "Error downloading AWS-SDK from $url and saving as $sdkdest"
    }
    Try{
        msiexec.exe /i $sdkdest /qb
    }
    Catch {
        Fail-Json $result "Error installing $sdkdest"
    }
    Set-Attr $result.win_s3 "aws_sdk_status" "aws_sdk was installed"
}
Else {
    Set-Attr $result.win_s3 "aws_sdk_status" "present"
}

# Import Module
Try {
    Import-Module AWSPowerShell
}
Catch {
    Fail-Json $result "Error importing module AWSPowerShell"
}

# ---Get Parameters--- (BUCKET, KEY, LOCAL, RM, METHOD, ACCESS_KEY, SECRET_KEY)
# BUCKET
If ($params.bucket) {
    $bucket = $params.bucket.toString()

    # Test that the bucket exists
    Try{
        Test-S3Bucket -BucketName $bucket
    }
    Catch {
        Fail-Json $result "Error. Bucket: $bucket not found. Or authorization to access bucket failed."
    }
}
Else {
    Fail-Json $result "missing required argument: bucket"
}

# KEY
If ($params.key) {
    $key = $params.key.toString()
}
Else {
    Fail-Json $result "missing required argument: key"
}

# RM (remove local file after successful upload)
If ($params.rm -match "true" -Or "yes") {
    $rm = $true
}
Else {
    $rm = $false
}

# LOCAL (file)
If ($params.local) {
    $local = $params.local.toString()

    # test that local file exists
    If (Test-Path $local -PathType Leaf)){
        $isLeaf = $true
    }
    ElseIf (Test-Path $local -PathType Container){
        $isContainer = $true
    }
    Else{
        Fail-Json $result "Local file or directory: $local does not exist"
    }
}
Else {
    Fail-Json $result "missing required argument: local"
}

# METHOD
If ($params.method) {
    $method = $params.method.toString()

    # Check for valid method<commit_msg>fixes extra paren<commit_after>#!powershell
# This file is part of Ansible
#
# Copyright 2014, <NAME> <<EMAIL>>
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible.  If not, see <http://www.gnu.org/licenses/>.

# WANT_JSON
# POWERSHELL_COMMON

$url = "http://sdk-for-net.amazonwebservices.com/latest/AWSToolsAndSDKForNet.msi"
$sdkdest = "C:\AWSPowerShell.msi"

# Global flags
$isLeaf = $false
$isContainer = $false

$params = Parse-Args $args;

$result = New-Object psobject @{
    win_s3 = New-Object psobject
    changed = $false
}

# Check if AWS SDK is installed
$list = Get-Module -ListAvailable
# If not download it and install
If (-Not ($list -match "AWSPowerShell")){
    Try{
        $client = New-Object System.Net.WebClient
        $client.DownloadFile($url, $sdkdest)
    }
    Catch {
        Fail-Json $result "Error downloading AWS-SDK from $url and saving as $sdkdest"
    }
    Try{
        msiexec.exe /i $sdkdest /qb
    }
    Catch {
        Fail-Json $result "Error installing $sdkdest"
    }
    Set-Attr $result.win_s3 "aws_sdk_status" "aws_sdk was installed"
}
Else {
    Set-Attr $result.win_s3 "aws_sdk_status" "present"
}

# Import Module
Try {
    Import-Module AWSPowerShell
}
Catch {
    Fail-Json $result "Error importing module AWSPowerShell"
}

# ---Get Parameters--- (BUCKET, KEY, LOCAL, RM, METHOD, ACCESS_KEY, SECRET_KEY)
# BUCKET
If ($params.bucket) {
    $bucket = $params.bucket.toString()

    # Test that the bucket exists
    Try{
        Test-S3Bucket -BucketName $bucket
    }
    Catch {
        Fail-Json $result "Error. Bucket: $bucket not found. Or authorization to access bucket failed."
    }
}
Else {
    Fail-Json $result "missing required argument: bucket"
}

# KEY
If ($params.key) {
    $key = $params.key.toString()
}
Else {
    Fail-Json $result "missing required argument: key"
}

# RM (remove local file after successful upload)
If ($params.rm -match "true" -Or "yes") {
    $rm = $true
}
Else {
    $rm = $false
}

# LOCAL (file)
If ($params.local) {
    $local = $params.local.toString()

    # test that local file exists
    If (Test-Path $local -PathType Leaf){
        $isLeaf = $true
    }
    ElseIf (Test-Path $local -PathType Container){
        $isContainer = $true
    }
    Else{
        Fail-Json $result "Local file or directory: $local does not exist"
    }
}
Else {
    Fail-Json $result "missing required argument: local"
}

# METHOD
If ($params.method) {
    $method = $params.method.toString()

    # Check for valid method
{'fraction_non_alphanumeric': 0.11195634198776253, 'fraction_numerical': 0.0029766826525549858, 'mean_word_length': 3.1003389830508477, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '307451', 'n_tokens_mistral': 2003, 'n_tokens_neox': 1932, 'n_words': 657}