]> git.puffer.fish Git - matthieu/nova.git/commitdiff
Merge branch 'main' into nats-structs-discord-gateway
authorn1c00o <34602094+n1c00o@users.noreply.github.com>
Sat, 16 Oct 2021 20:26:09 +0000 (22:26 +0200)
committerGitHub <noreply@github.com>
Sat, 16 Oct 2021 20:26:09 +0000 (22:26 +0200)
1  2 
Cargo.lock
common/rust/Cargo.toml
common/rust/src/config.rs
common/rust/src/lib.rs
common/rust/src/nats.rs
common/rust/src/payloads.rs

diff --cc Cargo.lock
index e6a2de2b60b7f6a5a7e24d119ae992eda6240bf2,c25dbfe7d33d43a05cf2f4a6281a6c45521e9aa3..e8b87c7e95fe17e8b9c7ff203162fb1b8d907f77
@@@ -222,8 -210,9 +211,10 @@@ dependencies = 
   "nats",
   "pretty_env_logger",
   "prometheus",
+  "redis",
   "serde 1.0.130",
 + "serde_repr",
+  "testcontainers",
   "tokio",
  ]
  
index 453f7b89bbd17fd5952bd0c28f72176da8a83edc,d54eea93cd54401937b76b880850faa53ed3066a..234f1b1a5143269006d8eb8823aa516075b029ea
@@@ -11,6 -10,10 +11,11 @@@ serde_repr = "0.1
  config = "0.11"
  hyper = { version = "0.14", features = ["full"] }
  tokio = { version = "1", features = ["full"] }
- prometheus = "0.12.0"
- nats = "0.15.2"
 +enumflags2 = { version = "0.7.1", features = ["serde"] }
+ prometheus = { version = "0.12.0", features = ["process"] }
+ nats = "0.15.2"
+ testcontainers = "0.12.0"
+ [dependencies.redis]
+ version = "*"
+ features = ["cluster", "connection-manager", "tokio-comp"]
index bd123502b832138b3ee2651ab906b26be5f02002,e4dbade18d2cf219f2b663eced9b9d163fa1c308..327f6f8ae9de9d8510b31bdf206718d5edd3465f
@@@ -17,7 -22,11 +22,12 @@@ impl<T> Settings<T
  where
      T: Deserialize<'static> + std::default::Default + Clone,
  {
++
+     /// Initializes a new configuration like the other components of nova
+     /// And starts the prometheus metrics server if needed.
      pub fn new(service_name: &str) -> Result<Settings<T>, ConfigError> {
+         pretty_env_logger::init();
          let mut default = Config::default();
          // this file my be shared with all the components
          default.merge(File::with_name("config/default"))?;
@@@ -32,8 -42,7 +43,9 @@@
          let mut config: Settings<T> = default.clone().try_into().unwrap();
  
          //  try to load the config
 -        config.config = default.get::<T>(&service_name).unwrap();
 +        config.config = default.get::<T>(service_name).unwrap();
-         pretty_env_logger::init();
++        // todo(MatthieuCodder): the following line was not present in the conflict
++        //         pretty_env_logger::init();
  
          // start the monitoring system if needed
          crate::monitoring::start_monitoring(&config.monitoring);
index a021e97f6c2cf20b3b7ea22db0b4d69263e3cba0,f4e27fc6c8d4423908ece04f94a4491455f36275..5418d0a0b5b6f4cb13f0bef01a014fcfedcd37fd
@@@ -1,8 -1,16 +1,18 @@@
- /// This crate contains shared code in all the rust projects
- /// It contains utilities such as monitoring, logging and more.
+ /// This crate is all the utilities shared by the nova rust projects
+ /// It includes loging, config and protocols.
  pub mod config;
 +pub mod discord_models;
 +pub mod error;
  pub mod monitoring;
  pub mod nats;
  pub mod payloads;
 -pub use ::redis as redis_crate;
+ pub mod error;
+ pub mod redis;
+ pub use log as log;
+ pub use serde as serde;
+ pub use ::config as config_crate;
+ pub use prometheus as prometheus;
+ pub use ::nats as nats_crate;
+ pub use testcontainers as testcontainers;
++pub use ::redis as redis_crate;
index 1a4d349c74fd2e5aa0785665f6c37bcea33447e2,c61aa4c789f4d764aab9144d79d3c26dd359cab5..a001dc94e35303dfd6cec810d8ac639bdd21e7eb
@@@ -2,30 -2,29 +2,31 @@@ use nats::{Connection, Options}
  use serde::Deserialize;
  
  #[derive(Clone, Debug, Deserialize)]
- struct NatsConfigurationClientCert {
-     cert: String,
-     key: String,
pub struct NatsConfigurationClientCert {
+     pub cert: String,
+     pub key: String,
  }
++
  #[derive(Clone, Debug, Deserialize)]
- struct NatsConfigurationTls {
-     mtu: Option<usize>,
pub struct NatsConfigurationTls {
+     pub mtu: Option<usize>,
  }
  
  #[derive(Clone, Debug, Deserialize)]
  pub struct NatsConfiguration {
-     client_cert: Option<NatsConfigurationClientCert>,
-     root_cert: Option<Vec<String>>,
-     jetstream_api_prefix: Option<String>,
-     max_reconnects: Option<usize>,
-     reconnect_buffer_size: Option<usize>,
-     tls: Option<NatsConfigurationTls>,
-     client_name: Option<String>,
-     tls_required: Option<bool>,
-     host: String,
+     pub client_cert: Option<NatsConfigurationClientCert>,
+     pub root_cert: Option<Vec<String>>,
+     pub jetstream_api_prefix: Option<String>,
+     pub max_reconnects: Option<usize>,
+     pub reconnect_buffer_size: Option<usize>,
+     pub tls: Option<NatsConfigurationTls>,
+     pub client_name: Option<String>,
+     pub tls_required: Option<bool>,
+     pub host: String,
  }
  
- ///
 +// todo: Prefer From since it automatically gives a free Into implementation
+ // Allows the configuration to directly create a nats connection
  impl Into<Connection> for NatsConfiguration {
      fn into(self) -> Connection {
          let mut options = Options::new();
index 4f70b451e7c7a97491019e7e5eff5bb799b65b5c,c97ac1db5cb9414d42f2fadf0abbc2d0f8303cc7..d8d06f2697c33be34c9af099de1907339dc73878
  use serde::{Deserialize, Serialize};
+ use std::fmt::Debug;
  
 -/// Data structure sent to the cache component
 -/// by the gateway & webhook.
 -#[derive(Serialize, Deserialize, Debug)]
 -#[serde(bound(deserialize = "T: Deserialize<'de> + Debug"))]
 -pub struct CachePayload<T> {
 +use crate::discord_models::{
 +    application::Application,
 +    channel::{Channel, Message, ThreadMember},
 +    emoji::Emoji,
 +    gateway::PresenceUpdate,
 +    guild::{Guild, GuildMember, Integration},
 +    invite::InviteTargetTypes,
 +    permissions::Role,
 +    slash_commands::{ApplicationCommand, Interaction},
 +    stage_instance::StageInstance,
 +    user::User,
 +    voice::VoiceState,
 +};
  
 -    #[serde(rename = "tr")]
 +/// Payload send to the nova cache queues
 +#[derive(Serialize, Deserialize, Debug, Clone)]
 +// #[serde(bound(deserialize = "T: Deserialize<'de> + std::default::Default + Clone"))]
 +pub struct CachePayload {
      pub tracing: Tracing,
 -
 -    #[serde(rename = "d")]
 -    pub data: T,
 -
 -    #[serde(rename = "o")]
 -    pub operation: String,
 +    pub data: CacheData,
  }
  
- #[derive(Serialize, Deserialize, Debug, Clone)]
+ #[derive(Serialize, Deserialize, Debug)]
  pub struct Tracing {
      pub node_id: String,
 -    pub span: Option<String>
 +    pub span: Option<String>,
 +}
 +
 +#[derive(Serialize, Deserialize, Debug, Clone)]
 +pub enum CacheData {
 +    Ready {
 +        version: u8,
 +        user: User,
 +        guilds: Vec<Guild>,
 +        session_id: String,
 +        shard: Option<Vec<i64>>,
 +        application: Application,
 +    },
 +    ApplicationCommandCreate {
 +        guild_id: Option<String>,
 +        command: ApplicationCommand,
 +    },
 +    ApplicationCommandUpdate {
 +        guild_id: Option<String>,
 +        command: ApplicationCommand,
 +    },
 +    ApplicationCommandDelete {
 +        guild_id: Option<String>,
 +        command: ApplicationCommand,
 +    },
 +    ChannelCreate {
 +        channel: Channel,
 +    },
 +    ChannelUpdate {
 +        channel: Channel,
 +    },
 +    ChannelDelete {
 +        channel: Channel,
 +    },
 +    ThreadCreate {
 +        channel: Channel,
 +    },
 +    ThreadUpdate {
 +        channel: Channel,
 +    },
 +    ThreadDelete {
 +        channel: Channel,
 +    },
 +    ThreadListSync {
 +        guild_id: String,
 +        channel_ids: Option<Vec<String>>,
 +        threads: Vec<Channel>,
 +        members: Vec<ThreadMember>,
 +    },
 +    ThreadMemberUpdate {
 +        member: ThreadMember,
 +    },
 +    ThreadMembersUpdate {
 +        id: String,
 +        guild_id: String,
 +        member_count: i64,
 +        added_members: Option<Vec<ThreadMember>>,
 +        removed_member_ids: Option<Vec<String>>,
 +    },
 +    ChannelPinsUpdate {
 +        guild_id: Option<String>,
 +        channel_id: String,
 +        last_pin_timestamp: Option<String>,
 +    },
 +    GuildCreate {
 +        guild: Guild,
 +    },
 +    GuildUpdate {
 +        guild: Guild,
 +    },
 +    GuildDelete {
 +        guild: Guild,
 +    },
 +    GuildBanAdd {
 +        guild_id: String,
 +        user: User,
 +    },
 +    GuildBanRemove {
 +        guild_id: String,
 +        user: User,
 +    },
 +    GuildEmojisUpdate {
 +        guild_id: String,
 +        emojis: Vec<Emoji>,
 +    },
 +    GuildIntegrationsUpdate {
 +        guild_id: String,
 +    },
 +    GuildMemberAdd {
 +        guild_id: String,
 +        member: GuildMember,
 +    },
 +    GuildMemberRemove {
 +        guild_id: String,
 +        user: User,
 +    },
 +    GuildMemberUpdate {
 +        guild_id: String,
 +        roles: Vec<String>,
 +        user: User,
 +        nick: Option<String>,
 +        joined_at: Option<String>,
 +        premium_since: Option<String>,
 +        deaf: Option<bool>,
 +        mute: Option<bool>,
 +        pending: Option<bool>,
 +    },
 +    GuildMembersChunk {
 +        guild_id: String,
 +        members: Vec<GuildMember>,
 +        chunk_index: i64,
 +        chunk_count: i64,
 +        not_found: Option<Vec<String>>,
 +        presences: Option<Vec<PresenceUpdate>>,
 +        nonce: Option<String>,
 +    },
 +    GuildRoleCreate {
 +        guild_id: String,
 +        role: Role,
 +    },
 +    GuildRoleUpdate {
 +        guild_id: String,
 +        role: Role,
 +    },
 +    GuildRoleDelete {
 +        guild_id: String,
 +        role_id: String,
 +    },
 +    IntegrationCreate {
 +        guild_id: String,
 +        integration: Integration,
 +    },
 +    IntegrationUpdate {
 +        guild_id: String,
 +        integration: Integration,
 +    },
 +    IntegrationDelete {
 +        id: String,
 +        guild_id: String,
 +        application_id: Option<String>,
 +    },
 +    InviteCreate {
 +        channel_id: String,
 +        code: String,
 +        created_at: String,
 +        guild_id: Option<String>,
 +        inviter: Option<User>,
 +        max_age: i64,
 +        max_uses: i64,
 +        target_type: Option<InviteTargetTypes>,
 +        target_user: Option<User>,
 +        target_application: Option<Application>,
 +        temporary: bool,
 +        uses: i64,
 +    },
 +    InviteDelete {
 +        channel_id: String,
 +        guild_id: Option<String>,
 +        code: String,
 +    },
 +    InteractionCreate {
 +        // boxed to avoid a large difference size between variants (https://rust-lang.github.io/rust-clippy/master/index.html#large_enum_variant)
 +        interaction: Box<Interaction>,
 +    },
 +    MessageCreate {
 +        message: Message,
 +    },
 +    MessageUpdate {
 +        message: Message,
 +    },
 +    MessageDelete {
 +        id: String,
 +        channel_id: String,
 +        guild_id: Option<String>,
 +    },
 +    MessageDeleteBulk {
 +        ids: Vec<String>,
 +        channel_id: String,
 +        guild_id: Option<String>,
 +    },
 +    MessageReactionAdd {
 +        user_id: String,
 +        channel_id: String,
 +        message_id: String,
 +        guild_id: Option<String>,
 +        member: Option<GuildMember>,
 +        emoji: Emoji,
 +    },
 +    MessageReactionRemove {
 +        user_id: String,
 +        channel_id: String,
 +        message_id: String,
 +        guild_id: Option<String>,
 +        emoji: Emoji,
 +    },
 +    MessageReactionRemoveAll {
 +        channel_id: String,
 +        message_id: String,
 +        guild_id: Option<String>,
 +    },
 +    MessageReactionRemoveEmoji {
 +        channel_id: String,
 +        message_id: String,
 +        guild_id: Option<String>,
 +        emoji: Emoji,
 +    },
 +    PresenceUpdate {
 +        presence: PresenceUpdate,
 +    },
 +    TypingStart {
 +        channel_id: String,
 +        guild_id: Option<String>,
 +        user_id: String,
 +        timestamp: i64,
 +        member: Option<GuildMember>,
 +    },
 +    UserUpdate {
 +        user: User,
 +    },
 +    VoiceStateUpdate {
 +        state: VoiceState,
 +    },
 +    VoiceServerUpdate {
 +        token: String,
 +        guild_id: String,
 +        endpoint: Option<String>,
 +    },
 +    WebhookUpdate {
 +        guild_id: String,
 +        channel_id: String,
 +    },
 +    StageInstanceCreate {
 +        instance: StageInstance,
 +    },
 +    StageInstanceUpdate {
 +        instance: StageInstance,
 +    },
 +    StageInstanceDelete {
 +        instance: StageInstance,
 +    },
  }