Skip to content
This repository was archived by the owner on Sep 19, 2025. It is now read-only.

Commit 4154aff

Browse files
committed
Add CLI docs. Update READMEs.
1 parent ace3089 commit 4154aff

File tree

6 files changed

+215
-20
lines changed

6 files changed

+215
-20
lines changed

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
## ⚠️ Security Warning
2+
3+
**Keep your API credentials secure!**
4+
5+
- The `<API_KEY>` and `<API_SECRET>` are sensitive credentials that grant access to your application’s PulseBeam resources. **Do not expose these credentials** in:
6+
- Public repositories.
7+
- Client-side code.
8+
- Shared or unencrypted environments.
9+
10+
- Treat tokens generated by this CLI as sensitive data. Tokens should only be shared with trusted clients.
11+
12+
### Recommended Practices:
13+
1. **Environment Variables:** Store your API credentials securely in environment variables instead of hardcoding them in your codebase.
14+
```bash
15+
export PULSEBEAM_API_KEY="your_api_key"
16+
export PULSEBEAM_API_SECRET="your_api_secret"
17+
```
18+
19+
2. **Access Controls:** Regularly rotate API credentials and limit their scope to only necessary permissions.
20+
21+
3. **Auditing:** Monitor usage of your credentials and investigate any unauthorized activity.
22+
23+
## 💳 Billing and Token Usage
24+
25+
**Be aware:** Generating and using tokens can incur billing charges. Each token enables interactions with PulseBeam's infrastructure, which may contribute to your account’s usage costs.
26+
27+
### Billing Best Practices:
28+
1. **Understand Your Plan:** Familiarize yourself with the details of your billing plan. For more information, visit our [Billing Page](https://pulsebeam.dev/billing).
29+
2. **Monitor Usage:** Keep track of token usage to avoid unexpected charges. Utilize PulseBeam’s dashboards and APIs for real-time monitoring.
30+
3. **Token Expiration:** Set appropriate `duration` values for tokens to limit unnecessary usage. Tokens with a longer duration may result in increased billing if misused.
31+
4. **Audit Token Distribution:** Ensure tokens are only distributed to trusted clients to avoid misuse that could drive up costs.
32+
33+
### ⚠️ Important Billing Warning
34+
35+
- Tokens allow access to PulseBeam's infrastructure and **may result in charges depending on your usage**.
36+
- Misuse or unauthorized distribution of tokens can lead to **unexpected billing costs**.
37+
- **Ensure you monitor your account's activity regularly** and revoke tokens that are no longer needed.
38+
39+
For detailed information on billing and usage policies, visit our [Billing Page](https://pulsebeam.dev/billing).

examples/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
target

examples/Cargo.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[package]
2+
name = "pulsebeam-cli"
3+
version = "0.0.1"
4+
authors = ["Lukas Herman [email protected]"]
5+
edition = "2021"
6+
7+
[[bin]]
8+
name = "pulsebeam-cli"
9+
path = "pulsebeam.rs"
10+
11+
[dependencies]
12+
anyhow = "1.0"
13+
clap = { version = "4", features = ["derive"] }
14+
pulsebeam-core = { path = ".." }

examples/README.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# PulseBeam CLI
2+
3+
Generates secure tokens for client-side applications. For example, clients using the `@pulsebeam/peer` WebRTC Peer-to-Peer Communication SDK.
4+
5+
These tokens enable secure interaction with PulseBeam signaling servers for peer-to-peer connections.
6+
7+
For a server-side token-generation alternative and more documentation, see [`@pulsebeam/server`](https://jsr.io/@pulsebeam/server).
8+
9+
## Quick Start
10+
11+
```bash
12+
cargo build
13+
./target/debug/pulsebeam-cli create-token \
14+
--peer-id "peer-1" \
15+
--group-id "test" \
16+
--allow-policy "test:peer-*" \
17+
--api-key "your_api_key" \
18+
--api-secret "your_api_secret"
19+
20+
./target/debug/pulsebeam-cli create-token \
21+
--peer-id "peer-2" \
22+
--group-id "test" \
23+
--allow-policy "test:peer-*" \
24+
--api-key "your_api_key" \
25+
--api-secret "your_api_secret"
26+
```
27+
28+
Now you should have two tokens. You can use the tokens to connect the two peers together using PulseBeam. They are valid for the next hour.
29+
30+
## Installation
31+
32+
1. Make sure you have Rust and Cargo installed: https://rustup.rs/
33+
2. Clone this repository.
34+
3. Navigate to the project directory in your terminal.
35+
4. Build the project: `cargo build`
36+
37+
## Usage
38+
39+
```bash
40+
./target/debug/pulsebeam-cli create-token --help
41+
```
42+
| Parameter | Description |
43+
|---------------|-------------------------------------------------------------------------------------------------------|
44+
| `peer-id` | ID for the peer this token is intended to be used by. [More info](https://jsr.io/@pulsebeam/server/doc/~/PeerClaims#constructor_0) |
45+
| `group-id` | ID for the group the peer is in, scoped to your application. [More info](https://jsr.io/@pulsebeam/server/doc/~/PeerClaims#constructor_0) |
46+
| `duration` | Duration in seconds TTL before token expiration. |
47+
| `allow-policy`| Defines which peer(s) this peer is allowed to connect to. Default: `\"*:*\"` (connect to any other peer)[^1]. [More info](https://jsr.io/@pulsebeam/server/doc/~/PeerPolicy) |
48+
| `create-token`| Generates a token[^2][^3] based on the provided inputs/defaults. |
49+
50+
[^1]: Even with the `\"*:*\"` allow-policy, peers can only connect to other peers within the scope of your `<API_KEY>`.
51+
52+
[^2]: Provide the CLI-generated token to your client's to allow them to talk to PulseBeam signaling servers and make connections with each other.
53+
54+
[^3]: See billing section below.
55+
56+
```bash
57+
./target/debug/pulsebeam-cli --help
58+
```
59+
60+
* Set `api-key` and `api-secret` with your credentials obtained from PulseBeam (https://pulsebeam.dev).
61+
* Warning: be sure to protect your <API_KEY> and <API_SECRET>. See information below
62+
63+
## ⚠️ Security Warning
64+
65+
**Keep your API credentials secure!**
66+
67+
- The `<API_KEY>` and `<API_SECRET>` are sensitive credentials that grant access to your application’s PulseBeam resources. **Do not expose these credentials** in:
68+
- Public repositories.
69+
- Client-side code.
70+
- Shared or unencrypted environments.
71+
72+
- Treat tokens generated by this CLI as sensitive data. Tokens should only be shared with trusted clients.
73+
74+
### Recommended Practices:
75+
1. **Environment Variables:** Store your API credentials securely in environment variables instead of hardcoding them in your codebase.
76+
```bash
77+
export PULSEBEAM_API_KEY="your_api_key"
78+
export PULSEBEAM_API_SECRET="your_api_secret"
79+
```
80+
81+
2. **Access Controls:** Regularly rotate API credentials and limit their scope to only necessary permissions.
82+
83+
3. **Auditing:** Monitor usage of your credentials and investigate any unauthorized activity.
84+
85+
## 💳 Billing and Token Usage
86+
87+
**Be aware:** Generating and using tokens can incur billing charges. Each token enables interactions with PulseBeam's infrastructure, which may contribute to your account’s usage costs.
88+
89+
### Billing Best Practices:
90+
1. **Understand Your Plan:** Familiarize yourself with the details of your billing plan. For more information, visit our [Billing Page](https://pulsebeam.dev/billing).
91+
2. **Monitor Usage:** Keep track of token usage to avoid unexpected charges. Utilize PulseBeam’s dashboards and APIs for real-time monitoring.
92+
3. **Token Expiration:** Set appropriate `duration` values for tokens to limit unnecessary usage. Tokens with a longer duration may result in increased billing if misused.
93+
4. **Audit Token Distribution:** Ensure tokens are only distributed to trusted clients to avoid misuse that could drive up costs.
94+
95+
### ⚠️ Important Billing Warning
96+
97+
- Tokens allow access to PulseBeam's infrastructure and **may result in charges depending on your usage**.
98+
- Misuse or unauthorized distribution of tokens can lead to **unexpected billing costs**.
99+
- **Ensure you monitor your account's activity regularly** and revoke tokens that are no longer needed.
100+
101+
For detailed information on billing and usage policies, visit our [Billing Page](https://pulsebeam.dev/billing).

examples/pulsebeam.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,24 @@ struct Cli {
88
#[command(subcommand)]
99
command: Commands,
1010

11-
/// Application ID (optional, can also be set with the PULSEBEAM_APP_ID environment variable)
11+
/// API KEY (required, can also be set with the PULSEBEAM_API_KEY environment variable)
1212
#[arg(long)]
13-
app_id: Option<String>,
13+
api_key: Option<String>,
1414

15-
/// Application secret (optional, can also be set with the PULSEBEAM_APP_SECRET environment variable)
15+
/// API SECRET (required, can also be set with the PULSEBEAM_API_SECRET environment variable)
1616
#[arg(long)]
17-
app_secret: Option<String>,
17+
api_secret: Option<String>,
1818
}
1919

2020
#[derive(Subcommand)]
2121
enum Commands {
2222
/// Create a new token
2323
CreateToken {
24-
/// Peer ID for the token
24+
/// (required) Peer ID for the token
2525
#[arg(long)]
2626
peer_id: String,
2727

28-
/// Group ID for the token
28+
/// (required) Group ID for the token
2929
#[arg(long)]
3030
group_id: String,
3131

@@ -34,27 +34,27 @@ enum Commands {
3434
duration: u32,
3535

3636
/// Allow connections from group ID and peer ID (format: "group_id:peer_id")
37-
#[arg(long, value_name = "GROUP_ID:PEER_ID")]
38-
allow_policy: Option<String>,
37+
#[arg(long, value_name = "GROUP_ID:PEER_ID", default_value = "*:*")]
38+
allow_policy: String,
3939
},
4040
}
4141

4242
fn main() -> anyhow::Result<()> {
4343
let cli = Cli::parse();
4444

45-
// Get app_id and app_secret, prioritizing CLI arguments over environment variables
46-
let app_id = cli
47-
.app_id
48-
.or_else(|| std::env::var("PULSEBEAM_APP_ID").ok())
45+
// Get api_key and api_secret, prioritizing CLI arguments over environment variables
46+
let api_key = cli
47+
.api_key
48+
.or_else(|| std::env::var("PULSEBEAM_API_KEY").ok())
4949
.context(
50-
"PULSEBEAM_APP_ID must be provided either as a CLI argument or an environment variable",
50+
"PULSEBEAM_API_KEY must be provided either as a CLI argument or an environment variable",
5151
)?;
52-
let app_secret = cli
53-
.app_secret
54-
.or_else(|| std::env::var("PULSEBEAM_APP_SECRET").ok())
55-
.context("PULSEBEAM_APP_SECRET must be provided either as a CLI argument or an environment variable")?;
52+
let api_secret = cli
53+
.api_secret
54+
.or_else(|| std::env::var("PULSEBEAM_API_SECRET").ok())
55+
.context("PULSEBEAM_API_SECRET must be provided either as a CLI argument or an environment variable")?;
5656

57-
let app = App::new(&app_id, &app_secret);
57+
let app = App::new(&api_key, &api_secret);
5858

5959
match &cli.command {
6060
Commands::CreateToken {
@@ -63,7 +63,7 @@ fn main() -> anyhow::Result<()> {
6363
duration,
6464
allow_policy,
6565
} => {
66-
let mut claims = PeerClaims::new(group_id, peer_id);
66+
let mut claims: PeerClaims = PeerClaims::new(group_id, peer_id);
6767

6868
// Helper function to parse "group_id:peer_id" strings
6969
let parse_peer_policy = |s: &String| -> Option<PeerPolicy> {
@@ -78,7 +78,7 @@ fn main() -> anyhow::Result<()> {
7878
}
7979
};
8080

81-
claims.allow_policy = allow_policy.as_ref().and_then(parse_peer_policy);
81+
claims.allow_policy = parse_peer_policy(allow_policy);
8282

8383
let token = app.create_token(&claims, *duration)?;
8484
println!("{}", token);

js/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,43 @@ For a deeper understanding of JWT (JSON web token) concepts, consult the RFC: ht
106106
### WebRTC Resources
107107

108108
For a deeper understanding of WebRTC concepts, consult the official WebRTC documentation: https://developer.mozilla.org/en-US/docs/Web/API/WebRTC_API
109+
110+
## ⚠️ Security Warning
111+
112+
**Keep your API credentials secure!**
113+
114+
- The `<API_KEY>` and `<API_SECRET>` are sensitive credentials that grant access to your application’s PulseBeam resources. **Do not expose these credentials** in:
115+
- Public repositories.
116+
- Client-side code.
117+
- Shared or unencrypted environments.
118+
119+
- Treat tokens generated by this CLI as sensitive data. Tokens should only be shared with trusted clients.
120+
121+
### Recommended Practices:
122+
1. **Environment Variables:** Store your API credentials securely in environment variables instead of hardcoding them in your codebase.
123+
```bash
124+
export PULSEBEAM_API_KEY="your_api_key"
125+
export PULSEBEAM_API_SECRET="your_api_secret"
126+
```
127+
128+
2. **Access Controls:** Regularly rotate API credentials and limit their scope to only necessary permissions.
129+
130+
3. **Auditing:** Monitor usage of your credentials and investigate any unauthorized activity.
131+
132+
## 💳 Billing and Token Usage
133+
134+
**Be aware:** Generating and using tokens can incur billing charges. Each token enables interactions with PulseBeam's infrastructure, which may contribute to your account’s usage costs.
135+
136+
### Billing Best Practices:
137+
1. **Understand Your Plan:** Familiarize yourself with the details of your billing plan. For more information, visit our [Billing Page](https://pulsebeam.dev/billing).
138+
2. **Monitor Usage:** Keep track of token usage to avoid unexpected charges. Utilize PulseBeam’s dashboards and APIs for real-time monitoring.
139+
3. **Token Expiration:** Set appropriate `duration` values for tokens to limit unnecessary usage. Tokens with a longer duration may result in increased billing if misused.
140+
4. **Audit Token Distribution:** Ensure tokens are only distributed to trusted clients to avoid misuse that could drive up costs.
141+
142+
### ⚠️ Important Billing Warning
143+
144+
- Tokens allow access to PulseBeam's infrastructure and **may result in charges depending on your usage**.
145+
- Misuse or unauthorized distribution of tokens can lead to **unexpected billing costs**.
146+
- **Ensure you monitor your account's activity regularly** and revoke tokens that are no longer needed.
147+
148+
For detailed information on billing and usage policies, visit our [Billing Page](https://pulsebeam.dev/billing).

0 commit comments

Comments
 (0)