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
58 changes: 54 additions & 4 deletions rust/src/application/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ use serde_json::{Value, json};
const GRAPHQL_PATH: &str = "/v1/apps/app-registry-subgraph";
const USER_AGENT: &str = concat!("godaddy-cli/", env!("CARGO_PKG_VERSION"));

/// App Registry `ApplicationStatus` enum values (see app-registry-api GraphQL schema).
///
/// The `applications` query defaults to ACTIVE-only when `status` is omitted, so
/// callers that want every app must pass an explicit `status.in` containing these.
pub const APPLICATION_STATUSES: &[&str] =
&["ACTIVE", "ARCHIVED", "BLOCKED", "INACTIVE", "VERIFYING"];

/// Builds a reqwest Client with the standard GoDaddy CLI User-Agent.
pub fn make_http_client() -> Client {
Client::builder()
Expand Down Expand Up @@ -132,11 +139,18 @@ impl ApplicationClient {
Ok(payload["data"].clone())
}

/// Lists applications across every App Registry status.
///
/// Always sends an explicit `status.in` of [`APPLICATION_STATUSES`]. Omitting
/// the GraphQL `status` argument is *not* equivalent: the API defaults to
/// ACTIVE-only.
pub async fn list_applications(&self) -> Result<Value, ClientError> {
let data = self.query(json!({
"query": "query ApplicationsList { applications { edges { node { id label name description status url proxyUrl } } } }"
}))
.await?;
let data = self
.query(json!({
"query": "query ApplicationsList($status: ApplicationStatusFilter) { applications(status: $status) { edges { node { id label name description status url proxyUrl } } } }",
"variables": { "status": { "in": APPLICATION_STATUSES } }
}))
.await?;
let nodes: Vec<Value> = data["applications"]["edges"]
.as_array()
.map(|edges| {
Expand Down Expand Up @@ -410,6 +424,42 @@ mod tests {
assert!(err.to_string().contains("definitely-not-a-real-env-xyz"));
}

#[tokio::test]
async fn list_applications_sends_all_app_registry_statuses() {
let server = MockServer::start_async().await;
let mock = server
.mock_async(|when, then| {
when.method(POST)
.path("/v1/apps/app-registry-subgraph")
.header("authorization", "Bearer test-token")
.is_true(|req| {
let body = req.body_string();
body.contains("ApplicationsList")
&& body.contains(r#""in":["ACTIVE","ARCHIVED","BLOCKED","INACTIVE","VERIFYING"]"#)
});
then.status(200).json_body(json!({
"data": {
"applications": {
"edges": [
{ "node": { "id": "a1", "name": "active-app", "status": "ACTIVE" } },
{ "node": { "id": "a2", "name": "inactive-app", "status": "INACTIVE" } }
]
}
}
}));
})
.await;

let data = ApplicationClient::new(server.base_url(), "test-token")
.list_applications()
.await
.expect("list applications");

mock.assert_async().await;
assert_eq!(data.as_array().expect("array").len(), 2);
assert_eq!(data[1]["status"], "INACTIVE");
}

#[tokio::test]
async fn activate_release_posts_mutation_with_ids() {
let server = MockServer::start_async().await;
Expand Down
14 changes: 12 additions & 2 deletions rust/src/application/commands/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ pub(super) fn command() -> RuntimeCommandSpec {
CommandSpec::new("list", "List all applications")
.with_long(
"List all GoDaddy developer-platform applications visible to \
the current account. Use `gddy platform app info --name <name>` \
to fetch full details for a single application.",
the current account, across every App Registry status. Use \

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't "all" already imply it's across all statuses?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"all" isn’t a valid status — the enum is only ACTIVE | ARCHIVED | BLOCKED | INACTIVE | VERIFYING.

Omitting status also isn’t “all”: the API defaults to ACTIVE-only.

The CLI has to send status.in with every enum value, which is why the help text calls that out.

`gddy platform app info --name <name>` to fetch full details \
for a single application.",
)
.with_system("applications")
.with_tier(Tier::Read)
Expand Down Expand Up @@ -49,6 +50,7 @@ mod tests {
use cli_engine::{Cli, CliConfig, PaginationConfig, Stage};

use super::command;
use crate::application::client::APPLICATION_STATUSES;

#[test]
fn command_opts_into_pagination_with_no_default_and_a_max_limit() {
Expand All @@ -61,6 +63,14 @@ mod tests {
);
}

#[test]
fn application_statuses_match_app_registry_enum() {
assert_eq!(
APPLICATION_STATUSES,
["ACTIVE", "ARCHIVED", "BLOCKED", "INACTIVE", "VERIFYING"]
);
}

/// API commands must stay fail-closed: `platform app list` calls the backend,
/// so it must require authentication. Built with **no auth provider
/// registered**, the engine's default `AuthRequirement::Required` must reject
Expand Down
Loading