Enveloppe / obsidian-enveloppe

Enveloppe helps you to publish your notes on a GitHub repository from your Obsidian Vault, for free!
https://enveloppe.github.io/
Apache License 2.0
613 stars 38 forks source link

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

Closed tep closed 6 months ago

tep commented 6 months ago

Issue validation

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/enterprise-server@3.10/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.
Mara-Li commented 6 months ago

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 commented 6 months ago

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 commented 6 months ago

GHE returns 404 with the following JSON body:

{
  "message": "Rate limiting is not enabled.",
  "documentation_url": "https://docs.github.com/enterprise-server@3.10/rest/reference/rate-limit#get-rate-limit-status-for-the-authenticated-user"
}
Mara-Li commented 6 months ago

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


BRAT

tep commented 6 months ago

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 commented 6 months ago

Thanks, will update the code :)

Mara-Li commented 6 months ago

I released the last version in beta!

tep commented 6 months ago

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 commented 6 months ago

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/enterprise-server@3.10/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 commented 6 months ago

Argh, sorry.

Mara-Li commented 6 months ago

Should be fixed with -4 version in beta

tep commented 6 months ago

Looks good to me! Thank you.