mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Update slurp/win_ping/win_stat to use Get-Attr.
This commit is contained in:
parent
e5399b12b9
commit
f86db3a4dc
3 changed files with 20 additions and 49 deletions
|
@ -19,46 +19,28 @@
|
||||||
|
|
||||||
$params = Parse-Args $args;
|
$params = Parse-Args $args;
|
||||||
|
|
||||||
$src = '';
|
$src = Get-Attr $params "src" (Get-Attr $params "path" $FALSE);
|
||||||
If ($params.src.GetType)
|
|
||||||
{
|
|
||||||
$src = $params.src;
|
|
||||||
}
|
|
||||||
Else
|
|
||||||
{
|
|
||||||
If ($params.path.GetType)
|
|
||||||
{
|
|
||||||
$src = $params.path;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
If (-not $src)
|
If (-not $src)
|
||||||
{
|
{
|
||||||
$result = New-Object psobject @{};
|
Fail-Json (New-Object psobject) "missing required argument: src";
|
||||||
Fail-Json $result "missing required argument: src";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
If (Test-Path $src)
|
If (Test-Path -PathType Leaf $src)
|
||||||
{
|
{
|
||||||
If ((Get-Item $src).Directory) # Only files have the .Directory attribute.
|
$bytes = [System.IO.File]::ReadAllBytes($src);
|
||||||
{
|
$content = [System.Convert]::ToBase64String($bytes);
|
||||||
$bytes = [System.IO.File]::ReadAllBytes($src);
|
$result = New-Object psobject @{
|
||||||
$content = [System.Convert]::ToBase64String($bytes);
|
changed = $false
|
||||||
|
encoding = "base64"
|
||||||
$result = New-Object psobject @{
|
content = $content
|
||||||
changed = $false
|
};
|
||||||
encoding = "base64"
|
Exit-Json $result;
|
||||||
};
|
}
|
||||||
Set-Attr $result "content" $content;
|
ElseIf (Test-Path -PathType Container $src)
|
||||||
Exit-Json $result;
|
{
|
||||||
}
|
Fail-Json (New-Object psobject) ("is a directory: " + $src);
|
||||||
Else
|
|
||||||
{
|
|
||||||
$result = New-Object psobject @{};
|
|
||||||
Fail-Json $result ("is a directory: " + $src);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Else
|
Else
|
||||||
{
|
{
|
||||||
$result = New-Object psobject @{};
|
Fail-Json (New-Object psobject) ("file not found: " + $src);
|
||||||
Fail-Json $result ("file not found: " + $src);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,14 +19,11 @@
|
||||||
|
|
||||||
$params = Parse-Args $args;
|
$params = Parse-Args $args;
|
||||||
|
|
||||||
$data = 'pong';
|
$data = Get-Attr $params "data" "pong";
|
||||||
If ($params.data.GetType)
|
|
||||||
{
|
|
||||||
$data = $params.data;
|
|
||||||
}
|
|
||||||
|
|
||||||
$result = New-Object psobject @{
|
$result = New-Object psobject @{
|
||||||
changed = $false
|
changed = $false
|
||||||
ping = $data
|
ping = $data
|
||||||
};
|
};
|
||||||
|
|
||||||
Exit-Json $result;
|
Exit-Json $result;
|
||||||
|
|
|
@ -19,21 +19,13 @@
|
||||||
|
|
||||||
$params = Parse-Args $args;
|
$params = Parse-Args $args;
|
||||||
|
|
||||||
$path = $FALSE;
|
$path = Get-Attr $params "path" $FALSE;
|
||||||
If ($params.path.GetType)
|
|
||||||
{
|
|
||||||
$path = $params.path;
|
|
||||||
}
|
|
||||||
If ($path -eq $FALSE)
|
If ($path -eq $FALSE)
|
||||||
{
|
{
|
||||||
Fail-Json (New-Object psobject) "missing required argument: path";
|
Fail-Json (New-Object psobject) "missing required argument: path";
|
||||||
}
|
}
|
||||||
|
|
||||||
$get_md5 = $TRUE;
|
$get_md5 = Get-Attr $params "get_md5" $TRUE | ConvertTo-Bool;
|
||||||
If ($params.get_md5.GetType)
|
|
||||||
{
|
|
||||||
$get_md5 = $params.get_md5 | ConvertTo-Bool;
|
|
||||||
}
|
|
||||||
|
|
||||||
$result = New-Object psobject @{
|
$result = New-Object psobject @{
|
||||||
stat = New-Object psobject
|
stat = New-Object psobject
|
||||||
|
|
Loading…
Reference in a new issue