Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/1328 range responses #1341

Merged
merged 2 commits into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 113 additions & 37 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,71 +7,147 @@
sbt.url = "github:zaninime/sbt-derivation";
};

outputs = inputs@{ self, nixpkgs, flake-utils, sbt }:
outputs = inputs @ {
self,
nixpkgs,
flake-utils,
sbt,
}:
{
overlays.default = final: prev: {
sharry = import ./nix/package.nix {
inherit (final) pkgs;
inherit sbt;
lib = final.pkgs.lib;
};
sharry-bin = prev.pkgs.callPackage (import ./nix/package-bin.nix) { };
sharry-bin = prev.pkgs.callPackage (import ./nix/package-bin.nix) {};
};
nixosModules.default = import ./nix/module.nix;

nixosConfigurations.test-vm =
let
nixosConfigurations = let
baseModule = {config, ...}: {system.stateVersion = "23.11";};
in {
test-vm = let
system = "x86_64-linux";
pkgs = import inputs.nixpkgs {
inherit system;
overlays = [ self.overlays.default ];
overlays = [self.overlays.default];
};

in
nixpkgs.lib.nixosSystem {
inherit pkgs system;
specialArgs = inputs;
nixpkgs.lib.nixosSystem {
inherit pkgs system;
specialArgs = inputs;
modules = [
baseModule
self.nixosModules.default
./nix/test/configuration-test.nix
];
};

dev-vm = nixpkgs.lib.nixosSystem {
system = flake-utils.lib.system.x86_64-linux;
specialArgs = {inherit inputs;};
modules = [
self.nixosModules.default
./nix/configuration-test.nix
baseModule
./nix/devsetup/vm.nix
./nix/devsetup/services.nix
];
};
} // flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; overlays = [ self.overlays.default ]; };
in
{

container = nixpkgs.lib.nixosSystem {
system = flake-utils.lib.system.x86_64-linux;
modules = [
baseModule
({pkgs, ...}: {
boot.isContainer = true;
networking.useDHCP = false;
})
./nix/devsetup/services.nix
];
};
};
}
// flake-utils.lib.eachDefaultSystem (
system: let
pkgs = import nixpkgs {
inherit system;
overlays = [self.overlays.default];
};
in {
packages = {
inherit (pkgs) sharry sharry-bin;
default = self.packages."${system}".sharry;
};

formatter = pkgs.nixpkgs-fmt;
formatter = pkgs.alejandra;

devShells.default =
let
run-jekyll = pkgs.writeScriptBin "jekyll-sharry" ''
jekyll serve -s modules/microsite/target/site --baseurl /sharry
'';
in
pkgs.mkShell {
buildInputs = with pkgs; [
pkgs.sbt
devShells = let
devscripts = (import ./nix/devsetup/dev-scripts.nix) {inherit (pkgs) concatTextFile writeShellScriptBin;};
allPkgs = devscripts // pkgs;
commonBuildInputs = with allPkgs; [
pkgs.sbt

# frontend
tailwindcss
elmPackages.elm
# frontend
tailwindcss
elmPackages.elm

# for debian packages
dpkg
fakeroot
# for debian packages
dpkg
fakeroot

# microsite
jekyll
nodejs_18
run-jekyll
];
# microsite
jekyll
nodejs_18

# convenience
postgresql
];
in {
default = pkgs.mkShellNoCC {
SHARRY_CONTAINER = "sharry-dev";
SHARRY_BACKEND_JDBC_URL = "jdbc:postgresql://sharry-dev:5432/sharry_dev";
SHARRY_BACKEND_JDBC_USER = "dev";
SHARRY_BACKEND_JDBC_PASSWORD = "dev";
SHARRY_BIND_ADDRESS = "0.0.0.0";
SHARRY_BACKEND_MAIL_SMTP_HOST = "sharry-dev";
SHARRY_BACKEND_MAIL_SMTP_PORT = "25";
SHARRY_BACKEND_MAIL_SMTP_USER = "admin";
SHARRY_BACKEND_MAIL_SMTP_PASSWORD = "admin";
SHARRY_BACKEND_MAIL_SMTP_SSL__TYPE = "none";

buildInputs =
commonBuildInputs
++ (with devscripts; [
# scripts
devcontainer-recreate
devcontainer-start
devcontainer-stop
devcontainer-login
]);
};

dev-vm = pkgs.mkShellNoCC {
SHARRY_BACKEND_JDBC_URL = "jdbc:postgresql://localhost:15432/sharry_dev";
SHARRY_BACKEND_JDBC_USER = "dev";
SHARRY_BACKEND_JDBC_PASSWORD = "dev";
SHARRY_BIND_ADDRESS = "0.0.0.0";
SHARRY_BACKEND_MAIL_SMTP_HOST = "localhost";
SHARRY_BACKEND_MAIL_SMTP_PORT = "10025";
SHARRY_BACKEND_MAIL_SMTP_USER = "admin";
SHARRY_BACKEND_MAIL_SMTP_PASSWORD = "admin";
SHARRY_BACKEND_MAIL_SMTP_SSL__TYPE = "none";
VM_SSH_PORT = "10022";

buildInputs =
commonBuildInputs
++ (with devscripts; [
# scripts
vm-build
vm-run
vm-ssh
]);
};
};
}
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package sharry.backend.config
import cats.data.{Validated, ValidatedNec}
import cats.syntax.all._

import sharry.common.ByteSize
import sharry.common.Ident
import sharry.store.FileStoreConfig

case class FilesConfig(
defaultStore: Ident,
stores: Map[Ident, FileStoreConfig],
copyFiles: CopyFilesConfig
copyFiles: CopyFilesConfig,
downloadChunkSize: ByteSize
) {

val enabledStores: Map[Ident, FileStoreConfig] =
Expand Down
16 changes: 16 additions & 0 deletions modules/restserver/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ sharry.restserver {
# Where the server binds to.
bind {
address = "localhost"
address = ${?SHARRY_BIND_ADDRESS}
port = 9090
port = ${?SHARRY_BIND_PORT}
}

# Configures logging
Expand Down Expand Up @@ -295,8 +297,11 @@ sharry.restserver {
# use the PostgreSQL compatibility mode.
jdbc {
url = "jdbc:h2://"${java.io.tmpdir}"/sharry-demo.db;MODE=PostgreSQL;DATABASE_TO_LOWER=TRUE"
url = ${?SHARRY_BACKEND_JDBC_URL}
user = "sa"
user = ${?SHARRY_BACKEND_JDBC_USER}
password = ""
password = ${?SHARRY_BACKEND_JDBC_PASSWORD}
}

# How files are stored.
Expand Down Expand Up @@ -353,6 +358,10 @@ sharry.restserver {
# How many files to copy in parallel.
parallel = 2
}

# For open range requests, use this amount of data when
# responding.
download-chunk-size = "4M"
}

# Checksums of uploaded files are computed in the background.
Expand Down Expand Up @@ -387,6 +396,7 @@ sharry.restserver {
# invitation key. Invitation keys can be generated by an admin.
# - closed: signing up is disabled.
mode = "open"
mode = ${?SHARRY_BACKEND_SIGNUP_MODE}

# If mode == 'invite', this is the period an invitation token is
# considered valid.
Expand All @@ -397,6 +407,7 @@ sharry.restserver {
# invitation keys. Generating such keys is only permitted to
# admin users.
invite-password = "generate-invite"
invite-password = ${?SHARRY_BACKEND_SIGNUP_INVITE__PASSWORD}
}


Expand Down Expand Up @@ -463,15 +474,20 @@ sharry.restserver {
smtp {
# Host and port of the SMTP server
host = "localhost"
host = ${?SHARRY_BACKEND_MAIL_SMTP_HOST}
port = 25
port = ${?SHARRY_BACKEND_MAIL_SMTP_PORT}

# User credentials to authenticate at the server. If the user
# is empty, mails are sent without authentication.
user = ""
user = ${?SHARRY_BACKEND_MAIL_SMTP_USER}
password = ""
password = ${?SHARRY_BACKEND_MAIL_SMTP_PASSWORD}

# One of: none, starttls, ssl
ssl-type = "starttls"
ssl-type = ${?SHARRY_BACKEND_MAIL_SMTP_SSL__TYPE}

# In case of self-signed certificates or other problems like
# that, checking certificates can be disabled.
Expand Down
44 changes: 33 additions & 11 deletions modules/restserver/src/main/scala/sharry/restserver/Main.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package sharry.restserver

import java.nio.file.Path
import java.nio.file.{Files, Paths}

import cats.effect._
Expand All @@ -14,6 +15,36 @@ object Main extends IOApp {
val connectEC =
ThreadFactories.fixed[IO](5, ThreadFactories.ofName("sharry-dbconnect"))

private def configFromSysProp: Option[Path] =
Option(System.getProperty("config.file")).filter(_.nonEmpty).flatMap { f =>
val path = Paths.get(f).toAbsolutePath.normalize
if (!Files.exists(path)) {
logger.asUnsafe.info(
s"Not using config file '$f' because it doesn't exist"
)
System.clearProperty("config.file")
None
} else {
logger.asUnsafe.info(s"Using config file from system properties: $f")
Some(path)
}
}
private def configFromEnv: Option[Path] =
Option(System.getenv("SHARRY_CONFIG_FILE")).filter(_.nonEmpty).flatMap { f =>
val path = Paths.get(f).toAbsolutePath.normalize
if (!Files.exists(path)) {
logger.asUnsafe.info(
s"Not using config file '$f' because it doesn't exist"
)
System.clearProperty("config.file")
None
} else {
logger.asUnsafe.info(s"Using config file from environment variable: $f")
System.setProperty("config.file", path.toString)
Some(path)
}
}

def run(args: List[String]): IO[ExitCode] =
for {
_ <- IO {
Expand All @@ -23,17 +54,8 @@ object Main extends IOApp {
logger.asUnsafe.info(s"Using given config file: $path")
System.setProperty("config.file", file)
case _ =>
Option(System.getProperty("config.file")) match {
case Some(f) if f.nonEmpty =>
val path = Paths.get(f).toAbsolutePath.normalize
if (!Files.exists(path)) {
logger.asUnsafe.info(
s"Not using config file '$f' because it doesn't exist"
)
System.clearProperty("config.file")
} else
logger.asUnsafe.info(s"Using config file from system properties: $f")
case _ =>
configFromSysProp.orElse(configFromEnv).map(_ => ()).getOrElse {
logger.asUnsafe.info("No configuration file found!")
}
}
}
Expand Down
Loading
Loading