aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@archive.org>2020-06-13 15:01:32 -0700
committerBryan Newbold <bnewbold@archive.org>2020-06-13 15:01:32 -0700
commitd342f7a1861d8b002f48c91836e9b9fc69eeb94c (patch)
treedc90fdbe3caeabc9f57b11bb73968bd6b115885d
parent4575478d953fae3068959feef80517cafc826fea (diff)
downloadfatcat-cli-d342f7a1861d8b002f48c91836e9b9fc69eeb94c.tar.gz
fatcat-cli-d342f7a1861d8b002f48c91836e9b9fc69eeb94c.zip
meta rust files from bnewbold-cli branch
-rw-r--r--rust/.gitignore6
-rw-r--r--rust/Cargo.toml59
-rwxr-xr-xrust/codegen_openapi.sh42
-rw-r--r--rust/example.env10
-rwxr-xr-xrust/openapi-generator-cli.sh70
5 files changed, 187 insertions, 0 deletions
diff --git a/rust/.gitignore b/rust/.gitignore
new file mode 100644
index 0000000..03e5059
--- /dev/null
+++ b/rust/.gitignore
@@ -0,0 +1,6 @@
+.env
+target/
+bin/
+fatcat-*.tar.gz
+
+!.cargo
diff --git a/rust/Cargo.toml b/rust/Cargo.toml
new file mode 100644
index 0000000..21da1db
--- /dev/null
+++ b/rust/Cargo.toml
@@ -0,0 +1,59 @@
+[package]
+name = "fatcat"
+version = "0.3.1"
+edition = "2018"
+authors = ["Bryan Newbold <bnewbold@archive.org>"]
+description = "A scalable, versioned, API-oriented catalog for bibliographic entities and file metadata"
+homepage = "https://fatcat.wiki"
+repository = "https://github.com/internetarchive/fatcat"
+license = "AGPL-3.0-or-later"
+
+[workspace]
+members = ["fatcat-openapi", "fatcat-cli"]
+
+[dependencies]
+fatcat-openapi = {version = "*", path = "fatcat-openapi", features = ["server"] }
+diesel = { version = "1.3", features = ["postgres", "uuid", "serde_json", "chrono", "r2d2"] }
+diesel_migrations = "1.3"
+dotenv = "0.15"
+clap = "2"
+uuid = "0.6"
+log = { version = "*", features = ["max_level_info", "release_max_level_info"] }
+data-encoding = "2.1"
+regex = "1"
+lazy_static = "1.0"
+sha1 = { version = "0.6", features = ["std"] }
+macaroon = { git = "https://github.com/bnewbold/libmacaroon-rs", branch = "bnewbold-broken" }
+rand = "*"
+failure = "*"
+
+# API server
+chrono = { version = "0.4", features = ["serde"] }
+futures = "0.1"
+hyper = "0.10"
+iron = "0.6"
+iron-slog = "0.0.2"
+iron-test = "*"
+swagger = "0.7"
+slog = "^2.0"
+slog-term = "*"
+slog-async = "*"
+slog-stdlog = "*"
+slog-scope = "*"
+serde_json = "1.0"
+serde = "1.0"
+serde_derive = "1.0"
+serde_ignored = "0.0.4"
+sentry = { version = "^0.12", default-features = false, features = ["with_client_implementation", "with_backtrace", "with_panic", "with_log", "with_rust_info", "with_failure"] }
+cadence = "^0.16"
+
+# Command-line tools
+crossbeam-channel = "0.2"
+num_cpus = "1"
+env_logger = "*"
+
+[profile.release]
+lto = true
+codegen-units = 1
+opt-level = "z"
+panic = "abort"
diff --git a/rust/codegen_openapi.sh b/rust/codegen_openapi.sh
new file mode 100755
index 0000000..f86b276
--- /dev/null
+++ b/rust/codegen_openapi.sh
@@ -0,0 +1,42 @@
+#!/bin/bash
+
+set -exu
+set -o pipefail
+
+echo "Running openapi-generator..."
+OUTPUT=`pwd`/fatcat-openapi
+mkdir -p $OUTPUT
+cat ../fatcat-openapi3.yml | grep -v "TAGLINE$" | perl -0777 -pe "s/<\!-- STARTLONGDESCRIPTION -->.*<\!-- ENDLONGDESCRIPTION -->//s" > $OUTPUT/api.yaml
+
+export OPENAPI_GENERATOR_VERSION=5.0.0-SNAPSHOT
+./openapi-generator-cli.sh \
+ generate \
+ --generator-name rust-server \
+ --input-spec $OUTPUT/api.yaml \
+ --output $OUTPUT \
+ --package-name=fatcat-openapi \
+ --generate-alias-as-model
+
+cd fatcat-openapi
+
+echo "Running cargo-fmt (first time)..."
+cargo fmt
+
+echo "Patching..."
+
+# Hack to fix "release_date" (and "withdrawn_date") as Date, not DateTime
+sed -i 's/_date: Option<chrono::DateTime<chrono::Utc>>/_date: Option<chrono::NaiveDate>/g' src/models.rs
+sed -i 's/_date: Vec<chrono::DateTime<chrono::Utc>>/_date: Vec<chrono::NaiveDate>/g' src/models.rs
+perl -0777 -pi -e 's/_date\.push\(\n\s+chrono::DateTime::<chrono::Utc>::from_str/_date\.push\(chrono::NaiveDate::from_str/gs' src/models.rs
+
+# unnecessary duplicate copies of API spec
+rm api.yaml
+rm -rf api/
+
+echo "Running cargo-fmt (final time)..."
+cargo fmt
+
+cp Cargo.toml Cargo.toml.codegen
+git checkout Cargo.toml
+diff Cargo.toml Cargo.toml.codegen && true
+echo "Check the above diff for non-metadata changes to fatcat-openapi/Cargo.toml"
diff --git a/rust/example.env b/rust/example.env
new file mode 100644
index 0000000..bee653c
--- /dev/null
+++ b/rust/example.env
@@ -0,0 +1,10 @@
+DATABASE_URL="postgres://fatcat:tactaf@localhost/fatcat"
+TEST_DATABASE_URL="postgres://fatcat:tactaf@localhost/fatcat_test"
+AUTH_LOCATION="dev.fatcat.wiki"
+AUTH_KEY_IDENT="20190101-dev-dummy-key"
+AUTH_SECRET_KEY="5555555555555555555555555555555555555555xms="
+AUTH_ALT_KEYS="20181220-dev:6666666666666666666666666666666666666666xms=,20181210-dev:7777777777777777777777777777777777777777xms="
+#SENTRY_DSN=
+# should be localhost IP, not 'localhost'
+#FATCAT_STATSD_HOST="127.0.0.1"
+#FATCAT_STATSD_PORT="8125"
diff --git a/rust/openapi-generator-cli.sh b/rust/openapi-generator-cli.sh
new file mode 100755
index 0000000..e39ee08
--- /dev/null
+++ b/rust/openapi-generator-cli.sh
@@ -0,0 +1,70 @@
+#!/usr/bin/env bash
+####
+# Save as openapi-generator-cli on your PATH. chmod u+x. Enjoy.
+#
+# This script will query github on every invocation to pull the latest released version
+# of openapi-generator.
+#
+# If you want repeatable executions, you can explicitly set a version via
+# OPENAPI_GENERATOR_VERSION
+# e.g. (in Bash)
+# export OPENAPI_GENERATOR_VERSION=3.1.0
+# openapi-generator-cli.sh
+# or
+# OPENAPI_GENERATOR_VERSION=3.1.0 openapi-generator-cli.sh
+#
+# This is also helpful, for example, if you want want to evaluate a SNAPSHOT version.
+#
+# NOTE: Jars are downloaded on demand from maven into the same directory as this script
+# for every 'latest' version pulled from github. Consider putting this under its own directory.
+####
+set -o pipefail
+
+for cmd in {mvn,jq,curl}; do
+ if ! command -v ${cmd} > /dev/null; then
+ >&2 echo "This script requires '${cmd}' to be installed."
+ exit 1
+ fi
+done
+
+function latest.tag {
+ local uri="https://api.github.com/repos/${1}/releases"
+ local ver=$(curl -s ${uri} | jq -r 'first(.[]|select(.prerelease==false)).tag_name')
+ if [[ $ver == v* ]]; then
+ ver=${ver:1}
+ fi
+ echo $ver
+}
+
+ghrepo=openapitools/openapi-generator
+groupid=org.openapitools
+artifactid=openapi-generator-cli
+ver=${OPENAPI_GENERATOR_VERSION:-$(latest.tag $ghrepo)}
+
+jar=${artifactid}-${ver}.jar
+cachedir=${OPENAPI_GENERATOR_DOWNLOAD_CACHE_DIR}
+
+DIR=${cachedir:-"$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"}
+
+if [ ! -d "${DIR}" ]; then
+ mkdir -p "${DIR}"
+fi
+
+if [ ! -f ${DIR}/${jar} ]; then
+ repo="central::default::https://repo1.maven.org/maven2/"
+ if [[ ${ver} =~ ^.*-SNAPSHOT$ ]]; then
+ repo="central::default::https://oss.sonatype.org/content/repositories/snapshots"
+ fi
+ mvn org.apache.maven.plugins:maven-dependency-plugin:2.9:get \
+ -DremoteRepositories=${repo} \
+ -Dartifact=${groupid}:${artifactid}:${ver} \
+ -Dtransitive=false \
+ -Ddest=${DIR}/${jar}
+fi
+
+java -ea \
+ ${JAVA_OPTS} \
+ -Xms512M \
+ -Xmx1024M \
+ -server \
+ -jar ${DIR}/${jar} "$@"