mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-04 01:18:34 +00:00
read secrets file
This commit is contained in:
1 parent
5e270d5c69
commit
a0d9bdb0d5
2 files changed
+13
-10
No files matched your search
+6
-5
@@ -5,6 +5,7 @@ use crate::util::anyhow_result::AnyhowResult;
|
||||
use twitch_api2::TwitchClient;
|
||||
use twitch_api2::helix::channels::GetChannelInformationRequest;
|
||||
use twitch_oauth2::{AppAccessToken, Scope, TwitchToken, tokens::errors::AppAccessTokenError, ClientId, ClientSecret};
|
||||
use crate::twitch::secrets::TwitchSecrets;
|
||||
|
||||
pub mod twitch;
|
||||
pub mod util;
|
||||
@@ -27,11 +28,10 @@ fn main() -> AnyhowResult<()> {
|
||||
|
||||
#[tokio::main]
|
||||
async fn run() -> AnyhowResult<()> {
|
||||
let client_id = "".to_string();
|
||||
let client_secret = "".to_string();
|
||||
let secrets = TwitchSecrets::from_file("secrets.toml")?;
|
||||
|
||||
let client_id = ClientId::new(client_id);
|
||||
let client_secret = ClientSecret::new(client_secret);
|
||||
let client_id = ClientId::new(&secrets.app_client_id);
|
||||
let client_secret = ClientSecret::new(&secrets.app_client_secret);
|
||||
|
||||
let client: TwitchClient<reqwest::Client> = TwitchClient::default();
|
||||
let token = AppAccessToken::get_app_access_token(
|
||||
@@ -42,7 +42,8 @@ async fn run() -> AnyhowResult<()> {
|
||||
).await?;
|
||||
|
||||
let req = GetChannelInformationRequest::builder()
|
||||
.broadcaster_id("27620241")
|
||||
//.broadcaster_id("27620241")
|
||||
.broadcaster_id("650154491")
|
||||
.build();
|
||||
|
||||
println!(
|
||||
|
||||
@@ -2,13 +2,12 @@ use crate::util::anyhow_result::AnyhowResult;
|
||||
|
||||
// TODO: Not sure I need all of these. The less I need to keep, the better.
|
||||
// Oauth delegation in particular seems not necessary.
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, serde::Deserialize)]
|
||||
pub struct TwitchSecrets {
|
||||
pub username: String,
|
||||
pub stream_key: String,
|
||||
pub app_client_id: String,
|
||||
pub app_client_secret: String,
|
||||
pub oauth_access_token: String,
|
||||
}
|
||||
|
||||
impl TwitchSecrets {
|
||||
@@ -17,14 +16,12 @@ impl TwitchSecrets {
|
||||
stream_key: &str,
|
||||
app_client_id: &str,
|
||||
app_client_secret: &str,
|
||||
oauth_access_token: &str
|
||||
) -> Self {
|
||||
Self {
|
||||
username: username.to_string(),
|
||||
stream_key: stream_key.to_string(),
|
||||
app_client_id: app_client_id.to_string(),
|
||||
app_client_secret: app_client_secret.to_string(),
|
||||
oauth_access_token: oauth_access_token.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,8 +31,13 @@ impl TwitchSecrets {
|
||||
&easyenv::get_env_string_required("TWITCH_STREAM_KEY")?,
|
||||
&easyenv::get_env_string_required("TWITCH_APP_CLIENT_ID")?,
|
||||
&easyenv::get_env_string_required("TWITCH_APP_CLIENT_SECRET")?,
|
||||
&easyenv::get_env_string_required("TWITCH_OAUTH_ACCESS_TOKEN")?,
|
||||
))
|
||||
}
|
||||
|
||||
pub fn from_file(filename: &str) -> AnyhowResult<Self> {
|
||||
let contents = std::fs::read_to_string(filename)?;
|
||||
let secrets = toml::from_str(&contents)?;
|
||||
Ok(secrets)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user