Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ rust/src/
nodejs/
mod.rs — hosting nodejs command group
client.rs — Node.js Hosting REST client
scopes.rs — OAuth scope constants
scopes.rs — centralized OAuth scope registry (all commands draw from this)
webhook/mod.rs — webhook commands
config/mod.rs — godaddy.toml read/write
auth.rs — auth module registration
Expand Down
1 change: 1 addition & 0 deletions rust/src/environments/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub const DEFAULT_ENV: &str = "prod";
pub const DEFAULT_OAUTH_SCOPES: &[&str] = &[
crate::scopes::APP_REGISTRY_READ,
crate::scopes::DOMAINS_READ,
crate::scopes::OFFLINE_ACCESS,
];
pub const REDIRECT_URI: &str = "http://localhost:7443/callback";
pub const APP_ID: &str = "gddy";
Expand Down
9 changes: 5 additions & 4 deletions rust/src/hosting/nodejs/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
pub mod client;
pub mod scopes;

use cli_engine::{
CliCoreError, CommandContext, CommandResult, CommandSpec, GroupSpec, NextAction,
Expand All @@ -12,9 +11,11 @@ use crate::{
output_schema::output_schema,
};

use self::scopes::{
APPS_CREATE, APPS_DELETE, APPS_READ, APPS_UPDATE, CODE_WRITE, DEPLOY_EXECUTE, LOGS_READ,
SECRETS_WRITE,
use crate::scopes::{
HOSTING_APPS_CREATE as APPS_CREATE, HOSTING_APPS_DELETE as APPS_DELETE,
HOSTING_APPS_READ as APPS_READ, HOSTING_APPS_UPDATE as APPS_UPDATE,
HOSTING_CODE_WRITE as CODE_WRITE, HOSTING_DEPLOY_EXECUTE as DEPLOY_EXECUTE,
HOSTING_LOGS_READ as LOGS_READ, HOSTING_SECRETS_WRITE as SECRETS_WRITE,
};

output_schema!(HostingAppSummary {
Expand Down
10 changes: 0 additions & 10 deletions rust/src/hosting/nodejs/scopes.rs

This file was deleted.

62 changes: 52 additions & 10 deletions rust/src/scopes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,23 @@
//!
//! So: **every scope the CLI uses is declared here, once**, and commands draw
//! from these constants rather than spelling out string literals. The [`ALL`]
//! slice is derived from the same declarations, so it is always the complete,
//! authoritative list of scopes the OAuth client must be registered for — a
//! single place to diff against the client's configuration.
//! slice is derived from the same declarations, so it is always the complete
//! list of `resource:action` *permission* scopes the OAuth client must be
//! registered for — a single place to diff against the client's configuration.
//!
//! `ALL` does NOT cover every scope requiring client registration, though:
//! directive scopes like [`OFFLINE_ACCESS`] aren't `resource:action` grants, so
//! they're declared outside [`declare_scopes!`]/`ALL` but still need the same
//! server-side registration. When syncing the OAuth client's configuration,
//! diff against `ALL` *plus* every such standalone constant, not `ALL` alone.
//!
//! # Adding a scope (READ THIS)
//!
//! 1. Add a constant to the [`declare_scopes!`] block below. It is automatically
//! included in [`ALL`] — you cannot add a scope constant without registering
//! it in the list.
//! 1. Add a constant to the [`declare_scopes!`] block below (or, for a directive
//! scope that isn't a `resource:action` permission, declare it standalone
//! like [`OFFLINE_ACCESS`]). Constants in `declare_scopes!` are automatically
//! included in [`ALL`] — you cannot add one there without registering it in
//! the list.
//! 2. Reference the new constant from the command via `.with_scopes(&[scopes::…])`.
//! 3. **Register the same scope on the CLI's OAuth client**, or it will be
//! ungrantable at runtime.
Expand All @@ -39,10 +47,15 @@ macro_rules! declare_scopes {
($( $(#[$doc:meta])* $name:ident => $value:literal ),+ $(,)?) => {
$( $(#[$doc])* pub const $name: &str = $value; )+

/// Every OAuth scope the CLI may request, and therefore the exact set its
/// OAuth client must be registered for. Auto-derived from the constants
/// declared in [`declare_scopes!`] — keep the client's registration in sync
/// with this list.
/// Every `resource:action` permission scope the CLI may request. Auto-derived
/// from the constants declared in [`declare_scopes!`] — keep the client's
/// registration in sync with this list.
///
/// NOT the complete set of scopes requiring OAuth client registration:
/// [`OFFLINE_ACCESS`] is a directive scope (not a `resource:action` permission)
/// and is deliberately excluded, but still must be registered on the client
/// server-side. Diff the client's configuration against `ALL` *plus*
/// [`OFFLINE_ACCESS`], not `ALL` alone.
Comment thread
jpage-godaddy marked this conversation as resolved.
Resolved
///
/// Not referenced by production code (the individual constants are what
/// commands use); it exists as the authoritative registry to diff against
Expand All @@ -52,6 +65,18 @@ macro_rules! declare_scopes {
};
}

/// OIDC directive scope requesting a `refresh_token` alongside the access
/// token. Requested at login by default (see
/// [`crate::environments::DEFAULT_OAUTH_SCOPES`]).
///
/// Deliberately declared outside [`declare_scopes!`]/[`ALL`]: unlike the
/// scopes below, it isn't a `resource:action` permission grant, so it fails
/// the `resource:action` shape the module tests enforce for `ALL`. It still
/// must be registered on the CLI's OAuth client server-side, or the
/// authorization server will refuse or silently drop it just like any other
Comment thread
jpage-godaddy marked this conversation as resolved.
Resolved
/// unregistered scope.
pub const OFFLINE_ACCESS: &str = "offline_access";

// DON'T FORGET! If you add a scope here, you must also register it on the CLI's OAuth client.
declare_scopes! {
/// Read the caller's registered applications. Requested at login by default
Expand All @@ -75,6 +100,23 @@ declare_scopes! {
DOMAINS_CREATE => "domains.domain:create",
/// Replace a domain's nameservers (`domain nameservers set`).
DOMAINS_NAMESERVER_UPDATE => "domains.nameserver:update",

/// Read Node.js Hosting apps (`hosting nodejs app list/get`).
HOSTING_APPS_READ => "hosting.paas.apps:read",
/// Create a Node.js Hosting app (`hosting nodejs app create`).
HOSTING_APPS_CREATE => "hosting.paas.apps:create",
/// Update a Node.js Hosting app (`hosting nodejs app update`).
HOSTING_APPS_UPDATE => "hosting.paas.apps:update",
/// Delete a Node.js Hosting app (`hosting nodejs app delete`).
HOSTING_APPS_DELETE => "hosting.paas.apps:delete",
/// Upload code to a Node.js Hosting app (`hosting nodejs app deploy`/`upload`).
HOSTING_CODE_WRITE => "hosting.paas.code:write",
/// Trigger a Node.js Hosting deploy (`hosting nodejs app deploy`).
HOSTING_DEPLOY_EXECUTE => "hosting.paas.deploy:execute",
/// Write Node.js Hosting app secrets (`hosting nodejs secret set/delete`).
HOSTING_SECRETS_WRITE => "hosting.paas.secrets:write",
/// Read Node.js Hosting app logs (`hosting nodejs app logs`).
HOSTING_LOGS_READ => "hosting.paas.logs:read",
}

#[cfg(test)]
Expand Down