Browse Source

Merge pull request 'Store' (#1) from store_config into master

Reviewed-on: https://git.scd31.com/stephen/cat-disruptor-7000/pulls/1
tags/v0.3.0
stephen 10 months ago
parent
commit
f983c629f3
8 changed files with 32 additions and 8 deletions
  1. +1
    -1
      Cargo.lock
  2. +4
    -3
      Cargo.toml
  3. +2
    -1
      config.example
  4. +1
    -0
      debian/cat-disruptor.service
  5. +6
    -0
      debian/config.json
  6. +3
    -0
      debian/maintainer_scripts/postinst
  7. +1
    -0
      src/config.rs
  8. +14
    -3
      src/main.rs

+ 1
- 1
Cargo.lock View File

@ -124,7 +124,7 @@ dependencies = [
[[package]]
name = "cat_disruptor_7000"
version = "0.1.0"
version = "0.2.0"
dependencies = [
"async-trait",
"matrix-sdk",


+ 4
- 3
Cargo.toml View File

@ -1,6 +1,6 @@
[package]
name = "cat_disruptor_7000"
version = "0.1.1"
version = "0.2.0"
authors = ["Stephen D <@stephen:m.scd31.com>"]
edition = "2018"
@ -31,5 +31,6 @@ priority = "optional"
assets = [
["target/release/cat_disruptor_7000", "usr/bin/", "755"],
["debian/cat-disruptor.service", "/lib/systemd/system/cat-disruptor.service", "644"],
["config.example", "/etc/cat_disruptor_7000/config.json", "644"]
]
["debian/config.json", "/etc/cat_disruptor_7000/config.json", "644"]
]
maintainer-scripts = "debian/maintainer_scripts/"

+ 2
- 1
config.example View File

@ -1,5 +1,6 @@
{
"homeserver_url": "changeme",
"username": "changeme",
"password": "changeme"
"password": "changeme",
"store_path": "crypto"
}

+ 1
- 0
debian/cat-disruptor.service View File

@ -8,6 +8,7 @@ ExecStart=/usr/bin/cat_disruptor_7000
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
User=cat-disruptor
[Install]
WantedBy=multi-user.target

+ 6
- 0
debian/config.json View File

@ -0,0 +1,6 @@
{
"homeserver_url": "changeme",
"username": "changeme",
"password": "changeme",
"store_path": "/etc/cat_disruptor_7000/store"
}

+ 3
- 0
debian/maintainer_scripts/postinst View File

@ -0,0 +1,3 @@
adduser --system cat-disruptor
mkdir -p /etc/cat_disruptor_7000/store
chown cat-disruptor /etc/cat_disruptor_7000/store

+ 1
- 0
src/config.rs View File

@ -7,6 +7,7 @@ pub struct Config {
pub homeserver_url: String,
pub username: String,
pub password: String,
pub store_path: String
}
pub fn get_config() -> Config {


+ 14
- 3
src/main.rs View File

@ -1,4 +1,6 @@
use std::collections::HashMap;
use std::path::Path;
use std::fs;
use url::Url;
@ -99,9 +101,9 @@ impl EventEmitter for EventCallback {
async fn login(
homeserver_url: String,
username: String,
password: String
password: String,
config: ClientConfig
) -> Result<(), matrix_sdk::Error> {
let config = ClientConfig::new();
let homeserver_url = Url::parse(&homeserver_url).expect("Couldn't parse the homeserver URL");
let mut client = Client::new_with_config(homeserver_url, config).unwrap();
@ -126,6 +128,15 @@ async fn main() -> Result<(), matrix_sdk::Error> {
config.password == "changeme" {
panic!("Please update the values in the config file!");
}
let store_path = fs::canonicalize(Path::new(&config.store_path)).unwrap();
if !store_path.exists() {
fs::create_dir(config.store_path.clone()).unwrap();
}
let matrix_config = ClientConfig::new()
.store_path(store_path);
login(config.homeserver_url, config.username, config.password).await
login(config.homeserver_url, config.username, config.password, matrix_config).await
}

Loading…
Cancel
Save