Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Cannot use repository on Github Enterprise instance with rate limiting disabled. #321

Closed
3 tasks done
tep opened this issue Mar 3, 2024 · 12 comments
Closed
3 tasks done
Assignees
Labels
🐛 Bug Something isn't working

Comments

@tep
Copy link

tep commented Mar 3, 2024

Issue validation

  • I checked the issue to prevent duplicate
  • I checked my configurations files and the documentation
  • My issue concern doesn't concern the Mkdocs template

Command used

Upload single current active note, Test the connection to the configured repository

Plugin version

7.0.2

Describe the bug

This Obsidian plugin cannot be used with a Github Enterprise instance where rate limiting has been disabled. When I attempt to do so, the Obsidian console log generates the following messages:

plugin:obsidian-mkdocs-publisher:21 [GitHub Publisher](qn.eval):
 Repository RepoOwner/repository-name exists. Now testing the main branch.
plugin:obsidian-mkdocs-publisher:21 [GitHub Publisher](main):
 HttpError: Rate limiting is not enabled.
    at eval (plugin:obsidian-mkdocs-publisher:17:43928)

This is against an internal (corporate) GHE instance that has no rate limiting -- as indicated by the following output from executing gh api --verbose /rate_limit against the enterprise server:

$ gh api --verbose /rate_limit
* Request at 2024-03-03 07:46:47.197074084 -0800 PST m=+0.036414897
* Request to https://redacted.hostname.tld/api/v3/rate_limit
> GET /api/v3/rate_limit HTTP/1.1
> Host: redacted.hostname.tld
> Accept: */* 
> Authorization: token redacted-auth-token
> Content-Type: application/json; charset=utf-8
> Time-Zone: America/Los_Angeles
> User-Agent: GitHub CLI 2.44.1

< HTTP/2.0 404 Not Found
< Access-Control-Allow-Origin: *
< Access-Control-Expose-Headers: ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset
< Cache-Control: no-cache
< Content-Security-Policy: default-src 'none'
< Content-Type: application/json; charset=utf-8
< Date: Sun, 03 Mar 2024 15:46:47 GMT 
< Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin
< Server: GitHub.com
< Strict-Transport-Security: max-age=31536000; includeSubdomains
< X-Accepted-Oauth-Scopes:
< X-Content-Type-Options: nosniff
< X-Frame-Options: deny
< X-Github-Api-Version-Selected: 2022-11-28
< X-Github-Enterprise-Version: 3.10.6
< X-Github-Media-Type: github.v3; format=json
< X-Github-Request-Id: 097f5601-b15f-4546-a7ed-2e0c61dbdd83
< X-Oauth-Client-Id: 178c6fc778ccc68e1d6a
< X-Oauth-Scopes: admin:org, admin:org_hook, admin:repo_hook, gist, repo, user
< X-Xss-Protection: 0

{
  "message": "Rate limiting is not enabled.",
  "documentation_url": "https://docs.github.com/[email protected]/rest/reference/rate-limit#get-rate-limit-status-for-the-authenticated-user"
}

This same command is successful when executed against api.github.com:

$ gh api --verbose /rate_limit
* Request at 2024-03-03 07:46:02.008636666 -0800 PST m=+0.035952823
* Request to https://api.github.com/rate_limit
> GET /rate_limit HTTP/1.1
> Host: api.github.com
> Accept: */*
> Authorization: token {redacted-auth-token}
> Content-Type: application/json; charset=utf-8
> Time-Zone: America/Los_Angeles
> User-Agent: GitHub CLI 2.44.1

< HTTP/2.0 200 OK
< Access-Control-Allow-Origin: *
< Access-Control-Expose-Headers: ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset
< Cache-Control: no-cache
< Content-Security-Policy: default-src 'none'
< Content-Type: application/json; charset=utf-8
< Date: Sun, 03 Mar 2024 15:46:02 GMT
< Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin
< Server: GitHub.com
< Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
< Vary: Accept-Encoding, Accept, X-Requested-With
< X-Accepted-Oauth-Scopes: 
< X-Content-Type-Options: nosniff
< X-Frame-Options: deny
< X-Github-Api-Version-Selected: 2022-11-28
< X-Github-Media-Type: github.v3; format=json
< X-Github-Request-Id: DA3A:2CFD4E:4BDDDD:6B4527:65E49B3A
< X-Oauth-Client-Id: 178c6fc778ccc68e1d6a
< X-Oauth-Scopes: admin:public_key, gist, read:org, repo
< X-Ratelimit-Limit: 5000
< X-Ratelimit-Remaining: 4992
< X-Ratelimit-Reset: 1709482284
< X-Ratelimit-Resource: core
< X-Ratelimit-Used: 8
< X-Xss-Protection: 0

{"jsonbody": "Redacted"}

How to reproduce ?

  1. Configure plugin against a GHE instance with rate limiting disabled.
  2. Attempt to publish a note, any note, it doesn't matter.
  3. Publish fails with the above console messages.

Minimal Reproducible Example

---
key: true
---

# Hello world!

Configuration

"github": {
    "branch": "main",
    "automaticallyMergePR": true,
    "dryRun": {
      "enable": false,
      "folderName": "github-publisher"
    },
    "tokenPath": "%configDir%/plugins/%pluginID%/env",
    "api": {
      "tiersForApi": "Enterprise",
      "hostname": "https://redacted.hostname.tld"
    },
    "workflow": {
      "commitMessage": "[PUBLISHER] Merge",
      "name": ""
    },
    "verifiedRepo": true
  },
  "upload": {
    "behavior": "fixed",
    "defaultName": "",
    "rootFolder": "",
    "yamlFolderKey": "",
    "frontmatterTitle": {
      "enable": false,
      "key": "title"
    },
    "replaceTitle": [],
    "replacePath": [],
    "autoclean": {
      "enable": false,
      "excluded": []
    },
    "folderNote": {
      "enable": false,
      "rename": "index.md",
      "addTitle": {
        "enable": false,
        "key": "title"
      }
    },
    "metadataExtractorPath": ""
  },
  "conversion": {
    "hardbreak": false,
    "dataview": true,
    "censorText": [],
    "tags": {
      "inline": false,
      "exclude": [],
      "fields": []
    },
    "links": {
      "internal": false,
      "unshared": false,
      "wiki": false,
      "slugify": "disable"
    }
  },
  "embed": {
    "attachments": true,
    "overrideAttachments": [],
    "keySendFile": [],
    "notes": false,
    "folder": "",
    "convertEmbedToLinks": "keep",
    "charConvert": "->"
  },
  "plugin": {
    "shareKey": "ghe",
    "excludedFolder": [],
    "copyLink": {
      "enable": false,
      "links": "",
      "removePart": [],
      "transform": {
        "toUri": true,
        "slugify": "lower",
        "applyRegex": []
      }
    },
    "setFrontmatterKey": "Set"
  }
}

Relevant log output

plugin:obsidian-mkdocs-publisher:21 [GitHub Publisher](qn.eval):
 Repository Tim-Peoples/project-status exists. Now testing the main branch.
plugin:obsidian-mkdocs-publisher:21 [GitHub Publisher](main):
 HttpError: Rate limiting is not enabled.
    at eval (plugin:obsidian-mkdocs-publisher:17:43928)

OS

No response

Anything else?

No response

Obsidian information

SYSTEM INFO:
	Obsidian version: v1.5.8
	Installer version: v1.5.8
	Operating system: #21~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Fri Feb  9 13:32:52 UTC 2 6.5.0-21-generic
	Login status: not logged in
	Insider build toggle: off
	Live preview: on
	Base theme: adapt to system
	Community theme: Mission Control v0.2.4
	Snippets enabled: 1
	Restricted mode: off
	Plugins installed: 12
	Plugins enabled: 9
		1: Hotkeys++ v0.2.7
		2: Tasks v6.0.0
		3: Custom File Explorer sorting v2.1.8
		4: Remotely Save v0.3.40
		5: Local REST API v2.1.1
		6: Dataview v0.5.64
		7: Hotkeys for templates v1.4.3
		8: Webpage HTML Export v1.8.0
		9: Github Publisher v7.0.2

RECOMMENDATIONS:
	Custom theme and snippets: for cosmetic issues, please first try updating your theme and disabling your snippets. If still not fixed, please try to make the issue happen in the Sandbox Vault or disable community theme and snippets.
	Community plugins: for bugs, please first try updating all your plugins to latest. If still not fixed, please try to make the issue happen in the Sandbox Vault or disable community plugins.
@tep tep added the 🐛 Bug Something isn't working label Mar 3, 2024
@Mara-Li
Copy link
Member

Mara-Li commented Mar 3, 2024

Thanks for the bug report. As I don't have any GitHub enterprise, it will be hard for me to fix it. I understand it's a uncaught error around the rate limit, so I will try to fix it in beta.

I will return to you when I tried one fix in beta. You should install the plugin with BRAT to test it.

@Mara-Li
Copy link
Member

Mara-Li commented Mar 3, 2024

Do you know which is the status / error code returned? So I can caught this specific error. I couldn't get any help in the documentation :/

@tep
Copy link
Author

tep commented Mar 3, 2024

GHE returns 404 with the following JSON body:

{
  "message": "Rate limiting is not enabled.",
  "documentation_url": "https://docs.github.com/[email protected]/rest/reference/rate-limit#get-rate-limit-status-for-the-authenticated-user"
}

@Mara-Li
Copy link
Member

Mara-Li commented Mar 3, 2024

Thank you. I released a beta update with an attempt to fix this error! The beta version is 7.0.3-0


BRAT

  • Install BRAT-42 using community plugin
  • Open command palette : BRAT: Plugins : Add a beta plugin for testing
  • Enter https://github.com/ObsidianPublisher/obsidian-github-publisher
  • Click on [ADD PLUGIN]
  • Wait for installation
  • Done!

@tep
Copy link
Author

tep commented Mar 3, 2024

Version 7.0.3-0 did not fix the issue so I cloned your repo and did a little debugging.

What I found is that this error instanceof RequestError condition in this situation is actually false (albeit, I can't explain why).

I fixed things but updating line 454 to be:

if settings.github.api.tiersForApi === GithubTiersVersion.entreprise && error.name === "HttpError" && error.status === 404 && error.response.data === "Rate limiting is not enabled." return 5000;

n.b. I put the enterprise test first so that short-circuiting will ignore the other conditions if GHE is not being used.

@Mara-Li
Copy link
Member

Mara-Li commented Mar 4, 2024

Thanks, will update the code :)

@Mara-Li
Copy link
Member

Mara-Li commented Mar 4, 2024

I released the last version in beta!

@tep
Copy link
Author

tep commented Mar 4, 2024

My apologies -- there was an error in my previous comment. This line should actually read:

   && (error as any).response.data.message === "Rate limiting is not enabled."
   //                              ^^^^^^^

i.e. data is an object with a message field containing the error string.

@tep
Copy link
Author

tep commented Mar 4, 2024

Looks like you switched up 2 of the identifiers on line 456; you have response.message.data but it should read response.data.message.

Here's the complete error object:

{
  "name": "HttpError",
  "status": 404,
  "response": {
    "url": "https://redacted.hostname.tld/api/v3/rate_limit",
    "status": 404,
    "headers": {
      "cache-control": "no-cache",
      "content-type": "application/json; charset=utf-8",
      "x-accepted-oauth-scopes": "", 
      "x-github-media-type": "github.v3; format=json",
      "x-github-request-id": "bbd23232-9b29-402e-bd1c-057acb0e9dd2",
      "x-oauth-scopes": "gist, read:org, repo"
    },  
    "data": {
      "message": "Rate limiting is not enabled.",
      "documentation_url": "https://docs.github.com/[email protected]/rest/reference/rate-limit#get-rate-limit-status-for-the-authenticated-user"
    }   
  },  
  "request": {
    "method": "GET",
    "url": "https://redacted.hostname.tld/api/v3/rate_limit",
    "headers": {
      "accept": "application/vnd.github.v3+json",
      "user-agent": "octokit-core.js/4.2.4 Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) obsidian/1.5.8 Chrome/120.0.6099.283 Electron/28.2.3 Safari/537.36",
      "authorization": "token [REDACTED]"
    },  
    "request": {}
  }
}

@Mara-Li
Copy link
Member

Mara-Li commented Mar 4, 2024

Argh, sorry.

@Mara-Li
Copy link
Member

Mara-Li commented Mar 4, 2024

Should be fixed with -4 version in beta

@tep
Copy link
Author

tep commented Mar 4, 2024

Looks good to me! Thank you.

@Mara-Li Mara-Li closed this as completed in 0e97ea5 Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants