Skip to content

Commit

Permalink
Merge pull request #69 from okta/lr-OKTA-821497-get-okta-logs-fix-sin…
Browse files Browse the repository at this point in the history
…ce-until-query-params

Fix: Get-OktaLogs changes the required date format for "since" and "until" query params #55
  • Loading branch information
laura-rodriguez authored Dec 19, 2024
2 parents f78b2c6 + e3fba1c commit 5c1de87
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 53 deletions.
4 changes: 2 additions & 2 deletions Build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ $Manifest = @{
ReleaseNotes = 'https://github.com/okta/okta-powershell-cli/releases'


ModuleVersion = '1.0.3'
ModuleVersion = '1.0.4'


RootModule = 'Okta.PowerShell.psm1'
Guid = '{5E82B81C-92D5-47BC-A10F-E26B40081903}' # Has to be static, otherwise each new build will be considered different module
Guid = '{257FCF83-C4E5-475C-B2C7-E624D7A7B6F3}' # Has to be static, otherwise each new build will be considered different module

PowerShellVersion = '6.2'

Expand Down
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,14 @@ _links : @{logo=System.Object[]; users=; apps=}
> Note: If you want to remove the access token from configuration you can execute `Invoke-OktaRemoveAccessToken`
### Configure a proxy

```powershell
$proxyUrl = "http://127.0.0.1:8888"
$webProxy = New-Object System.Net.WebProxy($proxyUrl)
$Configuration.Proxy = $webProxy
```

### Get a user

```powershell
Expand Down Expand Up @@ -259,6 +267,17 @@ $NewApp = Initialize-OktaOpenIdConnectApplication -Label "New App" -SignOnMode "
> Note: For more API samples checkout our [tests](https://github.com/okta/okta-powershell-cli/tree/main/tests/)
### Get logs

Since the System Log API requires `since` and `until` query params to be ISO 8601 compliant timestamp, make sure to format dates accordingly:

```powershell
$since = (Get-Date).AddMonths(-6).ToString("yyyy-MM-ddTHH:mm:ssZ")
$until = (Get-Date).ToString("yyyy-MM-ddTHH:mm:ssZ")
Get-OktaLogs -since $since -until $until
```

## Rate Limiting

The Okta API will return 429 responses if too many requests are made within a given time. Please see [Rate Limiting at Okta] for a complete list of which endpoints are rate limited. When a 429 error is received, the `X-Rate-Limit-Reset` header will tell you the time at which you can retry. This section discusses methods for handling rate limiting with this SDK.
Expand Down
36 changes: 18 additions & 18 deletions docs/OktaSystemLogApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ Method | HTTP request | Description
<a id="Get-OktaLogs"></a>
# **Get-OktaLogs**
> LogEvent[] Get-OktaLogs<br>
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[-Since] <System.Nullable[System.DateTime]><br>
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[-Until] <System.Nullable[System.DateTime]><br>
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[-Since] <String><br>
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[-Until] <String><br>
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[-After] <String><br>
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[-Filter] <String><br>
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[-Q] <String><br>
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[-Limit] <System.Nullable[Int32]><br>
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[-SortOrder] <String><br>
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[-After] <String><br>
List all System Log Events

Expand All @@ -31,17 +31,17 @@ $Configuration = Get-OktaConfiguration
$Configuration.ClientId = "YOUR_CLIENT_ID"
$Configuration.Scope = "OKTA_SCOPES" # for example okta.users.read
$Since = (Get-Date) # System.DateTime | (optional)
$Until = (Get-Date) # System.DateTime | (optional)
$Filter = "MyFilter" # String | (optional)
$Q = "MyQ" # String | (optional)
$Limit = 56 # Int32 | (optional) (default to 100)
$SortOrder = "MySortOrder" # String | (optional) (default to "ASCENDING")
$After = "MyAfter" # String | (optional)
$Since = "MySince" # String | Filters the lower time bound of the log events `published` property for bounded queries or persistence time for polling queries (optional) (default to "7 days prior to until")
$Until = "MyUntil" # String | Filters the upper time bound of the log events `published` property for bounded queries or persistence time for polling queries. (optional) (default to "current time")
$After = "MyAfter" # String | Retrieves the next page of results. Okta returns a link in the HTTP Header (`rel=next`) that includes the after query parameter (optional)
$Filter = "MyFilter" # String | Filter expression that filters the results. All operators except [ ] are supported. See [Filter](https://developer.okta.com/docs/api/#filter). (optional)
$Q = "MyQ" # String | Filters log events results by one or more case insensitive keywords. (optional)
$Limit = 56 # Int32 | Sets the number of results that are returned in the response (optional) (default to 100)
$SortOrder = "ASCENDING" # String | The order of the returned events that are sorted by the `published` property (optional) (default to "ASCENDING")
# List all System Log Events
try {
$Result = Get-OktaLogs -Since $Since -Until $Until -Filter $Filter -Q $Q -Limit $Limit -SortOrder $SortOrder -After $After
$Result = Get-OktaLogs -Since $Since -Until $Until -After $After -Filter $Filter -Q $Q -Limit $Limit -SortOrder $SortOrder
} catch {
Write-Host ("Exception occurred when calling Get-OktaLogs: {0}" -f ($_.ErrorDetails | ConvertFrom-Json))
Write-Host ("Response headers: {0}" -f ($_.Exception.Response.Headers | ConvertTo-Json))
Expand All @@ -52,13 +52,13 @@ try {

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**Since** | **System.DateTime**| | [optional]
**Until** | **System.DateTime**| | [optional]
**Filter** | **String**| | [optional]
**Q** | **String**| | [optional]
**Limit** | **Int32**| | [optional] [default to 100]
**SortOrder** | **String**| | [optional] [default to &quot;ASCENDING&quot;]
**After** | **String**| | [optional]
**Since** | **String**| Filters the lower time bound of the log events &#x60;published&#x60; property for bounded queries or persistence time for polling queries | [optional] [default to &quot;7 days prior to until&quot;]
**Until** | **String**| Filters the upper time bound of the log events &#x60;published&#x60; property for bounded queries or persistence time for polling queries. | [optional] [default to &quot;current time&quot;]
**After** | **String**| Retrieves the next page of results. Okta returns a link in the HTTP Header (&#x60;rel&#x3D;next&#x60;) that includes the after query parameter | [optional]
**Filter** | **String**| Filter expression that filters the results. All operators except [ ] are supported. See [Filter](https://developer.okta.com/docs/api/#filter). | [optional]
**Q** | **String**| Filters log events results by one or more case insensitive keywords. | [optional]
**Limit** | **Int32**| Sets the number of results that are returned in the response | [optional] [default to 100]
**SortOrder** | **String**| The order of the returned events that are sorted by the &#x60;published&#x60; property | [optional] [default to &quot;ASCENDING&quot;]

### Return type

Expand Down
2 changes: 1 addition & 1 deletion openapi3/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"templateDir": "./codegen-templates",
"outputDir" : "../",
"inputSpec" : "./management.yaml",
"packageVersion" : "1.0.3",
"packageVersion" : "1.0.4",
"packageDescription" : "Official PowerShell CLI for the Okta API",
"packageTitle" : "Official PowerShell for the Okta API",
"packageCompany" : "Okta, Inc.",
Expand Down
28 changes: 22 additions & 6 deletions openapi3/management.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10572,37 +10572,53 @@ paths:
operationId: getLogs
parameters:
- name: since
description: Filters the lower time bound of the log events `published` property for bounded queries or persistence time for polling queries
in: query
schema:
type: string
format: date-time
format: ISO 8601 compliant timestamp
default: 7 days prior to until
- name: until
description: Filters the upper time bound of the log events `published` property for bounded queries or persistence time for polling queries.
in: query
schema:
type: string
format: date-time
format: ISO 8601 compliant timestamp
default: current time
- name: after
description: Retrieves the next page of results. Okta returns a link in the HTTP Header (`rel=next`) that includes the after query parameter
in: query
schema:
type: string
format: Opaque token
- name: filter
description: Filter expression that filters the results. All operators except [ ] are supported. See [Filter](https://developer.okta.com/docs/api/#filter).
in: query
schema:
type: string
format: SCIM Filter expression
- name: q
description: Filters log events results by one or more case insensitive keywords.
in: query
schema:
type: string
format: URL encoded string. Max length is 40 characters per keyword, with a maximum of 10 keyword filters per query (before encoding)
- name: limit
description: Sets the number of results that are returned in the response
in: query
schema:
type: integer
format: Integer between 0 and 1000
default: 100
- name: sortOrder
description: The order of the returned events that are sorted by the `published` property
in: query
schema:
type: string
enum:
- ASCENDING
- DESCENDING
default: ASCENDING
- name: after
in: query
schema:
type: string
responses:
'200':
description: Success
Expand Down
43 changes: 22 additions & 21 deletions src/Okta.PowerShell/Api/OktaSystemLogApi.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,25 @@ List all System Log Events
No description available.
.PARAMETER Since
No description available.
Filters the lower time bound of the log events `published` property for bounded queries or persistence time for polling queries
.PARAMETER Until
No description available.
Filters the upper time bound of the log events `published` property for bounded queries or persistence time for polling queries.
.PARAMETER After
Retrieves the next page of results. Okta returns a link in the HTTP Header (`rel=next`) that includes the after query parameter
.PARAMETER Filter
No description available.
Filter expression that filters the results. All operators except [ ] are supported. See [Filter](https://developer.okta.com/docs/api/#filter).
.PARAMETER Q
No description available.
Filters log events results by one or more case insensitive keywords.
.PARAMETER Limit
No description available.
Sets the number of results that are returned in the response
.PARAMETER SortOrder
No description available.
.PARAMETER After
No description available.
The order of the returned events that are sorted by the `published` property
.PARAMETER Uri
Expand All @@ -57,26 +57,27 @@ function Get-OktaLogs {
[CmdletBinding()]
Param (
[Parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $false)]
[System.Nullable[System.DateTime]]
[String]
${Since},
[Parameter(Position = 1, ValueFromPipelineByPropertyName = $true, Mandatory = $false)]
[System.Nullable[System.DateTime]]
[String]
${Until},
[Parameter(Position = 2, ValueFromPipelineByPropertyName = $true, Mandatory = $false)]
[String]
${Filter},
${After},
[Parameter(Position = 3, ValueFromPipelineByPropertyName = $true, Mandatory = $false)]
[String]
${Q},
${Filter},
[Parameter(Position = 4, ValueFromPipelineByPropertyName = $true, Mandatory = $false)]
[String]
${Q},
[Parameter(Position = 5, ValueFromPipelineByPropertyName = $true, Mandatory = $false)]
[System.Nullable[Int32]]
${Limit},
[Parameter(Position = 5, ValueFromPipelineByPropertyName = $true, Mandatory = $false)]
[String]
${SortOrder},
[Parameter(Position = 6, ValueFromPipelineByPropertyName = $true, Mandatory = $false)]
[ValidateSet("ASCENDING", "DESCENDING")]
[String]
${After},
${SortOrder},
[Parameter(ValueFromPipelineByPropertyName = $true, Mandatory = $false)]
[String]
${Uri},
Expand Down Expand Up @@ -119,6 +120,10 @@ function Get-OktaLogs {
$LocalVarQueryParameters['until'] = $Until
}

if ($After) {
$LocalVarQueryParameters['after'] = $After
}

if ($Filter) {
$LocalVarQueryParameters['filter'] = $Filter
}
Expand All @@ -135,10 +140,6 @@ function Get-OktaLogs {
$LocalVarQueryParameters['sortOrder'] = $SortOrder
}

if ($After) {
$LocalVarQueryParameters['after'] = $After
}

if ($Configuration["ApiKey"] -and $Configuration["ApiKey"]["apiToken"]) {
$LocalVarHeaderParameters['apiToken'] = $Configuration["ApiKey"]["apiToken"]
Write-Verbose ("Using API key 'apiToken' in the header for authentication in {0}" -f $MyInvocation.MyCommand)
Expand Down
6 changes: 3 additions & 3 deletions src/Okta.PowerShell/Okta.PowerShell.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# Generated by: Okta, Inc.
#
# Generated on: 2024-10-29
# Generated on: 2024-12-16
#

@{
Expand All @@ -12,13 +12,13 @@
RootModule = 'Okta.PowerShell.psm1'

# Version number of this module.
ModuleVersion = '1.0.3'
ModuleVersion = '1.0.4'

# Supported PSEditions
CompatiblePSEditions = 'Core'

# ID used to uniquely identify this module
GUID = '5e82b81c-92d5-47bc-a10f-e26b40081903'
GUID = '257fcf83-c4e5-475c-b2c7-e624d7a7b6f3'

# Author of this module
Author = 'Okta, Inc.'
Expand Down
2 changes: 1 addition & 1 deletion src/Okta.PowerShell/Private/OktaApiClient.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ function Invoke-OktaApiClient {
}
}

$OktaUserAgent = [Microsoft.PowerShell.Commands.PSUserAgent]::Chrome + " okta-powershell-module/1.0.3"
$OktaUserAgent = [Microsoft.PowerShell.Commands.PSUserAgent]::Chrome + " okta-powershell-module/1.0.4"


# Setting up vars for retry
Expand Down
2 changes: 1 addition & 1 deletion src/Okta.PowerShell/en-US/about_Okta.PowerShell.help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ LONG DESCRIPTION
This PowerShell module is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project:

- API version: 3.0.0
- SDK version: 1.0.3
- SDK version: 1.0.4
- Build package: org.openapitools.codegen.languages.PowerShellClientCodegen
For more information, please visit [https://developer.okta.com/](https://developer.okta.com/)

Expand Down

0 comments on commit 5c1de87

Please sign in to comment.