AtlassianPS / JiraPS

PowerShell module to interact with Atlassian JIRA
https://AtlassianPS.org/module/JiraPS
MIT License
321 stars 131 forks source link

get-jirauser is failing against cloud instance #465

Open tsimons-mlmic opened 1 year ago

tsimons-mlmic commented 1 year ago

Description

While connected to our Jira Cloud instance, I'm unable to get-jirauser, it returns an error. Other commands, add-jiraissue, etc, have been verified as wworking

Steps To Reproduce

  1. Install, load JiraPS
  2. Set-JiraConfigServer and establish new-jirasession
  3. Command: get-jirauser -username "" to query all users fails:
    Invoke-JiraMethod : The username or property query parameter must be provided
    get-jirauser : No results when searching for user 
  4. Command: get-user -username jane@domain.com for the current user, also returns:
    
    Invoke-JiraMethod : The query parameter 'username' is not supported in GDPR strict mode.
    get-jirauser : No results when searching for user jane@domain.com

## Expected behavior

I've never been able to use this, I would assume it would return usable key pairs

## Your Environment

We are using Jira Cloud 

`PS C:\WINDOWS\system32> Get-Module JiraPS -ListAvailable | Select Name, Version VERBOSE: Populating RepositorySourceLocation property for module JiraPS. VERBOSE: Loading module from path 'C:\Users\\Documents\WindowsPowerShell\Modules\JiraPS\2.14.6\JiraPS.psm1'.

Name Version


JiraPS 2.14.6

PS C:\WINDOWS\system32> $PSVersionTable

Name Value


PSVersion 5.1.19041.1682
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.19041.1682
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

PS C:\WINDOWS\system32> `



## Possible Solution

unknown
Ayanmullick commented 1 year ago

Any update on this?

cjvanderlinden commented 1 year ago

I am seeing the same thing - and it seems it's because it's using v2 of the API in the module?

How to replicate:

$cred = Get-Credential
PowerShell credential request
Enter your credentials.
User: email@domain.com
Password for user email@domain.com: ************************
Set-JiraConfigServer -Server "https://company.atlassian.net"
New-JiraSession -Credential $cred

Username               WebSession
--------               ----------
email@domain.com Microsoft.PowerShell.Commands.WebRequestSession

get-jirauser -Name accountID -Credential $cred -Verbose
VERBOSE: [Get-JiraUser] Function started
VERBOSE: [Get-JiraConfigServer] Function started
VERBOSE: [Get-JiraConfigServer] Complete
VERBOSE: [Get-JiraUser] Processing [accountID]
VERBOSE: [Invoke-JiraMethod] Function started
VERBOSE: [ConvertTo-GetParameter] Making HTTP get parameter string out of a hashtable
VERBOSE:
Name                           Value
----                           -----
username                       accountID
maxResults                     50

VERBOSE: [Invoke-JiraMethod] Get https://company.atlassian.net/rest/api/2/user/search?username=accountID&maxResults=50
VERBOSE: [Invoke-JiraMethod] Failed to get an answer from the server
VERBOSE: [Test-ServerResponse] Checking response headers for authentication errors
VERBOSE: [Invoke-JiraMethod] Status code: BadRequest
VERBOSE: [Resolve-ErrorWebResponse] Function started
VERBOSE: [Resolve-ErrorWebResponse] Retrieved body of HTTP response for more information about the error ($responseBody)
Invoke-JiraMethod: The query parameter 'username' is not supported in GDPR strict mode.

Invoke-JiraMethod:

VERBOSE: [Resolve-ErrorWebResponse] Function ended
VERBOSE: [Invoke-JiraMethod] Function ended
Get-JiraUser: No results when searching for user accountID
VERBOSE: [Get-JiraUser] Complete
get-module jiraps

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Script     2.14.6                JiraPS                              {Add-JiraFilterPermission, Add-JiraGroupMember, A…

PS C:\Users\tdpocv0> $psversiontable

Name                           Value
----                           -----
PSVersion                      7.2.6
PSEdition                      Core
GitCommitId                    7.2.6
OS                             Microsoft Windows 10.0.19044
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
grmn46 commented 10 months ago

There is an issue in lines 2736 and 2737 in the JiraPS.psm1 file in version 2.14.6 of the JiraPS PowerShell Module.

        $searchResourceUri = "$server/rest/api/2/user/search?username={0}"
        $exactResourceUri = "$server/rest/api/2/user?username={0}"

According to the Jira REST API documentation, the "username" query parameter is deprecated.

In this section of the documentation, they say you can use the query parameter named "query" to match against the displayName and emailAddress user attributes.

In my install of the JiraPS module, I have modified my JiraPS.psm1 file to use the query parameter, "query".

        $searchResourceUri = "$server/rest/api/2/user/search?query={0}"
        $exactResourceUri = "$server/rest/api/2/user?query={0}"