Skip to content

Commit 36027da

Browse files
authored
Bug fixes
1 parent 71c2b76 commit 36027da

File tree

1 file changed

+37
-16
lines changed

1 file changed

+37
-16
lines changed

Module/OpConModule.psm1

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function OpCon_Login
4949
Param(
5050
[Parameter(Mandatory=$true)] [string]$url
5151
,[Parameter(Mandatory=$true)] [string]$user
52-
,[Parameter(Mandatory=$true)] [string]$password
52+
,[string] $password
5353
,[string] $appname
5454
)
5555

@@ -66,6 +66,18 @@ function OpCon_Login
6666
}
6767
}
6868
}
69+
elseif($user -like "Win*Auth*")
70+
{
71+
try
72+
{
73+
return Invoke-Restmethod -Method POST -Uri ($url + "/api/tokens") -ContentType "application/json" -UseDefaultCredentials
74+
}
75+
catch [Exception]
76+
{
77+
write-host $_
78+
write-host $_.Exception.Message
79+
}
80+
}
6981
else
7082
{
7183
$body = @{
@@ -90,6 +102,11 @@ function OpCon_Login
90102
}
91103
New-Alias "opc-login" OpCon_GetLogin
92104

105+
function OpCon_Errors($action)
106+
{
107+
$ErrorActionPreference = $action
108+
}
109+
93110
#Delete token from database
94111
function OpCon_DeleteAPIToken
95112
{
@@ -168,7 +185,7 @@ function OpCon_CreateGlobalProperty
168185
,[Parameter(Mandatory=$true)] [string]$token
169186
,[Parameter(Mandatory=$true)] [string]$name
170187
,[Parameter(Mandatory=$true)] [string]$value
171-
,[string] $encrypt
188+
,[string] $encrypt = $false
172189
)
173190

174191
#Get property information
@@ -180,7 +197,7 @@ function OpCon_CreateGlobalProperty
180197

181198
try
182199
{
183-
return nvoke-Restmethod -Method POST -Uri ($url + "/api/globalproperties") -Headers @{"authorization" = $token} -Body ($body | ConvertTo-Json) -ContentType "application/json"
200+
return Invoke-Restmethod -Method POST -Uri ($url + "/api/globalproperties") -Headers @{"authorization" = $token} -Body ($body | ConvertTo-Json) -ContentType "application/json"
184201
}
185202
catch [Exception]
186203
{
@@ -990,7 +1007,7 @@ function OpCon_GetDailyJob($url,$token,$sname,$jname,$date,$id)
9901007
New-Alias "opc-getdailyjob" OpCon_GetDailyJob
9911008

9921009
#Sends a job action to a job
993-
function OpCon_JobAction($url,$token,$sname,$jname,$date,$action,$reason)
1010+
function OpCon_JobAction($url,$token,$sname,$jname,$jobId,$date,$action,$reason)
9941011
{
9951012
if($action)
9961013
{
@@ -1014,23 +1031,27 @@ function OpCon_JobAction($url,$token,$sname,$jname,$date,$action,$reason)
10141031
}
10151032
}
10161033

1017-
if($jname -and $sname)
1034+
if($jname -and $sname -or $jobId)
10181035
{
10191036
if(!$date)
1037+
{ $date = Get-Date -Format "yyyy/MM/dd" }
1038+
1039+
$jobsArray = @()
1040+
if(!$jobId)
10201041
{
1021-
$date = Get-Date -Format "yyyy/MM/dd"
1022-
}
1023-
$job = OpCon_GetDailyJob -url $url -token $token -sname "$sname" -jname "$jname" -date $date
1042+
$job = OpCon_GetDailyJob -url $url -token $token -sname $sname -jname $jname -date $date
10241043

1025-
$counter = 0
1026-
$job | ForEach-Object{ $counter++ }
1027-
If($counter -ne 1)
1028-
{
1029-
Write-Host "Too many results for job!`r`n"
1044+
$counter = 0
1045+
$job | ForEach-Object{ $counter++ }
1046+
If($counter -ne 1)
1047+
{
1048+
Write-Host "Too many results for job!`r`n"
1049+
}
1050+
else
1051+
{ $jobsArray += @{ id=$job[0].id; } }
10301052
}
1031-
1032-
$jobsArray = @()
1033-
$jobsArray += @{ id=$job[0].id; }
1053+
else
1054+
{ $jobsArray += @{ id=$jobId } }
10341055

10351056
$body = @{
10361057
"action"=$action;

0 commit comments

Comments
 (0)