Merge pull request #7 from dat-adi/master
docs: Minor update in documentation and variable refactoring
This commit is contained in:
commit
29f5556586
10 changed files with 58 additions and 28 deletions
|
@ -182,13 +182,13 @@ pub trait SCDatabase: std::marker::Send + std::marker::Sync + CloneSPDatabase {
|
|||
/// delete DNS challenge
|
||||
async fn delete_dns_challenge(&self, key: &str) -> DBResult<()>;
|
||||
|
||||
/// create forge isntance
|
||||
async fn create_forge_isntance(&self, f: &CreateForge) -> DBResult<()>;
|
||||
/// create forge instance
|
||||
async fn create_forge_instance(&self, f: &CreateForge) -> DBResult<()>;
|
||||
|
||||
/// get forge isntance data
|
||||
/// get forge instance data
|
||||
async fn get_forge(&self, hostname: &str) -> DBResult<Forge>;
|
||||
|
||||
/// delete forge isntance
|
||||
/// delete forge instance
|
||||
async fn delete_forge_instance(&self, hostname: &str) -> DBResult<()>;
|
||||
|
||||
/// check if a forge instance exists
|
||||
|
|
|
@ -27,10 +27,10 @@ pub async fn adding_forge_works<'a, T: SCDatabase>(
|
|||
add_repo_msg: AddRepository<'a>,
|
||||
) {
|
||||
let _ = db.delete_forge_instance(create_forge_msg.hostname).await;
|
||||
db.create_forge_isntance(&create_forge_msg).await.unwrap();
|
||||
db.create_forge_instance(&create_forge_msg).await.unwrap();
|
||||
assert!(
|
||||
db.forge_exists(create_forge_msg.hostname).await.unwrap(),
|
||||
"forge creation failed, forge existance check failure"
|
||||
"forge creation failed, forge exinstance check failure"
|
||||
);
|
||||
|
||||
{
|
||||
|
|
|
@ -111,7 +111,7 @@ impl SCDatabase for Database {
|
|||
}
|
||||
}
|
||||
|
||||
/// delete forge isntance
|
||||
/// delete forge instance
|
||||
async fn delete_forge_instance(&self, hostname: &str) -> DBResult<()> {
|
||||
sqlx::query!(
|
||||
"DELETE FROM starchart_forges WHERE hostname = ($1)",
|
||||
|
@ -123,8 +123,8 @@ impl SCDatabase for Database {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// create forge isntance DB
|
||||
async fn create_forge_isntance(&self, f: &CreateForge) -> DBResult<()> {
|
||||
/// create forge instance DB
|
||||
async fn create_forge_instance(&self, f: &CreateForge) -> DBResult<()> {
|
||||
let now = now_unix_time_stamp();
|
||||
let forge_type = f.forge_type.to_str();
|
||||
sqlx::query!(
|
||||
|
@ -142,7 +142,7 @@ impl SCDatabase for Database {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// get forge isntance data
|
||||
/// get forge instance data
|
||||
async fn get_forge(&self, hostname: &str) -> DBResult<Forge> {
|
||||
let f = sqlx::query_as!(
|
||||
InnerForge,
|
||||
|
|
|
@ -32,9 +32,38 @@ project.**
|
|||
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
|
||||
```
|
||||
|
||||
### Setting up the workspace
|
||||
After installing rust, the database schema needs to be migrated,
|
||||
we use `sqlx` in this project to handle this. However, before running
|
||||
this application you might end up finding yourself stuck, here are a
|
||||
few things that you might come across.
|
||||
|
||||
#### Environment variables
|
||||
> thread 'main' panicked at 'called `Result::unwrap()` on an `Err`
|
||||
> value: missing field `url`'
|
||||
|
||||
Please ensure that you have the `.env` stored in the root of the
|
||||
repository, you can copy this from the `.env-sample` present in
|
||||
the root of the repository.
|
||||
|
||||
[temporary fix] There is also a need for the `DATABASE_URL` to
|
||||
be defined, so add that in too.
|
||||
|
||||
Next up, run the following commands to have the project compile and run,
|
||||
```bash
|
||||
source .env
|
||||
make migrate
|
||||
make
|
||||
```
|
||||
|
||||
This should ideally get your instance of Starchart running, and if
|
||||
you face any issues at this point, it's a good idea to check your
|
||||
environment variables once more, and review the dependencies for
|
||||
the project.
|
||||
|
||||
## Implementing Support for $FORGE
|
||||
|
||||
> In future, Starchart will be modified to talk forge federation
|
||||
> In the future, Starchart will be modified to talk forge federation
|
||||
> ActivityPub protocol(general term, not referring to
|
||||
> [forgefed](https://forgefed.peers.community/)), so implementing support
|
||||
> for $FORGE would mean implementing that protocol for $FORGE.
|
||||
|
|
|
@ -36,10 +36,10 @@ pub trait Federate: Sync + Send {
|
|||
/// utility method to remove file/dir
|
||||
async fn rm_util(&self, path: &Path) -> Result<(), Self::Error>;
|
||||
|
||||
/// create forge isntance
|
||||
async fn create_forge_isntance(&self, f: &CreateForge<'_>) -> Result<(), Self::Error>;
|
||||
/// create forge instance
|
||||
async fn create_forge_instance(&self, f: &CreateForge<'_>) -> Result<(), Self::Error>;
|
||||
|
||||
/// delete forge isntance
|
||||
/// delete forge instance
|
||||
async fn delete_forge_instance(&self, hostname: &str) -> Result<(), Self::Error>;
|
||||
|
||||
/// check if a forge instance exists
|
||||
|
@ -48,10 +48,10 @@ pub trait Federate: Sync + Send {
|
|||
/// check if an user exists.
|
||||
async fn user_exists(&self, username: &str, hostname: &str) -> Result<bool, Self::Error>;
|
||||
|
||||
/// create user isntance
|
||||
/// create user instance
|
||||
async fn create_user(&self, f: &AddUser<'_>) -> Result<(), Self::Error>;
|
||||
|
||||
/// add repository isntance
|
||||
/// add repository instance
|
||||
async fn create_repository(&self, f: &AddRepository<'_>) -> Result<(), Self::Error>;
|
||||
|
||||
/// check if a repository exists.
|
||||
|
|
|
@ -27,7 +27,7 @@ pub async fn adding_forge_works<'a, T: Federate>(
|
|||
) {
|
||||
let _ = ff.delete_forge_instance(create_forge_msg.hostname).await;
|
||||
assert!(!ff.forge_exists(&create_forge_msg.hostname).await.unwrap());
|
||||
ff.create_forge_isntance(&create_forge_msg).await.unwrap();
|
||||
ff.create_forge_instance(&create_forge_msg).await.unwrap();
|
||||
assert!(ff.forge_exists(&create_forge_msg.hostname).await.unwrap());
|
||||
|
||||
// add user
|
||||
|
|
|
@ -128,14 +128,14 @@ impl Federate for PccFederate {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// create forge isntance
|
||||
async fn create_forge_isntance(&self, f: &CreateForge<'_>) -> FResult<()> {
|
||||
/// create forge instance
|
||||
async fn create_forge_instance(&self, f: &CreateForge<'_>) -> FResult<()> {
|
||||
let path = self.get_instance_path(f.hostname, true).await?;
|
||||
self.write_util(f, &path.join(INSTANCE_INFO_FILE)).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// delete forge isntance
|
||||
/// delete forge instance
|
||||
async fn delete_forge_instance(&self, hostname: &str) -> FResult<()> {
|
||||
let path = self.get_instance_path(hostname, false).await?;
|
||||
self.rm_util(&path).await
|
||||
|
@ -163,13 +163,13 @@ impl Federate for PccFederate {
|
|||
}
|
||||
}
|
||||
|
||||
/// create user isntance
|
||||
/// create user instance
|
||||
async fn create_user(&self, f: &AddUser<'_>) -> Result<(), Self::Error> {
|
||||
let path = self.get_user_path(f.username, f.hostname, true).await?;
|
||||
self.write_util(f, &path.join(USER_INFO_FILE)).await
|
||||
}
|
||||
|
||||
/// add repository isntance
|
||||
/// add repository instance
|
||||
async fn create_repository(&self, f: &AddRepository<'_>) -> Result<(), Self::Error> {
|
||||
let path = self
|
||||
.get_repo_path(f.name, f.owner, f.hostname, true)
|
||||
|
|
|
@ -193,11 +193,11 @@ def add_tag(repo: str, client: HTMLClient):
|
|||
|
||||
if __name__ == "__main__":
|
||||
for i in range(TOTAL_NUM_REPOS):
|
||||
REPOS.append(f"reopsitory_{i}")
|
||||
REPOS.append(f"repository_{i}")
|
||||
check_online()
|
||||
print("Instace online")
|
||||
print("Instance online")
|
||||
install()
|
||||
print("Instace configured and installed")
|
||||
print("Instance configured and installed")
|
||||
client = HTMLClient()
|
||||
count = 0
|
||||
while True:
|
||||
|
|
|
@ -31,6 +31,7 @@ pub mod routes;
|
|||
pub mod settings;
|
||||
pub mod spider;
|
||||
pub mod static_assets;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
pub mod utils;
|
||||
|
|
|
@ -44,7 +44,7 @@ impl Ctx {
|
|||
hostname,
|
||||
forge_type: forge.forge_type(),
|
||||
};
|
||||
db.create_forge_isntance(&msg).await.unwrap();
|
||||
db.create_forge_instance(&msg).await.unwrap();
|
||||
} else {
|
||||
if !federate.forge_exists(hostname).await.unwrap() {
|
||||
let forge = db.get_forge(hostname).await.unwrap();
|
||||
|
@ -52,7 +52,7 @@ impl Ctx {
|
|||
hostname,
|
||||
forge_type: forge.forge_type,
|
||||
};
|
||||
federate.create_forge_isntance(&msg).await.unwrap();
|
||||
federate.create_forge_instance(&msg).await.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -142,7 +142,7 @@ mod tests {
|
|||
.unwrap());
|
||||
assert!(db.user_exists(GITEA_USERNAME, None).await.unwrap());
|
||||
for i in 0..100 {
|
||||
let repo = format!("reopsitory_{i}");
|
||||
let repo = format!("repository_{i}");
|
||||
assert!(db
|
||||
.repository_exists(&repo, GITEA_USERNAME, hostname.as_str())
|
||||
.await
|
||||
|
|
Loading…
Reference in a new issue