Skip to content

Commit 52800c7

Browse files
completed redid the auth flow
1 parent e2ff3d0 commit 52800c7

File tree

8 files changed

+2466
-407
lines changed

8 files changed

+2466
-407
lines changed

Formula/r2sql-shell.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
class R2sqlShell < Formula
22
desc "Interactive shell for querying R2 Data Catalog with R2 SQL"
33
homepage "https://github.com/marcinthecloud/r2sql-shell"
4-
url "https://github.com/marcinthecloud/r2sql-shell/releases/download/1.0.0/r2sql-shell-macos"
5-
sha256 "326c722240c05460f0651e1e2746ac62bf8d1dbdd726eb790c10ee3b47884364" # Run: shasum -a 256 bin/r2sql-shell-macos
6-
version "1.0.0"
4+
url "https://github.com/marcinthecloud/r2sql-shell/releases/download/1.1.0/r2sql-shell-macos"
5+
sha256 "edac479a3acce97ac9045ee3830d77c553d567c0c04577d209d18392a8ae773a" # Run: shasum -a 256 bin/r2sql-shell-macos
6+
version "1.1.0"
77
license "MIT"
88

99
def install
@@ -13,7 +13,7 @@ def install
1313

1414
test do
1515
# Test that the binary runs and returns correct version
16-
assert_match "1.0.0", shell_output("#{bin}/r2sql-shell --version")
16+
assert_match "1.1.0", shell_output("#{bin}/r2sql-shell --version")
1717

1818
# Test that help works
1919
assert_match "Interactive shell", shell_output("#{bin}/r2sql-shell --help")

README.md

Lines changed: 90 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,46 @@ An interactive TUI (Text User Interface) for querying R2 Data Catalog using R2 S
3939

4040
## Configuration
4141

42-
Create a `.env` file in the project root with your Cloudflare credentials:
42+
### Authentication Options
43+
44+
r2sql-shell offers multiple ways to authenticate with Cloudflare, making it easy to get started:
45+
46+
#### Option 1: Interactive Setup (Recommended) 🚀
47+
48+
The easiest way to get started! Just run:
49+
50+
```bash
51+
r2sql-shell login
52+
```
53+
54+
This will:
55+
1. Ask for your Cloudflare Account ID
56+
2. Ask if you have an R2 API token, or help you create one
57+
3. Open your browser to Cloudflare's R2 API tokens page (if needed)
58+
4. Guide you to create a token with **Admin Read & Write** permissions
59+
5. Ask for your R2 bucket name
60+
6. Store everything securely in `~/.r2sql-shell/config.json` (file permissions: 0600)
61+
7. **Automatically start the shell!**
62+
63+
Your credentials are saved, so next time just run `r2sql-shell`
64+
65+
You can always override the bucket with: `r2sql-shell --bucket other-bucket`
66+
67+
You can check your authentication status anytime:
68+
69+
```bash
70+
r2sql-shell status
71+
```
72+
73+
To logout and remove all stored credentials:
74+
75+
```bash
76+
r2sql-shell logout
77+
```
78+
79+
#### Option 2: Environment Variables
80+
81+
Create a `.env` file in the project root:
4382

4483
```bash
4584
cp .env.example .env
@@ -53,15 +92,36 @@ R2_BUCKET_NAME=your_bucket_name_here
5392
CLOUDFLARE_API_TOKEN=your_api_token_here
5493
```
5594

56-
OR simply start `r2sql-shell` for the first time to set it up
95+
#### Option 3: Command-Line Arguments
96+
97+
Pass credentials directly when starting the shell:
98+
99+
```bash
100+
r2sql-shell --account-id YOUR_ID --bucket YOUR_BUCKET --token YOUR_TOKEN
101+
```
102+
103+
#### Option 4: Interactive Prompts
104+
105+
Simply start r2sql-shell without any configuration and you'll be prompted for your credentials interactively.
106+
107+
### Authentication Priority
108+
109+
r2sql-shell checks for credentials in this order:
110+
1. r2sql-shell stored config (`~/.r2sql-shell/config.json`)
111+
2. `CLOUDFLARE_API_TOKEN` environment variable
112+
3. `.env` file configuration
113+
4. Command-line arguments (`--token`)
114+
5. Interactive prompts
115+
116+
**Note:** The `--bucket` flag always overrides the stored bucket name, allowing you to easily switch between buckets.
57117

58118
### Getting Your Credentials
59119

60120
1. **Account ID**: Found in your Cloudflare dashboard URL or on the right side of the dashboard
61121
2. **Bucket Name**: The name of your R2 bucket with Data Catalog enabled
62-
3. **API Token**: Create one at https://dash.cloudflare.com/profile/api-tokens
63-
- Use the "Create Custom Token" option
64-
- Add the permissions listed above
122+
3. **R2 API Token**: Create one at https://dash.cloudflare.com/?to=/:account/r2/api-tokens
123+
- Select **Admin Read & Write** permissions
124+
- This gives access to R2 SQL and related services
65125

66126
## Installation
67127

@@ -103,59 +163,17 @@ brew install r2sql-shell
103163

104164
Now you can run `r2sql-shell` from anywhere!
105165

106-
### Download Pre-built Binary (Coming Soon)
107-
108-
Download the latest release for your platform from the [releases page](https://github.com/marcinthecloud/r2sql-shell/releases):
109-
- macOS (Intel/Apple Silicon)
110-
- Linux (x64)
111-
- Windows (x64)
112-
113-
## Quick Start
114-
115-
### Option 1: Interactive Setup (Easiest)
116-
117-
Just run the command and you'll be prompted for your credentials:
118-
119-
```bash
120-
r2sql-shell
121-
# or if running from source:
122-
npm start
123-
```
124-
125-
### Option 2: Using Command-Line Arguments
126-
127-
```bash
128-
r2sql-shell --account-id YOUR_ACCOUNT_ID --bucket YOUR_BUCKET --token YOUR_API_TOKEN
129-
```
130-
131-
### Option 3: Using Environment Variables
132-
133-
Create a `.env` file:
134-
135-
```bash
136-
cp .env.example .env
137-
```
138-
139-
Edit `.env` with your credentials:
140-
141-
```env
142-
CLOUDFLARE_ACCOUNT_ID=your_account_id_here
143-
R2_BUCKET_NAME=your_bucket_name_here
144-
CLOUDFLARE_API_TOKEN=your_api_token_here
145-
```
146-
147-
Then run:
148-
149-
```bash
150-
r2sql-shell
151-
```
152-
153166
## Usage
154167

155-
### Command-Line Options
168+
### Commands
156169

157170
```bash
158-
r2sql-shell [options]
171+
r2sql-shell [command] [options]
172+
173+
Commands:
174+
login Authenticate with Cloudflare using OAuth
175+
logout Remove stored authentication credentials
176+
status Check authentication status
159177

160178
Options:
161179
--account-id <id> Cloudflare Account ID
@@ -173,24 +191,34 @@ Options:
173191
### Starting the Shell
174192

175193
```bash
176-
# Start with interactive prompt for credentials
177-
r2sql-shell
194+
# Authenticate first (one-time setup)
195+
r2sql-shell login
178196

179-
# Start in TUI mode with credentials
180-
r2sql-shell --account-id YOUR_ID --bucket YOUR_BUCKET --token YOUR_TOKEN
197+
# Check authentication status
198+
r2sql-shell status
199+
200+
# Start the shell with stored credentials
201+
r2sql-shell --account-id YOUR_ID --bucket YOUR_BUCKET
181202

182203
# Execute a query on startup
183-
r2sql-shell -e "SELECT * FROM my_namespace.my_table LIMIT 10"
204+
r2sql-shell --account-id YOUR_ID --bucket YOUR_BUCKET \
205+
-e "SELECT * FROM my_namespace.my_table LIMIT 10"
184206

185207
# Enable query history logging
186-
r2sql-shell --history
208+
r2sql-shell --account-id YOUR_ID --bucket YOUR_BUCKET --history
187209

188210
# Start in simple REPL mode
189-
r2sql-shell --simple
211+
r2sql-shell --account-id YOUR_ID --bucket YOUR_BUCKET --simple
190212

191213
# Combine options
192-
r2sql-shell --account-id YOUR_ID --bucket YOUR_BUCKET --token YOUR_TOKEN \
214+
r2sql-shell --account-id YOUR_ID --bucket YOUR_BUCKET \
193215
-e "SELECT * FROM default.logs LIMIT 5" --history
216+
217+
# Or use full credentials if not using OAuth
218+
r2sql-shell --account-id YOUR_ID --bucket YOUR_BUCKET --token YOUR_TOKEN
219+
220+
# Logout when done
221+
r2sql-shell logout
194222
```
195223

196224
### First Time Setup

0 commit comments

Comments
 (0)