-
Notifications
You must be signed in to change notification settings - Fork 824
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
registry: Move queries from RegistryClient methods functions in api m…
…odule
- Loading branch information
Showing
3 changed files
with
72 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use anyhow::Context; | ||
|
||
use crate::RegistryClient; | ||
|
||
use crate::graphql::mutations; | ||
use crate::types::{PublishDeployAppOutput, PublishDeployAppRawVars}; | ||
|
||
/// Generate a Deploy token for for the given Deploy app version id. | ||
pub async fn generate_deploy_token( | ||
client: &RegistryClient, | ||
app_version_id: String, | ||
) -> Result<String, anyhow::Error> { | ||
let vars = mutations::generate_deploy_token::Variables { app_version_id }; | ||
let res = client | ||
.execute::<mutations::GenerateDeployToken>(vars) | ||
.await?; | ||
let token = res | ||
.generate_deploy_token | ||
.context("Query did not return a token")? | ||
.token; | ||
|
||
Ok(token) | ||
} | ||
|
||
/// Publish a Deploy app. | ||
/// | ||
/// Takes a raw, unvalidated deployment config. | ||
// TODO: Add a variant of this query that takes a typed DeployV1 config. | ||
pub async fn publish_deploy_app_raw( | ||
client: &RegistryClient, | ||
data: PublishDeployAppRawVars, | ||
) -> Result<PublishDeployAppOutput, anyhow::Error> { | ||
let vars2 = mutations::publish_deploy_app::Variables { | ||
name: data.name, | ||
owner: data.namespace, | ||
config: serde_json::to_string(&data.config)?, | ||
}; | ||
|
||
let version = client | ||
.execute::<mutations::PublishDeployApp>(vars2) | ||
.await? | ||
.publish_deploy_app | ||
.context("Query did not return data")? | ||
.deploy_app_version; | ||
let app = version.app.context("Query did not return expected data")?; | ||
|
||
Ok(PublishDeployAppOutput { | ||
app_id: app.id, | ||
app_name: app.name, | ||
version_id: version.id, | ||
version_name: version.version, | ||
owner_name: app.owner.global_name, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters