Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F4094214
D2470.id.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D2470.id.diff
View Options
diff --git a/phabricator/read-token.py b/phabricator/read-token.py
new file mode 100755
--- /dev/null
+++ b/phabricator/read-token.py
@@ -0,0 +1,59 @@
+#!/usr/bin/env python3
+
+
+import json
+import os
+import sys
+
+
+# -------------------------------------------------------------
+# Parse Phabricator configuration
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+def get_phabricator_configuration_path():
+ candidates = [
+ os.environ["HOME"] + "/.arcrc",
+ "/usr/local/etc/arcrc",
+ "/etc/arcrc",
+ ]
+
+ for candidate in candidates:
+ if os.path.exists(candidate):
+ return candidate
+
+ raise FileNotFoundError("Can't find Arc configuration")
+
+
+def get_token(phabricator_url):
+ config_path = get_phabricator_configuration_path()
+
+ with open(config_path) as fd:
+ config = json.load(fd)
+
+ for instance, args in config.get("hosts", {}).items():
+ if phabricator_url in instance:
+ return args["token"]
+
+ raise RuntimeError(
+ f"{config_path} doesn't describe host {phabricator_url}")
+
+
+# -------------------------------------------------------------
+# Application entry point
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+
+def run(phabricator_url):
+ token = get_token(phabricator_url)
+ print(token)
+
+
+if __name__ == "__main__":
+ try:
+ phabricator_url_fragment = sys.argv[1]
+ except IndexError:
+ print("Usage:", sys.argv[0],
+ "<Phabricator instance URL>", file=sys.stderr)
+ sys.exit(2)
+
+ run(phabricator_url_fragment)
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Feb 8, 06:46 (5 h, 23 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2397381
Default Alt Text
D2470.id.diff (1 KB)
Attached To
Mode
D2470: Allow to read Phabricator token
Attached
Detach File
Event Timeline
Log In to Comment