Skip to content

Commit

Permalink
refactor(openssl): Remove OpenSSL dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
klausi committed Dec 15, 2024
1 parent ef99bde commit c10a976
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 152 deletions.
121 changes: 1 addition & 120 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ description = "Synchronizes posts from Mastodon to Bluesky and back."
edition = "2021"

[dependencies]
bsky-sdk = { version = ">=0.1", default-features = false, features = [
"rich-text",
] }
anyhow = ">=1"
atrium-xrpc-client = ">=0.1"
bsky-sdk = ">=0.1"
atrium-xrpc-client = { version = ">=0.1", default-features = false, features = [
"reqwest",
] }
# Switching off default features removes a dependency to the "time" crate that
# contains a potential security issue.
# See https://github.com/time-rs/time/issues/293
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ RUN cargo vendor >> /code/.cargo/config.toml

FROM rust:1-alpine AS builder

RUN apk add --no-cache musl-dev openssl-dev openssl-libs-static
RUN apk add --no-cache musl-dev

ENV USER=root
WORKDIR /code
Expand Down
18 changes: 8 additions & 10 deletions src/bluesky_video.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
use crate::BskyAgent;
use anyhow::{bail, Result};
use atrium_xrpc_client::reqwest::ReqwestClient;
use bsky_sdk::{
api::{
client::AtpServiceClient,
types::{string::Did, BlobRef},
xrpc::{
http::{uri::Builder, Request, Response},
types::AuthorizationToken,
HttpClient, XrpcClient,
},
use bsky_sdk::api::{
client::AtpServiceClient,
types::{string::Did, BlobRef},
xrpc::{
http::{uri::Builder, Request, Response},
types::AuthorizationToken,
HttpClient, XrpcClient,
},
BskyAgent,
};
use serde::Serialize;
use std::result::Result::Ok;
Expand Down
2 changes: 1 addition & 1 deletion src/delete_favs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use bsky_sdk::api::types::string::Nsid;
use bsky_sdk::api::types::string::RecordKey;
use bsky_sdk::api::types::LimitedNonZeroU8;
use bsky_sdk::api::types::TryFromUnknown;
use bsky_sdk::BskyAgent;
use chrono::prelude::*;
use chrono::Duration;
use megalodon::error::Kind;
Expand All @@ -17,6 +16,7 @@ use tokio::fs;

use crate::cache_file;
use crate::config::*;
use crate::BskyAgent;

// Delete old favourites of this account that are older than 90 days.
pub async fn mastodon_delete_older_favs(
Expand Down
2 changes: 1 addition & 1 deletion src/delete_posts.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use anyhow::Result;
use bsky_sdk::api::types::LimitedNonZeroU8;
use bsky_sdk::api::types::TryFromUnknown;
use bsky_sdk::BskyAgent;
use chrono::prelude::*;
use chrono::Duration;
use std::collections::BTreeMap;
Expand All @@ -10,6 +9,7 @@ use crate::cache_file;
use crate::load_dates_from_cache;
use crate::remove_date_from_cache;
use crate::save_dates_to_cache;
use crate::BskyAgent;
use crate::DatePostList;

// Delete old posts of this account that are older than 90 days.
Expand Down
43 changes: 27 additions & 16 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use anyhow::Context;
use anyhow::Result;
use atrium_xrpc_client::reqwest::ReqwestClient;
use bsky_sdk::agent::config::FileStore;
use bsky_sdk::agent::BskyAgentBuilder;
use bsky_sdk::api::types::LimitedNonZeroU8;
use bsky_sdk::BskyAgent;
use delete_posts::bluesky_delete_older_posts;
use log::debug;
use megalodon::generator;
Expand All @@ -29,6 +30,8 @@ mod post;
mod registration;
mod sync;

type BskyAgent = bsky_sdk::BskyAgent<atrium_xrpc_client::reqwest::ReqwestClient>;

pub async fn run(args: Args) -> Result<()> {
debug!("running with args {:?}", args);

Expand Down Expand Up @@ -97,21 +100,27 @@ pub async fn run(args: Args) -> Result<()> {
match bsky_sdk::agent::config::Config::load(&FileStore::new("bluesky-auth-cache.json"))
.await
{
Ok(bsky_config) => match BskyAgent::builder().config(bsky_config).build().await {
Ok(agent) => {
// Save the session in case it was refreshed.
agent
.to_config()
.await
.save(&FileStore::new("bluesky-auth-cache.json"))
.await?;
agent
}
Err(_) => {
get_new_bluesky_agent(&config.bluesky.email, &config.bluesky.app_password)
.await?
Ok(bsky_config) => {
match BskyAgentBuilder::new(ReqwestClient::new("https://bsky.social"))
.config(bsky_config)
.build()
.await
{
Ok(agent) => {
// Save the session in case it was refreshed.
agent
.to_config()
.await
.save(&FileStore::new("bluesky-auth-cache.json"))
.await?;
agent
}
Err(_) => {
get_new_bluesky_agent(&config.bluesky.email, &config.bluesky.app_password)
.await?
}
}
},
}
Err(_) => {
get_new_bluesky_agent(&config.bluesky.email, &config.bluesky.app_password).await?
}
Expand Down Expand Up @@ -230,7 +239,9 @@ fn cache_file(name: &str) -> String {
}

async fn get_new_bluesky_agent(email: &str, app_password: &str) -> Result<BskyAgent> {
let agent = BskyAgent::builder().build().await?;
let agent = BskyAgentBuilder::new(ReqwestClient::new("https://bsky.social"))
.build()
.await?;
let _session = agent.login(email, app_password).await?;
agent
.to_config()
Expand Down
2 changes: 1 addition & 1 deletion src/post.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::bluesky_richtext::get_rich_text;
use crate::bluesky_video::bluesky_upload_video;
use crate::sync::NewStatus;
use crate::BskyAgent;
use anyhow::bail;
use anyhow::Context;
use anyhow::Result;
use bsky_sdk::BskyAgent;
use image_compressor::compressor::Compressor;
use image_compressor::Factor;
use megalodon::megalodon::PostStatusOutput;
Expand Down

0 comments on commit c10a976

Please sign in to comment.