1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-11-20 12:02:22 +03:00

Switch to camino's Utf8Path* instead of std::path::Path*

This commit is contained in:
Quentin Gliech
2022-11-18 18:50:11 +01:00
parent c76a1dd2e7
commit a86798d2b3
21 changed files with 99 additions and 74 deletions

View File

@@ -12,10 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use std::{num::NonZeroU32, path::PathBuf, time::Duration};
use std::{num::NonZeroU32, time::Duration};
use anyhow::Context;
use async_trait::async_trait;
use camino::Utf8PathBuf;
use rand::Rng;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
@@ -85,7 +86,8 @@ enum ConnectConfig {
/// Directory containing the UNIX socket to connect to
#[serde(default)]
socket: Option<PathBuf>,
#[schemars(with = "Option<String>")]
socket: Option<Utf8PathBuf>,
/// PostgreSQL user name to connect as
#[serde(default)]

View File

@@ -12,10 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use std::{borrow::Cow, io::Cursor, ops::Deref, path::PathBuf};
use std::{borrow::Cow, io::Cursor, ops::Deref};
use anyhow::bail;
use async_trait::async_trait;
use camino::Utf8PathBuf;
use mas_keystore::PrivateKey;
use rand::Rng;
use schemars::JsonSchema;
@@ -99,7 +100,8 @@ pub enum BindConfig {
/// Listen on a UNIX domain socket
Unix {
/// Path to the socket
socket: PathBuf,
#[schemars(with = "String")]
socket: Utf8PathBuf,
},
/// Accept connections on file descriptors passed by the parent process.
@@ -125,14 +127,16 @@ pub enum BindConfig {
#[serde(rename_all = "snake_case")]
pub enum KeyOrFile {
Key(String),
KeyFile(PathBuf),
#[schemars(with = "String")]
KeyFile(Utf8PathBuf),
}
#[derive(JsonSchema, Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "snake_case")]
pub enum CertificateOrFile {
Certificate(String),
CertificateFile(PathBuf),
#[schemars(with = "String")]
CertificateFile(Utf8PathBuf),
}
/// Configuration related to TLS on a listener
@@ -252,7 +256,8 @@ pub enum Resource {
/// Path from which to serve static files. If not specified, it will
/// serve the static files embedded in the server binary
#[serde(default)]
web_root: Option<PathBuf>,
#[schemars(with = "Option<String>")]
web_root: Option<Utf8PathBuf>,
},
/// Mount a "/connection-info" handler which helps debugging informations on
@@ -263,10 +268,12 @@ pub enum Resource {
/// Mount the single page app
Spa {
/// Path to the vite manifest
manifest: PathBuf,
#[schemars(with = "String")]
manifest: Utf8PathBuf,
/// Path to the assets to server
assets: PathBuf,
#[schemars(with = "String")]
assets: Utf8PathBuf,
},
}

View File

@@ -12,9 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use std::path::PathBuf;
use async_trait::async_trait;
use camino::Utf8PathBuf;
use rand::Rng;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
@@ -40,7 +39,8 @@ fn default_authorization_grant_endpoint() -> String {
pub struct PolicyConfig {
/// Path to the WASM module
#[serde(default)]
pub wasm_module: Option<PathBuf>,
#[schemars(with = "Option<String>")]
pub wasm_module: Option<Utf8PathBuf>,
/// Entrypoint to use when evaluating client registrations
#[serde(default = "default_client_registration_endpoint")]

View File

@@ -12,10 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use std::{borrow::Cow, path::PathBuf};
use std::borrow::Cow;
use anyhow::Context;
use async_trait::async_trait;
use camino::Utf8PathBuf;
use mas_jose::jwk::{JsonWebKey, JsonWebKeySet};
use mas_keystore::{Encrypter, Keystore, PrivateKey};
use rand::{
@@ -38,14 +39,16 @@ fn example_secret() -> &'static str {
#[serde(rename_all = "snake_case")]
pub enum KeyOrFile {
Key(String),
KeyFile(PathBuf),
#[schemars(with = "String")]
KeyFile(Utf8PathBuf),
}
#[derive(JsonSchema, Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "snake_case")]
pub enum PasswordOrFile {
Password(String),
PasswordFile(PathBuf),
#[schemars(with = "String")]
PasswordFile(Utf8PathBuf),
}
#[derive(JsonSchema, Serialize, Deserialize, Clone, Debug)]

View File

@@ -13,6 +13,7 @@
// limitations under the License.
use async_trait::async_trait;
use camino::Utf8PathBuf;
use rand::Rng;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
@@ -28,7 +29,8 @@ fn default_builtin() -> bool {
pub struct TemplatesConfig {
/// Path to the folder that holds the custom templates
#[serde(default)]
pub path: Option<String>,
#[schemars(with = "Option<String>")]
pub path: Option<Utf8PathBuf>,
/// Load the templates embedded in the binary
#[serde(default = "default_builtin")]

View File

@@ -12,10 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use std::path::Path;
use anyhow::Context;
use async_trait::async_trait;
use camino::Utf8Path;
use figment::{
error::Error as FigmentError,
providers::{Env, Format, Serialized, Yaml},
@@ -65,20 +64,20 @@ pub trait ConfigurationSection<'a>: Sized + Deserialize<'a> + Serialize {
/// Load configuration from a list of files and environment variables.
fn load_from_files<P>(paths: &[P]) -> Result<Self, FigmentError>
where
P: AsRef<Path>,
P: AsRef<Utf8Path>,
{
let base = Figment::new().merge(Env::prefixed("MAS_").split("_"));
paths
.iter()
.fold(base, |f, path| f.merge(Yaml::file(path)))
.fold(base, |f, path| f.merge(Yaml::file(path.as_ref())))
.extract_inner(Self::path())
}
/// Load configuration from a file and environment variables.
fn load_from_file<P>(path: P) -> Result<Self, FigmentError>
where
P: AsRef<Path>,
P: AsRef<Utf8Path>,
{
Self::load_from_files(&[path])
}