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

Use Kong for CLI management and config retrieval #126

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
64 changes: 37 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ Environment="LIB_PATH=<absolute path to the library>"

then, start the service with `service coreander start`. You can manage it with the usual commands `start`, `stop` and `status`. Refer to your service manager documentation for more information.

Coreander requires a `LIB_PATH` environment variable to be set, which tells the application where your documents are located.
Coreander requires the absolute path where your documents are located as an argument. You can also pass it through the `LIB_PATH` environment variable.

On first run, Coreander will index the documents in your library, creating a database with those entries located at `$home/coreander/index`. Depending on your system's performance and the size of your library this may take a while. Also, the database can grow fairly big, so make sure you have enough free space on disk.

Every time is run, the application scans the library folder only for documents not yet indexed and adds them to the index. You can force to index all documents wether they were previously indexed or not by setting the environment variable `FORCE_INDEXING` to `true`.
Every time is run, the application scans the library folder only for documents not yet indexed and adds them to the index. You can force to index all documents wether they were previously indexed or not by passing the `--force-indexing` flag or setting the environment variable `FORCE_INDEXING` to `true`.

Even if the application is still indexing entries, you can access its web interface right away. Just open a web browser and go to `localhost:3000` (replace `localhost` with the hostname / IP address of the machine where the server is running if you want to access it from another system). It is possible to change the listening port just executing the application with the `PORT` environment variable (e. g. `PORT=4000 coreander`)
Even if the application is still indexing entries, you can access its web interface right away. Just open a web browser and go to `localhost:3000` (replace `localhost` with the hostname / IP address of the machine where the server is running if you want to access it from another system). It is possible to change the listening port just executing the application with the `-p` or `--port` flags, or the `PORT` environment variable (e. g. `coreander -p 4000` or `PORT=4000 coreander`)

### Setting up an Internet-facing server

Expand All @@ -88,12 +88,14 @@ Some features rely on having an SMTP email service set up, and won't be availabl
* Send document to email.
* Recover user password.

You can use any email service that allow sending emails using the SMTP protocol, like [GMX](https://gmx.com/mail). The following environment variables need to be defined:
You can use any email service that allow sending emails using the SMTP protocol, like [GMX](https://gmx.com/mail). The following flags or environment variables need to be defined:

* `SMTP_SERVER`: The URL of the SMTP server to be used, for example `mail.gmx.com`.
* `SMTP_PORT`: The port number used by the email service, defaults to `587`.
* `SMTP_USER`: The user name.
* `SMTP_PASSWORD`: User's password.
|Flag|Environment variable|Description|
|----|--------------------|-----------|
|`--smtp-server` | `SMTP_SERVER` | The URL of the SMTP server to be used, for example `mail.gmx.com`.|
|`--smtp-port` | `SMTP_PORT` | The port number used by the email service, defaults to `587`. |
|`--smtp-user` | `SMTP_USER` | The user name. |
|`--smtp-password`| `SMTP_PASSWORD`| User's password. |

#### Send to email

Expand All @@ -103,7 +105,7 @@ Coreander can send documents through email. This way, you can take advantage of

Coreander distinguish between two kinds of users: regular users and administrator users, with the latter being the only ones with the ability to create new users and upload and delete documents.

By default, Coreander allow unrestricted access to its contents, except management areas which require an administrator user. To allow access only to registered users in the whole application, pass the `REQUIRE_AUTH=true` environment variable.
By default, Coreander allow unrestricted access to its contents, except management areas which require an administrator user. To allow access only to registered users in the whole application, pass the `-a` or `--require-auth` flags, or the `REQUIRE_AUTH=true` environment variable.

On first run, Coreander creates an admin user with the following credentials:

Expand All @@ -114,23 +116,31 @@ On first run, Coreander creates an admin user with the following credentials:

### Settings

* `LIB_PATH`: Absolute path to the folder containing the documents.
* `PORT`: Port number in which the webserver listens for requests. Defaults to 3000.
* `BATCH_SIZE`: Number of documents persisted by the indexer in one write operation. Defaults to 100.
* `COVER_MAX_WIDTH`: Maximum horizontal size for documents cover thumbnails in pixels. Defaults to 600.
* `FORCE_INDEXING`: Whether to force indexing already indexed documents or not. Defaults to false.
* `SMTP_SERVER`: Address of the send mail server.
* `SMTP_PORT`: Port number of the send mail server. Defaults to 587.
* `SMTP_USER`: User to authenticate against the SMTP server.
* `SMTP_PASSWORD`: User's password to authenticate against the SMTP server.
* `JWT_SECRET`: String to use to sign JWTs.
* `REQUIRE_AUTH`: Require authentication to access the application if true. Defaults to false.
* `MIN_PASSWORD_LENGTH`: Minimum length acceptable for passwords. Defaults to 5.
* `WORDS_PER_MINUTE`: Defines a default words per minute reading speed that will be used for not logged-in users. Defaults to 250.
* `SESSION_TIMEOUT`: Specifies the maximum time a user session may last, in hours. Floating-point values are allowed. Defaults to 24 hours.
* `RECOVERY_TIMEOUT`: Specifies the maximum time a user recovery link may last, in hours. Floating-point values are allowed. Defaults to 2 hours.
* `UPLOAD_DOCUMENT_MAX_SIZE`: Maximum document size allowed to be uploaded to the library, in megabytes. Set this to 0 to unlimit upload size. Defaults to 20 megabytes.
* `FQDN`: Domain name of the server. If Coreander is listening to a non-standard HTTP / HTTPS port, include it using a colon (e. g. example.com:3000). Defaults to `localhost`.
Run `coreander -h` or `coreander --help` to see help.

In case both a flag and its equivalent environment variable are passed, flag takes precendence.

|Flag|Environment variable|Description|
|----|--------------------|-----------|
|`--lib-path` |`LIB_PATH` | Absolute path to the folder containing the documents.
|`-p` or `--port` |`PORT` | Port number in which the webserver listens for requests. Defaults to 3000.
|`-b` or `--batch-size` |`BATCH_SIZE` | Number of documents persisted by the indexer in one write operation. Defaults to 100.
|`--cover-max-width` |`COVER_MAX_WIDTH` | Maximum horizontal size for documents cover thumbnails in pixels. Defaults to 600.
|`-f` or `--force-indexing` |`FORCE_INDEXING` | Whether to force indexing already indexed documents or not. Defaults to false.
|`--smtp-server` |`SMTP_SERVER` | Address of the send mail server.
|`--smtp-port` |`SMTP_PORT` | Port number of the send mail server. Defaults to 587.
|`--smtp-user` |`SMTP_USER` | User to authenticate against the SMTP server.
|`--smtp-password` |`SMTP_PASSWORD` | User's password to authenticate against the SMTP server.
|`-s` or `--jwt-secret` |`JWT_SECRET` | String to use to sign JWTs.
|`-a` or `--require-auth` |`REQUIRE_AUTH` | Require authentication to access the application if true. Defaults to false.
|`--min-password-length` |`MIN_PASSWORD_LENGTH` | Minimum length acceptable for passwords. Defaults to 5.
|`--words-per-minute` |`WORDS_PER_MINUTE` | Defines a default words per minute reading speed that will be used for not logged-in users. Defaults to 250.
|`--session-timeout` |`SESSION_TIMEOUT` | Specifies the maximum time a user session may last, in hours. Floating-point values are allowed. Defaults to 24 hours.
|`--recovery-timeout` |`RECOVERY_TIMEOUT` | Specifies the maximum time a user recovery link may last, in hours. Floating-point values are allowed. Defaults to 2 hours.
|`-u` or `--upload-document-max-size` |`UPLOAD_DOCUMENT_MAX_SIZE`| Maximum document size allowed to be uploaded to the library, in megabytes. Set this to 0 to unlimit upload size. Defaults to 20 megabytes.
|`-d` or `--fqdn` |`FQDN` | Domain name of the server. If Coreander is listening to a non-standard HTTP / HTTPS port, include it using a colon (e. g. example.com:3000). Defaults to `localhost`.
|`-v` or `--version` | | Show version number.


## Screenshots

Expand All @@ -139,4 +149,4 @@ On first run, Coreander creates an admin user with the following credentials:
![Document detail in dark mode](doc-detail.png)
*Document detail in dark mode*
![Reading interface](reading.png)
*Reading interface*
*Reading interface*
36 changes: 18 additions & 18 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,38 @@ package main
// Config stores the application configuration
type Config struct {
// LibPath holds the absolute path to the folder containing the documents
LibPath string `env:"LIB_PATH" env-required:"true"`
// FQDN stores the domain name of the server. If the server is listening on a non-standard HTTP / HTTPS port, include it using a colon (e. g. :3000)
FQDN string `env:"FQDN" env-default:"localhost"`
LibPath string `arg:"" env:"LIB_PATH" help:"Absolute path to the folder containing the documents." type:"path"`
// FQDN stores the domain name of the server. If the server is listening on a non-standard HTTP / HTTPS port, include it using a colon (e. g. example.com:3000)
FQDN string `env:"FQDN" short:"d" default:"localhost" name:"fqdn" help:"Domain name of the server. If the server is listening on a non-standard HTTP / HTTPS port, include it using a colon (e. g. example:3000)"`
// Port defines the port number in which the webserver listens for requests
Port int `env:"PORT" env-default:"3000"`
Port int `env:"PORT" short:"p" default:"3000" help:"Port number in which the webserver listens for requests"`
// BatchSize indicates the number of documents persisted by the indexer in one operation
BatchSize int `env:"BATCH_SIZE" env-default:"100"`
BatchSize int `env:"BATCH_SIZE" short:"b" default:"100" name:"batch-size" help:"Number of documents persisted by the indexer in one operation"`
// CoverMaxWidth sets the maximum horizontal size for documents cover thumbnails in pixels
CoverMaxWidth int `env:"COVER_MAX_WIDTH" env-default:"600"`
CoverMaxWidth int `env:"COVER_MAX_WIDTH" default:"600" name:"cover-max-width" help:"Maximum horizontal size for documents cover thumbnails in pixels"`
// ForceIndexing signals whether to force indexing already indexed documents or not
ForceIndexing bool `env:"FORCE_INDEXING" env-default:"false"`
ForceIndexing bool `env:"FORCE_INDEXING" short:"f" default:"false" name:"force-indexing" help:"Force indexing already indexed documents"`
// SmtpServer points to the address of the send mail server
SmtpServer string `env:"SMTP_SERVER"`
SmtpServer string `env:"SMTP_SERVER" name:"smtp-server" help:"Address of the send mail server"`
// SmtpPort defines the port in which the mail server listens for requests
SmtpPort int `env:"SMTP_PORT" env-default:"587"`
SmtpPort int `env:"SMTP_PORT" default:"587" name:"smtp-port" help:"Port in which the mail server listens for requests"`
// SmtpUser holds the user to authenticate against the SMTP server
SmtpUser string `env:"SMTP_USER"`
SmtpUser string `env:"SMTP_USER" name:"smtp-user" help:"User to authenticate against the SMTP server"`
// SmtpUser holds the password to authenticate against the SMTP server
SmtpPassword string `env:"SMTP_PASSWORD"`
SmtpPassword string `env:"SMTP_PASSWORD" name:"smtp-password" help:"Password to authenticate against the SMTP server"`
// JwtSecret stores the string to use to sign JWTs
JwtSecret []byte `env:"JWT_SECRET"`
JwtSecret string `env:"JWT_SECRET" short:"s" name:"jwt-secret" help:"String to use to sign JWTs"`
// RequireAuth is a switch to enable the application to require authentication to access any route if true
RequireAuth bool `env:"REQUIRE_AUTH" env-default:"false"`
RequireAuth bool `env:"REQUIRE_AUTH" short:"a" default:"false" name:"require-auth" help:"Require authentication to access any route"`
// MinPasswordLength is the minimum length acceptable for passwords
MinPasswordLength int `env:"MIN_PASSWORD_LENGTH" env-default:"5"`
MinPasswordLength int `env:"MIN_PASSWORD_LENGTH" default:"5" name:"min-password-length" help:"Minimum length acceptable for passwords"`
// WordsPerMinute defines a default words per minute reading speed that will be used for not logged-in users
WordsPerMinute float64 `env:"WORDS_PER_MINUTE" env-default:"250"`
WordsPerMinute float64 `env:"WORDS_PER_MINUTE" default:"250" name:"words-per-minute" help:"Default words per minute reading speed that will be used for not logged-in users"`
// SessionTimeout specifies the maximum time a user session may last in hours
SessionTimeout float64 `env:"SESSION_TIMEOUT" env-default:"24"`
SessionTimeout float64 `env:"SESSION_TIMEOUT" default:"24" name:"session-timeout" help:"Maximum time a user session may last in hours"`
// RecoveryTimeout specifies the maximum time a user recovery link may last in hours
RecoveryTimeout float64 `env:"RECOVERY_TIMEOUT" env-default:"2"`
RecoveryTimeout float64 `env:"RECOVERY_TIMEOUT" default:"2" name:"recovery-timeout" help:"Maximum time a user recovery link may last in hours"`
// UploadDocumentMaxSize is the maximum document size allowed to be uploaded to the library, in megabytes.
// Set this to 0 to unlimit upload size. Defaults to 20 megabytes.
UploadDocumentMaxSize int `env:"UPLOAD_DOCUMENT_MAX_SIZE" env-default:"20"`
UploadDocumentMaxSize int `env:"UPLOAD_DOCUMENT_MAX_SIZE" short:"u" default:"20" name:"upload-document-max-size" help:"Maximum document size allowed to be uploaded to the library, in megabytes. Set this to 0 to unlimit upload size."`
}
6 changes: 1 addition & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.23
toolchain go1.23.0

require (
github.com/alecthomas/kong v1.6.1
github.com/blevesearch/bleve/v2 v2.4.4
github.com/bmatcuk/doublestar/v4 v4.7.1
github.com/glebarez/sqlite v1.11.0
Expand All @@ -14,7 +15,6 @@ require (
github.com/golang-jwt/jwt/v4 v4.5.1
github.com/google/uuid v1.6.0
github.com/hhrutter/tiff v1.0.1
github.com/ilyakaznacheev/cleanenv v1.5.0
github.com/kovidgoyal/imaging v1.6.3
github.com/magefile/mage v1.15.0
github.com/microcosm-cc/bluemonday v1.0.27
Expand Down Expand Up @@ -60,7 +60,6 @@ require (
)

require (
github.com/BurntSushi/toml v1.4.0 // indirect
github.com/PuerkitoBio/goquery v1.10.1
github.com/RoaringBitmap/roaring v1.9.4 // indirect
github.com/andybalholm/brotli v1.1.1 // indirect
Expand All @@ -87,7 +86,6 @@ require (
github.com/golang/snappy v0.0.4 // indirect
github.com/gorilla/css v1.0.1 // indirect
github.com/gosimple/slug v1.15.0
github.com/joho/godotenv v1.5.1 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.11 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
Expand All @@ -108,6 +106,4 @@ require (
golang.org/x/sys v0.29.0 // indirect
google.golang.org/protobuf v1.36.2 // indirect
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
gopkg.in/yaml.v3 v3.0.1 // indirect
olympos.io/encoding/edn v0.0.0-20201019073823-d3554ca0b0a3 // indirect
)
16 changes: 7 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0=
github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
github.com/PuerkitoBio/goquery v1.10.1 h1:Y8JGYUkXWTGRB6Ars3+j3kN0xg1YqqlwvdTV8WTFQcU=
github.com/PuerkitoBio/goquery v1.10.1/go.mod h1:IYiHrOMps66ag56LEH7QYDDupKXyo5A8qrjIx3ZtujY=
github.com/RoaringBitmap/roaring v1.9.4 h1:yhEIoH4YezLYT04s1nHehNO64EKFTop/wBhxv2QzDdQ=
github.com/RoaringBitmap/roaring v1.9.4/go.mod h1:6AXUsoIEzDTFFQCe1RbGA6uFONMhvejWj5rqITANK90=
github.com/alecthomas/assert/v2 v2.11.0 h1:2Q9r3ki8+JYXvGsDyBXwH3LcJ+WK5D0gc5E8vS6K3D0=
github.com/alecthomas/assert/v2 v2.11.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k=
github.com/alecthomas/kong v1.6.1 h1:/7bVimARU3uxPD0hbryPE8qWrS3Oz3kPQoxA/H2NKG8=
github.com/alecthomas/kong v1.6.1/go.mod h1:p2vqieVMeTAnaC83txKtXe8FLke2X07aruPWXyMPQrU=
github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc=
github.com/alecthomas/repr v0.4.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
github.com/andybalholm/brotli v1.1.1 h1:PR2pgnyFznKEugtsUo0xLdDop5SKXd5Qf5ysW+7XdTA=
github.com/andybalholm/brotli v1.1.1/go.mod h1:05ib4cKhjx3OQYUY22hTVd34Bc8upXjOLL2rKwwZBoA=
Expand Down Expand Up @@ -106,19 +109,16 @@ github.com/gosimple/slug v1.15.0 h1:wRZHsRrRcs6b0XnxMUBM6WK1U1Vg5B0R7VkIf1Xzobo=
github.com/gosimple/slug v1.15.0/go.mod h1:UiRaFH+GEilHstLUmcBgWcI42viBN7mAb818JrYOeFQ=
github.com/gosimple/unidecode v1.0.1 h1:hZzFTMMqSswvf0LBJZCZgThIZrpDHFXux9KeGmn6T/o=
github.com/gosimple/unidecode v1.0.1/go.mod h1:CP0Cr1Y1kogOtx0bJblKzsVWrqYaqfNOnHzpgWw4Awc=
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
github.com/hhrutter/lzw v1.0.0 h1:laL89Llp86W3rRs83LvKbwYRx6INE8gDn0XNb1oXtm0=
github.com/hhrutter/lzw v1.0.0/go.mod h1:2HC6DJSn/n6iAZfgM3Pg+cP1KxeWc3ezG8bBqW5+WEo=
github.com/hhrutter/tiff v1.0.1 h1:MIus8caHU5U6823gx7C6jrfoEvfSTGtEFRiM8/LOzC0=
github.com/hhrutter/tiff v1.0.1/go.mod h1:zU/dNgDm0cMIa8y8YwcYBeuEEveI4B0owqHyiPpJPHc=
github.com/ilyakaznacheev/cleanenv v1.5.0 h1:0VNZXggJE2OYdXE87bfSSwGxeiGt9moSR2lOrsHHvr4=
github.com/ilyakaznacheev/cleanenv v1.5.0/go.mod h1:a5aDzaJrLCQZsazHol1w8InnDcOX0OColm64SlIi6gk=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/klauspost/compress v1.16.3/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
Expand Down Expand Up @@ -369,5 +369,3 @@ modernc.org/strutil v1.2.0 h1:agBi9dp1I+eOnxXeiZawM8F4LawKv4NzGWSaLfyeNZA=
modernc.org/strutil v1.2.0/go.mod h1:/mdcBmfOibveCTBxUl5B5l6W+TTH1FXPLHZE6bTosX0=
modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=
modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
olympos.io/encoding/edn v0.0.0-20201019073823-d3554ca0b0a3 h1:slmdOY3vp8a7KQbHkL+FLbvbkgMqmXojpFUO/jENuqQ=
olympos.io/encoding/edn v0.0.0-20201019073823-d3554ca0b0a3/go.mod h1:oVgVk4OWVDi43qWBEyGhXgYxt7+ED4iYNpTngSLX2Iw=
Loading
Loading