microsoft / PowerShellForGitHub

Microsoft PowerShell wrapper for GitHub API
Other
588 stars 186 forks source link

Cannot Get-GitHubOrganizationMember #370

Closed Liturgist closed 1 year ago

Liturgist commented 2 years ago

Issue Details

On a GitHub Enterprise Cloud account, Get-GitHubOrganizationMember is not working. It is working on a non-cloud GitHub Enterprise account.

I started by using Clear-GitHubAuthentication and Reset-GitHubConfiguration commands. Then, Set-GitHubAuthentication and Set-GitHubConfiguration were used.

It appears not to find the URI. StatusCode: 404, ReasonPhrase: 'Not Found'

Is this a correct URI to get members? RequestUri: 'https://github.com/enterprises/XXX/api/v3/orgs/XXX-internal/members'

Steps to reproduce the issue

PS C:\> Test-GitHubAuthenticationConfigured
True
PS C:\> Get-GitHubConfiguration -Name ApiHostName
github.com/enterprises/XXX
PS C:\> Get-GitHubOrganizationMember -OrganizationName XXX-internal
Invoke-WebRequest: C:\Users\lit\Documents\PowerShell\Modules\PowerShellForGitHub\0.16.1\GitHubCore.ps1:313
Line |
 313 |              $result = Invoke-WebRequest @params
     |                        ~~~~~~~~~~~~~~~~~~~~~~~~~
     | Not Found

PS C:\> $PSVersionTable.PSVersion.ToString()
7.2.6

Verbose logs showing the problem

PS C:\> get-error

Exception             :
    Type       : Microsoft.PowerShell.Commands.HttpResponseException
    Response   : StatusCode: 404, ReasonPhrase: 'Not Found', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:
                 {
                 Server: GitHub.com
                 Date: Fri, 30 Sep 2022 21:25:14 GMT
                 Transfer-Encoding: chunked
                 Vary: X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame
                 Vary: Accept-Encoding, Accept, X-Requested-With
                 Cache-Control: no-cache
                 Set-Cookie: logged_in=no; domain=.github.com; path=/; expires=Sat, 30 Sep 2023 21:25:14 GMT; secure; HttpOnly; SameSite=Lax
                 Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
                 X-Frame-Options: DENY
                 X-Content-Type-Options: nosniff
                 X-XSS-Protection: 0
                 Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin
                 Expect-CT: max-age=2592000, report-uri="https://api.github.com/_private/browser/errors"
                 Content-Security-Policy: default-src 'none'; base-uri 'self'; connect-src 'self'; form-action 'self'; img-src 'self' data:; script-src 'self';
style-src 'unsafe-inline'
                 X-GitHub-Request-Id: A2EC:4EBF:624C7E:8ED281:63375EBA
                 Content-Type: text/plain; charset=utf-8
                 }
    TargetSite :
        Name          : ThrowTerminatingError
        DeclaringType : System.Management.Automation.MshCommandRuntime, System.Management.Automation, Version=7.2.6.500, Culture=neutral,
PublicKeyToken=31bf3856ad364e35
        MemberType    : Method
        Module        : System.Management.Automation.dll
    Message    : Response status code does not indicate success: 404 (Not Found).
    Source     : System.Management.Automation
    HResult    : -2146233088
    StackTrace :
   at System.Management.Automation.MshCommandRuntime.ThrowTerminatingError(ErrorRecord errorRecord)
TargetObject          : Method: GET, RequestUri: 'https://github.com/enterprises/XXX/api/v3/orgs/XXX-internal/members', Version: 1.1, Content: <null>, Headers:
                        {
                        Accept: application/vnd.github.v3+json
                        User-Agent: PowerShellForGitHub
                        Authorization: token ghp_9xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxyloO
                        }
CategoryInfo          : InvalidOperation: (Method: GET, Reques…cazayp0tdp0TyloO
                        }:HttpRequestMessage) [Invoke-WebRequest], HttpResponseException
FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
ErrorDetails          : Not Found
InvocationInfo        :
    MyCommand        : Invoke-WebRequest
    ScriptLineNumber : 313
    OffsetInLine     : 23
    HistoryId        : 129
    ScriptName       : C:\Users\lit\Documents\PowerShell\Modules\PowerShellForGitHub\0.16.1\GitHubCore.ps1
    Line             :             $result = Invoke-WebRequest @params

    PositionMessage  : At C:\Users\lit\Documents\PowerShell\Modules\PowerShellForGitHub\0.16.1\GitHubCore.ps1:313 char:23
                       +             $result = Invoke-WebRequest @params
                       +                       ~~~~~~~~~~~~~~~~~~~~~~~~~
    PSScriptRoot     : C:\Users\lit\Documents\PowerShell\Modules\PowerShellForGitHub\0.16.1
    PSCommandPath    : C:\Users\lit\Documents\PowerShell\Modules\PowerShellForGitHub\0.16.1\GitHubCore.ps1
    InvocationName   : Invoke-WebRequest
    CommandOrigin    : Internal
ScriptStackTrace      : at Invoke-GHRestMethod, C:\Users\lit\Documents\PowerShell\Modules\PowerShellForGitHub\0.16.1\GitHubCore.ps1: line 313
                        at Invoke-GHRestMethodMultipleResult, C:\Users\lit\Documents\PowerShell\Modules\PowerShellForGitHub\0.16.1\GitHubCore.ps1: line 703
                        at Get-GitHubOrganizationMember, C:\Users\lit\Documents\PowerShell\Modules\PowerShellForGitHub\0.16.1\GitHubOrganizations.ps1: line 66
                        at <ScriptBlock>, <No file>: line 1

PS C:> Get-ComputerInfo -Property @(

        'OsName',
        'OsOperatingSystemSKU',
        'OSArchitecture',
        'WindowsVersion',
        'WindowsBuildLabEx',
        'OsLanguage',
        'OsMuiLanguages')

OsName : Microsoft Windows 10 Enterprise OsOperatingSystemSKU : EnterpriseEdition OsArchitecture : 64-bit WindowsVersion : 2009 WindowsBuildLabEx : 19041.1.amd64fre.vb_release.191206-1406 OsLanguage : en-US OsMuiLanguages : {en-US}


#### PowerShell Version

PS C:> $PSVersionTable

Name Value


PSVersion 7.2.6 PSEdition Core GitCommitId 7.2.6 OS Microsoft Windows 10.0.19042 Platform Win32NT PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…} PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1 WSManStackVersion 3.0


#### Module Version

PS C:> @(

        "Running: $((Get-Module -Name PowerShellForGitHub) | Select-Object -ExpandProperty Version)",
        "Installed: $((Get-Module -Name PowerShellForGitHub -ListAvailable) | Select-Object -ExpandProperty Version)"
    ) -join [Environment]::NewLine

Running: 0.16.1 Installed: 0.16.1

HowardWolosky commented 2 years ago

Hello again @Liturgist.

Some thoughts:

  1. I appreciate you trying to root out configuration issues by first using Reset-GitHubConfiguration and Clear-GitHubAuthentication to see if the issue still repro'd. Just to be clear though, it's expected that most users will likely never need to use those commands. Just wanted to make sure expectations were properly set that you shouldn't need to be using those commands normally.

  2. To better understand the scope of the issue you're having, is Get-GitHubOrganizationMember the only command that's currently failing in this scenario? In other words, can you successfully use (for instance) Get-GitHubRepository and Get-GitHubUser? Or was Get-GitHubOrganizationMember just one example of how all of the commands are failing for you under a GitHub Enterprise configuration?

  3. As I mentioned last time, I don't have access to a GitHub Enterprise system myself, so I don't have an easy way to diagnose this. I'm just going off the documentation that I can find online. Here's the core documentation I could find for GitHub Cloud. According to that:

    All API access is over HTTPS, and accessed from https://api.github.com.

    That guidance is consistent with the documentation for GitHub public acccess. Based on that, it sounds like you're not supposed to change the ApiHostName at all.

So, based on all this, it sounds like using GitHub Enterprise Cloud should require no change in configuration from folks who are using regular GitHub.

Liturgist commented 1 year ago

I think the problem was that my PAT (Personal Access Token) had not been enabled for the repo.

I hope you are able to get access to an Enterprise account.