Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
ouuan committed Jan 17, 2024
2 parents 6e67558 + 1ea64f0 commit 15b5f26
Show file tree
Hide file tree
Showing 55 changed files with 1,807 additions and 727 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
strategy:
fail-fast: false
matrix:
db: [sqlite, postgres, mysql, mariadb]
db: [sqlite, postgres, mysql, mariadb, mssql]

steps:
- name: Check out code into the Go module directory
Expand Down
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ Optionally, you can set up a [client-side proxy](https://github.com/muety/wakapi
You can specify configuration options either via a config file (default: `config.yml`, customizable through the `-c` argument) or via environment variables. Here is an overview of all options.

| YAML key / Env. variable | Default | Description |
|------------------------------------------------------------------------------|--------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ---------------------------------------------------------------------------- | ------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `env` /<br>`ENVIRONMENT` | `dev` | Whether to use development- or production settings |
| `app.leaderboard_enabled` /<br>`WAKAPI_LEADERBOARD_ENABLED` | `true` | Whether to enable the public leaderboard |
| `app.leaderboard_scope` /<br>`WAKAPI_LEADERBOARD_SCOPE` | `7_days` | Aggregation interval for public leaderboard (see [here](https://github.com/muety/wakapi/blob/7d156cd3edeb93af2997bd95f12933b0aabef0c9/config/config.go#L71) for allowed values) |
Expand Down Expand Up @@ -173,7 +173,7 @@ You can specify configuration options either via a config file (default: `config
| `db.user` /<br> `WAKAPI_DB_USER` | - | Database user |
| `db.password` /<br> `WAKAPI_DB_PASSWORD` | - | Database password |
| `db.name` /<br> `WAKAPI_DB_NAME` | `wakapi_db.db` | Database name |
| `db.dialect` /<br> `WAKAPI_DB_TYPE` | `sqlite3` | Database type (one of `sqlite3`, `mysql`, `postgres`, `cockroach`) |
| `db.dialect` /<br> `WAKAPI_DB_TYPE` | `sqlite3` | Database type (one of `sqlite3`, `mysql`, `postgres`, `cockroach`, `mssql`) |
| `db.charset` /<br> `WAKAPI_DB_CHARSET` | `utf8mb4` | Database connection charset (for MySQL only) |
| `db.max_conn` /<br> `WAKAPI_DB_MAX_CONNECTIONS` | `2` | Maximum number of database connections |
| `db.ssl` /<br> `WAKAPI_DB_SSL` | `false` | Whether to use TLS encryption for database connection (Postgres and CockroachDB only) |
Expand Down Expand Up @@ -202,6 +202,7 @@ Wakapi uses [GORM](https://gorm.io) as an ORM. As a consequence, a set of differ
* [MariaDB](https://hub.docker.com/_/mariadb) (_open-source MySQL alternative_)
* [Postgres](https://hub.docker.com/_/postgres) (_open-source as well_)
* [CockroachDB](https://www.cockroachlabs.com/docs/stable/install-cockroachdb-linux.html) (_cloud-native, distributed, Postgres-compatible API_)
* [Microsoft SQL Server](https://hub.docker.com/_/microsoft-mssql-server) (_Microsoft SQL Server_)

## 🔐 Authentication
Wakapi supports different types of user authentication.
Expand Down Expand Up @@ -499,6 +500,13 @@ It is unclear how to handle the three minutes in between. Did the developer do a
Wakapi adds a "padding" of two minutes before the third heartbeat. This is why total times will slightly vary between Wakapi and WakaTime.
</details>

## 👥 Community contributions
* 💻 [Code] Image generator from Wakapi stats – [LacazeThomas/wakapi-stats](https://github.com/LacazeThomas/wakapi-stats) (`Go`)
* 💻 [Code] Discord integration for Wakapi - [LLoneDev6/Wakapi-Discord](https://github.com/LoneDev6/Wakapi-Discord) (`JavaScript`)
* 💻 [Code] Alternative heartbeats export script - [wakapiexporter.nim](https://github.com/theAkito/mini-tools-nim/tree/master/generic/web/wakapiexporter) (`Nim`)
* 💻 [Code] Wakapi Helm chart for K8s deployments - [andreymaznyak/wakapi-helm-chart](https://github.com/andreymaznyak/wakapi-helm-chart) (`YAML`)
* 🗒 [Article] [Wakamonth: hours reporting tool](https://bitstillery.com/2024/01/09/wakamonth-hours-reporting-tool/)

## 👏 Support

Coding in open source is my passion and I would love to do it on a full-time basis and make a living from it one day. So if you like this project, please consider supporting it 🙂. You can donate either through [buying me a coffee](https://buymeacoff.ee/n1try) or becoming a GitHub sponsor. Every little donation is highly appreciated and boosts my motivation to keep improving Wakapi!
Expand Down
4 changes: 2 additions & 2 deletions config.default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ db:
user: # leave blank when using sqlite3
password: # leave blank when using sqlite3
name: wakapi_db.db # database name for mysql / postgres or file path for sqlite (e.g. /tmp/wakapi.db)
dialect: sqlite3 # mysql, postgres, sqlite3
dialect: sqlite3 # mysql, postgres, sqlite3, mssql
charset: utf8mb4 # only used for mysql connections
max_conn: 2 # maximum number of concurrent connections to maintain
ssl: false # whether to use tls for db connection (must be true for cockroachdb) (ignored for mysql and sqlite)
ssl: false # whether to use tls for db connection (must be true for cockroachdb) (ignored for mysql and sqlite) (true means encrypt=true in mssql)
automigrate_fail_silently: false # whether to ignore schema auto-migration failures when starting up

security:
Expand Down
8 changes: 7 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package config
import (
"encoding/json"
"fmt"
"github.com/duke-git/lancet/v2/slice"
"net"
"net/http"
"os"
Expand All @@ -12,6 +11,8 @@ import (
"strings"
"time"

"github.com/duke-git/lancet/v2/slice"

"github.com/emvi/logbuch"
"github.com/gorilla/securecookie"
"github.com/jinzhu/configor"
Expand All @@ -27,6 +28,7 @@ const (
SQLDialectMysql = "mysql"
SQLDialectPostgres = "postgres"
SQLDialectSqlite = "sqlite3"
SQLDialectMssql = "mssql"

KeyLatestTotalTime = "latest_total_time"
KeyLatestTotalUsers = "latest_total_users"
Expand Down Expand Up @@ -340,6 +342,10 @@ func (c *dbConfig) IsPostgres() bool {
return c.Dialect == "postgres"
}

func (c *dbConfig) IsMssql() bool {
return c.Dialect == SQLDialectMssql
}

func (c *serverConfig) GetPublicUrl() string {
return strings.TrimSuffix(c.PublicUrl, "/")
}
Expand Down
16 changes: 16 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,19 @@ func Test_sqliteConnectionString(t *testing.T) {
}
assert.Equal(t, c.Name, sqliteConnectionString(c))
}

func Test_mssqlConnectionString(t *testing.T) {
c := &dbConfig{
Name: "dbinstance",
Host: "test_host",
Port: 1433,
User: "test_user",
Password: "test_password",
Dialect: "mssql",
Ssl: true,
}

assert.Equal(t,
"sqlserver://test_user:test_password@test_host:1433?database=dbinstance&encrypt=true",
mssqlConnectionString(c))
}
25 changes: 25 additions & 0 deletions config/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package config

import (
"fmt"
"net/url"

"github.com/glebarez/sqlite"
"gorm.io/driver/mysql"
"gorm.io/driver/postgres"
"gorm.io/driver/sqlserver"
"gorm.io/gorm"
)

Expand Down Expand Up @@ -50,7 +52,10 @@ func (c *dbConfig) GetDialector() gorm.Dialector {
})
case SQLDialectSqlite:
return sqlite.Open(sqliteConnectionString(c))
case SQLDialectMssql:
return sqlserver.Open(mssqlConnectionString(c))
}

return nil
}

Expand Down Expand Up @@ -98,3 +103,23 @@ func postgresConnectionString(config *dbConfig) string {
func sqliteConnectionString(config *dbConfig) string {
return config.Name
}

func mssqlConnectionString(config *dbConfig) string {

query := url.Values{}

query.Add("database", config.Name)

if config.Ssl {
query.Add("encrypt", "true")
}

u := &url.URL{
Scheme: "sqlserver",
User: url.UserPassword(config.User, config.Password),
Host: fmt.Sprintf("%s:%d", config.Host, config.Port),
RawQuery: query.Encode(),
}

return u.String()
}
Loading

0 comments on commit 15b5f26

Please sign in to comment.