-
Notifications
You must be signed in to change notification settings - Fork 0
Static ActionConfig #291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Static ActionConfig #291
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a798688
ref: renamed ActionConfiguration into ServiceConfiguration
raphael-goetz 9409f75
feat: added action configurations to service configuration
raphael-goetz 953ffb5
Update Rust crate tokio to v1.51.1
renovate[bot] e76d45f
feat: returning empty action configuration instead of panicing
raphael-goetz 49507a4
Update Rust crate tucana to 0.0.68
renovate[bot] 02054d7
feat: adjusted service config after rebase
raphael-goetz 5b7be6f
feat: config will expect json as value
raphael-goetz 6f725b6
feat: adjusted config to accept json values
raphael-goetz f56f7f4
Merge branch `main` into #264-action-config
raphael-goetz 211b8dc
drop: removed overleft file after merge
raphael-goetz 96b248e
Potential fix for pull request finding
raphael-goetz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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,30 @@ | ||
| { | ||
| "actions": [ | ||
| { | ||
| "token": "token", | ||
| "identifier": "discord", | ||
| "configs": [ | ||
| { | ||
| "project_id": 1, | ||
| "configs": [ | ||
| { | ||
| "identifier": "send_message", | ||
| "value": { | ||
| "channel_id": "123456789012345678", | ||
| "content": "Hello from bot" | ||
| } | ||
| }, | ||
| { | ||
| "identifier": "assign_role", | ||
| "value": { | ||
| "guild_id": "987654321098765432", | ||
| "user_id": "111111111111111111", | ||
| "role_id": "222222222222222222" | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } |
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| pub mod action; | ||
| pub mod service; | ||
| pub mod config; | ||
| pub mod state; |
This file contains hidden or 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,157 @@ | ||
| use serde::{Deserialize, Serialize}; | ||
| use serde_json::from_str; | ||
| use std::{fs::File, io::Read}; | ||
| use tucana::shared::{ActionConfigurations, helper::value::from_json_value}; | ||
|
|
||
| #[derive(Serialize, Deserialize, Clone)] | ||
| struct SerializableActionConfiguration { | ||
| identifier: String, | ||
| value: serde_json::Value, | ||
| } | ||
|
|
||
| type SerializeableActionConfiguration = SerializableActionConfiguration; | ||
|
|
||
| #[derive(Serialize, Deserialize, Clone)] | ||
| struct SerializableActionProjectConfiguration { | ||
| project_id: i64, | ||
| #[serde(default)] | ||
| configs: Vec<SerializableActionConfiguration>, | ||
| } | ||
|
|
||
| type SerializeableActionProjectConfiguration = SerializableActionProjectConfiguration; | ||
|
|
||
| #[derive(Serialize, Deserialize, Clone)] | ||
| pub struct SerializableActionServiceConfiguration { | ||
| token: String, | ||
| identifier: String, | ||
| #[serde(default)] | ||
| configs: Vec<SerializableActionProjectConfiguration>, | ||
| } | ||
|
|
||
| pub type SerializeableActionServiceConfiguration = SerializableActionServiceConfiguration; | ||
|
|
||
| #[derive(Serialize, Deserialize, Clone, Default)] | ||
| pub struct SerializableServiceConfiguration { | ||
| #[serde(default)] | ||
| actions: Vec<SerializableActionServiceConfiguration>, | ||
| } | ||
|
|
||
| pub type SerializeableServiceConfiguration = SerializableServiceConfiguration; | ||
|
|
||
| #[derive(Serialize, Deserialize, Clone)] | ||
| pub struct ActionServiceConfiguration { | ||
| token: String, | ||
| service_name: String, | ||
| config: Vec<ActionConfigurations>, | ||
| } | ||
|
|
||
| #[derive(Serialize, Deserialize, Clone, Default)] | ||
| pub struct ServiceConfiguration { | ||
| actions: Vec<ActionServiceConfiguration>, | ||
| } | ||
|
|
||
| impl From<SerializableActionConfiguration> for tucana::shared::ActionConfiguration { | ||
| fn from(value: SerializableActionConfiguration) -> Self { | ||
| Self { | ||
| identifier: value.identifier, | ||
| value: Some(from_json_value(value.value)), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl From<SerializeableActionProjectConfiguration> for tucana::shared::ActionProjectConfiguration { | ||
| fn from(value: SerializeableActionProjectConfiguration) -> Self { | ||
| Self { | ||
| project_id: value.project_id, | ||
| action_configurations: value.configs.into_iter().map(Into::into).collect(), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl From<SerializeableActionServiceConfiguration> for ActionServiceConfiguration { | ||
| fn from(value: SerializeableActionServiceConfiguration) -> Self { | ||
| let action_identifier = value.identifier.clone(); | ||
|
|
||
| Self { | ||
| token: value.token, | ||
| service_name: value.identifier, | ||
| config: vec![ActionConfigurations { | ||
| action_identifier, | ||
| action_configurations: value.configs.into_iter().map(Into::into).collect(), | ||
| }], | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl From<SerializeableServiceConfiguration> for ServiceConfiguration { | ||
| fn from(value: SerializeableServiceConfiguration) -> Self { | ||
| Self { | ||
| actions: value.actions.into_iter().map(Into::into).collect(), | ||
| } | ||
| } | ||
| } | ||
| impl ServiceConfiguration { | ||
| pub fn has_action(&self, token: &String, action_identifier: &String) -> bool { | ||
| match self | ||
| .actions | ||
| .iter() | ||
| .find(|x| &x.token == token && &x.service_name == action_identifier) | ||
| { | ||
| Some(_) => true, | ||
| None => false, | ||
| } | ||
| } | ||
|
|
||
| pub fn get_action_configuration( | ||
| &self, | ||
| action_identifier: &String, | ||
| ) -> Vec<ActionConfigurations> { | ||
| match self | ||
| .actions | ||
| .iter() | ||
| .find(|x| &x.service_name == action_identifier) | ||
| { | ||
| Some(a) => a.config.clone(), | ||
| None => vec![], | ||
| } | ||
| } | ||
|
|
||
| pub fn from_path(path: &String) -> Self { | ||
| let mut data = String::new(); | ||
|
|
||
| let mut file = match File::open(path) { | ||
| Ok(file) => file, | ||
| Err(error) => { | ||
| log::warn!( | ||
| "Couldn't open service configuration file, Reason: {}. Starting with empty service configuration", | ||
| error | ||
| ); | ||
| return ServiceConfiguration::default(); | ||
| } | ||
| }; | ||
|
|
||
| match file.read_to_string(&mut data) { | ||
| Ok(_) => { | ||
| log::debug!("Successfully loaded action configuration file"); | ||
| } | ||
| Err(error) => { | ||
| log::warn!( | ||
| "Couldn't read service configuration file, Reason: {}. Starting with empty service configuration", | ||
| error | ||
| ); | ||
| return ServiceConfiguration::default(); | ||
| } | ||
| } | ||
|
|
||
| match from_str::<SerializeableServiceConfiguration>(&data) { | ||
| Ok(conf) => return conf.into(), | ||
| Err(error) => { | ||
| log::warn!( | ||
| "Couldn't parse service configuration file, Reason: {}. Starting with empty service configuration", | ||
| error | ||
| ); | ||
| return ServiceConfiguration::default(); | ||
| } | ||
| }; | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.