-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Lol3rrr
committed
Oct 30, 2023
1 parent
94b2c64
commit 8d52486
Showing
9 changed files
with
509 additions
and
12 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Gold-Pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Gold-Pass-Bot | ||
|
||
## Environment-Variables | ||
* `S3_BUCKET` | ||
* `S3_ACCESS_KEY` | ||
* `S3_SECRET_KEY` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use crate::StorageBackend; | ||
|
||
pub struct Replicated<P, S> { | ||
primary: P, | ||
secondary: S, | ||
} | ||
|
||
impl<P, S> Replicated<P, S> { | ||
pub fn new(primary: P, secondary: S) -> Self { | ||
Self { primary, secondary } | ||
} | ||
} | ||
|
||
impl<P, S> StorageBackend for Replicated<P, S> | ||
where | ||
P: StorageBackend, | ||
S: StorageBackend, | ||
{ | ||
fn write( | ||
&mut self, | ||
content: Vec<u8>, | ||
) -> std::pin::Pin<Box<dyn std::future::Future<Output = Result<(), ()>> + Send + 'static>> { | ||
let pfut = self.primary.write(content.clone()); | ||
let sfut = self.secondary.write(content); | ||
|
||
Box::pin(async move { | ||
let pres = pfut.await; | ||
let sres = sfut.await; | ||
|
||
pres.or(sres) | ||
}) | ||
} | ||
|
||
fn load( | ||
&mut self, | ||
) -> std::pin::Pin<Box<dyn std::future::Future<Output = Result<Vec<u8>, ()>> + Send + 'static>> | ||
{ | ||
let pfut = self.primary.load(); | ||
let sfut = self.secondary.load(); | ||
|
||
Box::pin(async move { | ||
if let Ok(r) = pfut.await { | ||
return Ok(r); | ||
} | ||
|
||
sfut.await | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use crate::StorageBackend; | ||
|
||
pub struct S3Storage { | ||
bucket: s3::Bucket, | ||
filename: String, | ||
} | ||
|
||
impl S3Storage { | ||
pub fn new(bucket: s3::Bucket) -> Self { | ||
Self { | ||
bucket, | ||
filename: "/storage.json".to_string(), | ||
} | ||
} | ||
} | ||
|
||
impl StorageBackend for S3Storage { | ||
fn write( | ||
&mut self, | ||
content: Vec<u8>, | ||
) -> std::pin::Pin<Box<dyn std::future::Future<Output = Result<(), ()>> + Send + 'static>> { | ||
let bucket = self.bucket.clone(); | ||
let filename = self.filename.clone(); | ||
|
||
Box::pin(async move { | ||
let filename = filename; | ||
let content = content; | ||
|
||
let res = bucket.put_object(&filename, &content); | ||
|
||
match res.await { | ||
Ok(_) => Ok(()), | ||
Err(e) => Err(()), | ||
} | ||
}) | ||
} | ||
|
||
fn load( | ||
&mut self, | ||
) -> std::pin::Pin<Box<dyn std::future::Future<Output = Result<Vec<u8>, ()>> + Send + 'static>> | ||
{ | ||
let bucket = self.bucket.clone(); | ||
let filename = self.filename.clone(); | ||
|
||
Box::pin(async move { | ||
match bucket.get_object(filename).await { | ||
Ok(c) => Ok(c.to_vec()), | ||
Err(e) => Err(()), | ||
} | ||
}) | ||
} | ||
} |