#![allow(clippy::all, unused_imports, dead_code)]
//! Auto-generated API actors for Firebase
//!
//! Service: Firebase (firebase)
//! Google's mobile and web application development platform
//!
//! Required env var: FIREBASE_API_KEY (OAuth2 access token)
//!
//! Generated by api-schema-gen codegen — do not edit manually.
use crate::{Actor, ActorBehavior, ClientBuilderExt, Message, Port};
use anyhow::{Error, Result};
use reflow_actor::{message::EncodableValue, ActorContext};
use reflow_actor_macro::actor;
use serde_json::{json, Value};
use std::collections::HashMap;
use std::time::Duration;
const BASE_URL: &str = "https://firebase.googleapis.com/v1";
const ENV_KEY: &str = "FIREBASE_API_KEY";
/// Apply authentication to the request builder.
fn apply_auth(
config: &reflow_actor::ActorConfig,
mut builder: reqwest::RequestBuilder,
) -> Result<reqwest::RequestBuilder> {
let credential = config
.get_config_or_env(ENV_KEY)
.ok_or_else(|| anyhow::anyhow!("Missing env var: {}", ENV_KEY))?;
builder = builder.header("Authorization", format!("Bearer {}", credential));
Ok(builder)
}
/// create document via Firebase API
///
/// Method: POST /projects/{projectId}/databases/{databaseId}/documents/{collectionId}
#[actor(
FirebaseCreateDocumentActor,
inports::<100>(projectId, databaseId, collectionId),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn firebase_create_document(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/projects/{projectId}/databases/{databaseId}/documents/{collectionId}".to_string();
if let Some(val) = inputs.get("projectId") {
endpoint = endpoint.replace("{{projectId}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("databaseId") {
endpoint = endpoint.replace("{{databaseId}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("collectionId") {
endpoint = endpoint.replace("{{collectionId}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("POST /projects/{{projectId}}/databases/{{databaseId}}/documents/{{collectionId}} failed: {}", e).into()));
}
}
Ok(output)
}
/// read document via Firebase API
///
/// Method: GET /projects/{projectId}/databases/{databaseId}/documents/{documentPath}
#[actor(
FirebaseReadDocumentActor,
inports::<100>(projectId, databaseId, documentPath),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn firebase_read_document(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint =
"/projects/{projectId}/databases/{databaseId}/documents/{documentPath}".to_string();
if let Some(val) = inputs.get("projectId") {
endpoint = endpoint.replace("{{projectId}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("databaseId") {
endpoint = endpoint.replace("{{databaseId}}", &super::message_to_str(val));
}
if let Some(val) = inputs.get("documentPath") {
endpoint = endpoint.replace("{{documentPath}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert("error".to_string(), Message::Error(format!("GET /projects/{{projectId}}/databases/{{databaseId}}/documents/{{documentPath}} failed: {}", e).into()));
}
}
Ok(output)
}
/// Lists each [Google Cloud Platform (GCP) `Project`] (https://cloud.google.com/resource-manager/reference/rest/v1/projects) that can have Firebase resources added to it. A Project will only be listed if: - The caller has sufficient [Google IAM](https://cloud.google.com/iam) permissions to call AddFirebase. - The Project is not already a FirebaseProject. - The Project is not in an Organization which has policies that prevent Firebase resources from being added.
///
/// Method: GET /v1beta1/availableProjects
#[actor(
FirebaseListAvailableProjectsActor,
inports::<100>(pageSize, pageToken),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn firebase_list_available_projects(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/v1beta1/availableProjects".to_string();
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("pageSize") {
query_pairs.push(("pageSize", super::message_to_str(val)));
}
if let Some(val) = inputs.get("pageToken") {
query_pairs.push(("pageToken", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert(
"error".to_string(),
Message::Error(format!("GET /v1beta1/availableProjects failed: {}", e).into()),
);
}
}
Ok(output)
}
/// Lists each FirebaseProject accessible to the caller. The elements are returned in no particular order, but they will be a consistent view of the Projects when additional requests are made with a `pageToken`. This method is eventually consistent with Project mutations, which means newly provisioned Projects and recent modifications to existing Projects might not be reflected in the set of Projects. The list will include only ACTIVE Projects. Use GetFirebaseProject for consistent reads as well as for additional Project details.
///
/// Method: GET /v1beta1/projects
#[actor(
FirebaseListProjectsActor,
inports::<100>(pageSize, pageToken, showDeleted),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn firebase_list_projects(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let endpoint = "/v1beta1/projects".to_string();
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("pageSize") {
query_pairs.push(("pageSize", super::message_to_str(val)));
}
if let Some(val) = inputs.get("pageToken") {
query_pairs.push(("pageToken", super::message_to_str(val)));
}
if let Some(val) = inputs.get("showDeleted") {
query_pairs.push(("showDeleted", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert(
"error".to_string(),
Message::Error(format!("GET /v1beta1/projects failed: {}", e).into()),
);
}
}
Ok(output)
}
/// Updates the attributes of the specified WebApp.
///
/// Method: PATCH /v1beta1/{name}
#[actor(
FirebaseUpdateProjectsActor,
inports::<100>(name, updateMask, projectId, appUrls, state, webId, displayName, appId, apiKeyId, etag, expireTime),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn firebase_update_projects(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/v1beta1/{name}".to_string();
if let Some(val) = inputs.get("name") {
endpoint = endpoint.replace("{{name}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.patch(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut query_pairs: Vec<(&str, String)> = Vec::new();
if let Some(val) = inputs.get("updateMask") {
query_pairs.push(("updateMask", super::message_to_str(val)));
}
if !query_pairs.is_empty() {
builder = builder.query(&query_pairs);
}
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("projectId") {
body.insert("projectId".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("appUrls") {
body.insert("appUrls".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("state") {
body.insert("state".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("name") {
body.insert("name".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("webId") {
body.insert("webId".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("displayName") {
body.insert("displayName".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("appId") {
body.insert("appId".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("apiKeyId") {
body.insert("apiKeyId".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("etag") {
body.insert("etag".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("expireTime") {
body.insert("expireTime".to_string(), val.clone().into());
}
if !body.is_empty() {
builder = builder.json(&serde_json::Value::Object(body));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert(
"error".to_string(),
Message::Error(format!("PATCH /v1beta1/{{name}} failed: {}", e).into()),
);
}
}
Ok(output)
}
/// Removes a ShaCertificate from the specified AndroidApp.
///
/// Method: DELETE /v1beta1/{name}
#[actor(
FirebaseDeleteProjectsActor,
inports::<100>(name),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn firebase_delete_projects(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/v1beta1/{name}".to_string();
if let Some(val) = inputs.get("name") {
endpoint = endpoint.replace("{{name}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.delete(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert(
"error".to_string(),
Message::Error(format!("DELETE /v1beta1/{{name}} failed: {}", e).into()),
);
}
}
Ok(output)
}
/// Gets the configuration artifact associated with the specified WebApp.
///
/// Method: GET /v1beta1/{name}
#[actor(
FirebaseReadProjectsActor,
inports::<100>(name),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn firebase_read_projects(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/v1beta1/{name}".to_string();
if let Some(val) = inputs.get("name") {
endpoint = endpoint.replace("{{name}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.get(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert(
"error".to_string(),
Message::Error(format!("GET /v1beta1/{{name}} failed: {}", e).into()),
);
}
}
Ok(output)
}
/// Removes the specified WebApp from the FirebaseProject.
///
/// Method: POST /v1beta1/{name}:remove
#[actor(
FirebaseCreateProjectsActor,
inports::<100>(name, etag, allowMissing, immediate, validateOnly),
outports::<50>(response, error),
state(MemoryState)
)]
pub async fn firebase_create_projects(
context: ActorContext,
) -> Result<HashMap<String, Message>, Error> {
let inputs = context.get_payload();
let actor_config = context.get_config();
let mut endpoint = "/v1beta1/{name}:remove".to_string();
if let Some(val) = inputs.get("name") {
endpoint = endpoint.replace("{{name}}", &super::message_to_str(val));
}
let url = format!("{}{}", BASE_URL.trim_end_matches('/'), endpoint);
let client = reqwest::Client::builder()
.timeout_compat(Duration::from_secs(30))
.build()?;
let mut builder = client.post(&url);
builder = builder.header("Content-Type", "application/json");
builder = apply_auth(actor_config, builder)?;
let mut body = serde_json::Map::new();
if let Some(val) = inputs.get("etag") {
body.insert("etag".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("allowMissing") {
body.insert("allowMissing".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("immediate") {
body.insert("immediate".to_string(), val.clone().into());
}
if let Some(val) = inputs.get("validateOnly") {
body.insert("validateOnly".to_string(), val.clone().into());
}
if !body.is_empty() {
builder = builder.json(&serde_json::Value::Object(body));
}
let mut output = HashMap::new();
match builder.send().await {
Ok(resp) => {
let status = resp.status().as_u16();
let headers: HashMap<String, String> = resp
.headers()
.iter()
.filter_map(|(k, v)| v.to_str().ok().map(|val| (k.to_string(), val.to_string())))
.collect();
let body_text = resp.text().await.unwrap_or_default();
let body_value: Value =
serde_json::from_str(&body_text).unwrap_or(Value::String(body_text));
output.insert(
"response".to_string(),
Message::object(EncodableValue::from(json!({
"status": status,
"headers": headers,
"body": body_value,
}))),
);
}
Err(e) => {
output.insert(
"error".to_string(),
Message::Error(format!("POST /v1beta1/{{name}}:remove failed: {}", e).into()),
);
}
}
Ok(output)
}