use serde::{Deserialize, Serialize};
use std::collections::HashMap;
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ConductorUser {
pub id: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub email: Option<String>,
#[serde(default)]
pub roles: Vec<Role>,
#[serde(default)]
pub groups: Vec<Group>,
#[serde(default)]
pub application_user: bool,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct UpsertUserRequest {
pub name: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub email: Option<String>,
#[serde(default)]
pub roles: Vec<String>,
#[serde(default)]
pub groups: Vec<String>,
}
impl UpsertUserRequest {
pub fn new(name: impl Into<String>) -> Self {
Self {
name: name.into(),
..Default::default()
}
}
#[must_use]
pub fn with_email(mut self, email: impl Into<String>) -> Self {
self.email = Some(email.into());
self
}
#[must_use]
pub fn with_roles(mut self, roles: Vec<String>) -> Self {
self.roles = roles;
self
}
#[must_use]
pub fn with_groups(mut self, groups: Vec<String>) -> Self {
self.groups = groups;
self
}
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Group {
pub id: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
#[serde(default)]
pub roles: Vec<Role>,
#[serde(default)]
pub default_access: HashMap<String, Vec<String>>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct UpsertGroupRequest {
pub name: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
#[serde(default)]
pub roles: Vec<String>,
#[serde(default)]
pub default_access: HashMap<String, Vec<String>>,
}
impl UpsertGroupRequest {
pub fn new(name: impl Into<String>) -> Self {
Self {
name: name.into(),
..Default::default()
}
}
#[must_use]
pub fn with_description(mut self, description: impl Into<String>) -> Self {
self.description = Some(description.into());
self
}
#[must_use]
pub fn with_roles(mut self, roles: Vec<String>) -> Self {
self.roles = roles;
self
}
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Role {
pub name: String,
#[serde(default)]
pub permissions: Vec<Permission>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Permission {
pub name: String,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ConductorApplication {
pub id: String,
pub name: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub create_time: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub created_by: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub update_time: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub updated_by: Option<String>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CreateOrUpdateApplicationRequest {
pub name: String,
}
impl CreateOrUpdateApplicationRequest {
pub fn new(name: impl Into<String>) -> Self {
Self { name: name.into() }
}
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AccessKey {
pub id: String,
pub status: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub create_time: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub created_by: Option<String>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CreatedAccessKey {
pub id: String,
pub secret: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SubjectRef {
#[serde(rename = "type")]
pub subject_type: SubjectType,
pub id: String,
}
impl SubjectRef {
pub fn user(id: impl Into<String>) -> Self {
Self {
subject_type: SubjectType::User,
id: id.into(),
}
}
pub fn group(id: impl Into<String>) -> Self {
Self {
subject_type: SubjectType::Group,
id: id.into(),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum SubjectType {
User,
Group,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TargetRef {
#[serde(rename = "type")]
pub target_type: TargetType,
pub id: String,
}
impl TargetRef {
pub fn workflow(name: impl Into<String>) -> Self {
Self {
target_type: TargetType::WorkflowDef,
id: name.into(),
}
}
pub fn task(name: impl Into<String>) -> Self {
Self {
target_type: TargetType::TaskDef,
id: name.into(),
}
}
pub fn secret(name: impl Into<String>) -> Self {
Self {
target_type: TargetType::Secret,
id: name.into(),
}
}
pub fn domain(name: impl Into<String>) -> Self {
Self {
target_type: TargetType::Domain,
id: name.into(),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum TargetType {
WorkflowDef,
TaskDef,
Secret,
Domain,
Tag,
Integration,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum AccessType {
Create,
Read,
Update,
Delete,
Execute,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct GrantedPermission {
pub target: Option<TargetRef>,
#[serde(default)]
pub access: Vec<AccessType>,
#[serde(skip_serializing_if = "Option::is_none")]
pub tag: Option<String>,
}