Make GH auth query static
This commit is contained in:
parent
8c3f870321
commit
1690585bd7
@ -4,7 +4,10 @@ extern crate actix_web;
|
|||||||
extern crate lazy_static;
|
extern crate lazy_static;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate serde_derive;
|
extern crate serde_derive;
|
||||||
|
#[macro_use]
|
||||||
|
extern crate structopt;
|
||||||
|
|
||||||
|
mod config;
|
||||||
mod data;
|
mod data;
|
||||||
mod error;
|
mod error;
|
||||||
mod service;
|
mod service;
|
||||||
@ -14,7 +17,7 @@ use crate::{
|
|||||||
data::FilePath,
|
data::FilePath,
|
||||||
error::Result,
|
error::Result,
|
||||||
service::{Bitbucket, GitLab, Github, Service},
|
service::{Bitbucket, GitLab, Github, Service},
|
||||||
statics::FAVICON,
|
statics::{FAVICON, OPT},
|
||||||
};
|
};
|
||||||
use actix_web::{
|
use actix_web::{
|
||||||
http::header::{self, CacheControl, CacheDirective},
|
http::header::{self, CacheControl, CacheDirective},
|
||||||
@ -113,6 +116,7 @@ fn main() -> Result<()> {
|
|||||||
web::get().to_async(handle_request::<GitLab>),
|
web::get().to_async(handle_request::<GitLab>),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.bind("0.0.0.0:8080")?
|
.workers(OPT.workers)
|
||||||
|
.bind((OPT.interface, OPT.port))?
|
||||||
.run()?)
|
.run()?)
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
use crate::data::FilePath;
|
use crate::{
|
||||||
|
data::FilePath,
|
||||||
|
statics::{GITHUB_AUTH_QUERY, OPT},
|
||||||
|
};
|
||||||
use actix_web::{
|
use actix_web::{
|
||||||
http::{header::LOCATION, StatusCode},
|
http::{header::LOCATION, StatusCode},
|
||||||
web, Error, HttpResponse,
|
web, Error, HttpResponse,
|
||||||
@ -105,11 +108,15 @@ pub(crate) trait Service {
|
|||||||
pub(crate) struct Github;
|
pub(crate) struct Github;
|
||||||
|
|
||||||
impl Github {
|
impl Github {
|
||||||
fn auth_query() -> Option<String> {
|
pub(crate) fn auth_query() -> Option<String> {
|
||||||
use std::env::var;
|
use std::env::var;
|
||||||
var("GITHUB_CLIENT_ID").ok().and_then(|id| {
|
OPT.github_id
|
||||||
var("GITHUB_CLIENT_SECRET")
|
.clone()
|
||||||
.ok()
|
.or_else(|| var("GITHUB_CLIENT_ID").ok())
|
||||||
|
.and_then(|id| {
|
||||||
|
OPT.github_secret
|
||||||
|
.clone()
|
||||||
|
.or_else(|| var("GITHUB_CLIENT_SECRET").ok())
|
||||||
.map(|secret| format!("?client_id={}&client_secret={}", id, secret))
|
.map(|secret| format!("?client_id={}&client_secret={}", id, secret))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -131,7 +138,7 @@ impl Service for Github {
|
|||||||
path.user,
|
path.user,
|
||||||
path.repo,
|
path.repo,
|
||||||
path.commit,
|
path.commit,
|
||||||
Self::auth_query().unwrap_or_default()
|
GITHUB_AUTH_QUERY.as_str()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
|
use crate::{config::Opt, service::Github};
|
||||||
|
use structopt::StructOpt;
|
||||||
|
|
||||||
const VERSION: &str = env!("CARGO_PKG_VERSION");
|
const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||||
pub(crate) const FAVICON: &[u8] = include_bytes!("../static/favicon32.png");
|
pub(crate) const FAVICON: &[u8] = include_bytes!("../static/favicon32.png");
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
pub(crate) static ref USER_AGENT: String = format!("gitache/{}", VERSION);
|
pub(crate) static ref USER_AGENT: String = format!("gitache/{}", VERSION);
|
||||||
|
pub(crate) static ref OPT: Opt = Opt::from_args();
|
||||||
|
pub(crate) static ref GITHUB_AUTH_QUERY: String = Github::auth_query().unwrap_or_default();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user