Skip to content
Closed
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
37 changes: 37 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

name: Go tests

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch: {}

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: '1.24'

- name: Cache Go modules
uses: actions/cache@v4
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-

- name: Install dependencies
run: go mod download

- name: Run tests
run: go test ./... -v
5 changes: 4 additions & 1 deletion cmd/server/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ DB_HOST=
DB_USER=
DB_PASSWORD=
DB_NAME=
DB_PORT=
DB_PORT=
PORT=
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
Comment on lines +5 to +8
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Add missing COOKIE_SESSION_KEY environment variable.

The cmd/server/main.go requires COOKIE_SESSION_KEY for auth.NewAuth(), but it's not documented in this example file.

📝 Proposed addition
 DB_PORT=
 PORT=
+COOKIE_SESSION_KEY=
 GOOGLE_CLIENT_ID=
 GOOGLE_CLIENT_SECRET=
🧰 Tools
🪛 dotenv-linter (4.0.0)

[warning] 5-5: [UnorderedKey] The DB_PORT key should go before the DB_USER key

(UnorderedKey)


[warning] 7-7: [UnorderedKey] The GOOGLE_CLIENT_ID key should go before the PORT key

(UnorderedKey)


[warning] 8-8: [EndingBlankLine] No blank line at the end of the file

(EndingBlankLine)


[warning] 8-8: [UnorderedKey] The GOOGLE_CLIENT_SECRET key should go before the PORT key

(UnorderedKey)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmd/server/.env.example` around lines 5 - 8, The .env.example is missing the
COOKIE_SESSION_KEY variable required by auth.NewAuth() in cmd/server/main.go;
add a line "COOKIE_SESSION_KEY=" to the example file and include a short comment
if desired explaining it's a random secret used for session signing so reviewers
know to set a secure value before running the server.

38 changes: 32 additions & 6 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,54 @@ package main

import (
"fmt"
"log"
"os"

"github.com/gin-gonic/gin"
"github.com/jasutiin/envlink/internal/server/auth"
"github.com/jasutiin/envlink/internal/server/api/auth"
"github.com/jasutiin/envlink/internal/server/api/projects"
"github.com/jasutiin/envlink/internal/server/api/pull"
"github.com/jasutiin/envlink/internal/server/api/push"
"github.com/jasutiin/envlink/internal/server/database"
"github.com/jasutiin/envlink/internal/server/projects"
"github.com/jasutiin/envlink/internal/server/pull"
"github.com/jasutiin/envlink/internal/server/push"
"github.com/joho/godotenv"
)

func main() {
err := godotenv.Load()
if err != nil {
log.Println("No .env file found, using environment variables directly")
}

port := os.Getenv("PORT")
if port == "" {
log.Fatalf("Port was not provided!")
}

server := gin.Default()
api := server.Group("/api/v1")
db := database.CreateDB()
database.AutoMigrate(db) // creates tables if they don't exist

// empty RAILWAY_ENVIRONMENT_NAME means dev environment, otherwise production
isProd := os.Getenv("RAILWAY_ENVIRONMENT_NAME") != ""

key := os.Getenv("COOKIE_SESSION_KEY")
if key == "" {
log.Fatalf("COOKIE_SESSION_KEY is required")
}

domain := os.Getenv("RAILWAY_PUBLIC_DOMAIN")

err = auth.NewAuth(port, domain, key, isProd)
if err != nil {
log.Fatalf("Failed to initialize auth: %s", err)
}

auth.AuthRouter(api, db)
push.PushRouter(api)
pull.PullRouter(api)
projects.ProjectsRouter(api)

port := os.Getenv("PORT")
fmt.Printf("listening on port %s", port)
server.Run("0.0.0.0:" + port)
};
}
8 changes: 8 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,33 @@ go 1.24.4

require (
github.com/gin-gonic/gin v1.11.0
github.com/gorilla/sessions v1.4.0
github.com/joho/godotenv v1.5.1
github.com/markbates/goth v1.82.0
github.com/spf13/cobra v1.10.2
github.com/spf13/viper v1.21.0
gorm.io/driver/postgres v1.6.0
gorm.io/gorm v1.31.1
)

require (
cloud.google.com/go/compute/metadata v0.3.0 // indirect
github.com/bytedance/sonic v1.14.0 // indirect
github.com/bytedance/sonic/loader v0.3.0 // indirect
github.com/cloudwego/base64x v0.1.6 // indirect
github.com/fsnotify/fsnotify v1.9.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.8 // indirect
github.com/gin-contrib/sse v1.1.0 // indirect
github.com/go-chi/chi/v5 v5.2.2 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.27.0 // indirect
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/goccy/go-yaml v1.18.0 // indirect
github.com/gorilla/context v1.1.1 // indirect
github.com/gorilla/mux v1.6.2 // indirect
github.com/gorilla/securecookie v1.1.2 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
Expand Down Expand Up @@ -54,6 +61,7 @@ require (
golang.org/x/crypto v0.40.0 // indirect
golang.org/x/mod v0.26.0 // indirect
golang.org/x/net v0.42.0 // indirect
golang.org/x/oauth2 v0.27.0 // indirect
golang.org/x/sync v0.16.0 // indirect
golang.org/x/sys v0.35.0 // indirect
golang.org/x/text v0.28.0 // indirect
Expand Down
22 changes: 20 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
cloud.google.com/go/compute/metadata v0.3.0 h1:Tz+eQXMEqDIKRsmY3cHTL6FVaynIjX2QxYC4trgAKZc=
cloud.google.com/go/compute/metadata v0.3.0/go.mod h1:zFmK7XCadkQkj6TtorcaGlCW1hT1fIilQDwofLpJ20k=
github.com/bytedance/sonic v1.14.0 h1:/OfKt8HFw0kh2rj8N0F6C/qPGRESq0BbaNZgcNXXzQQ=
github.com/bytedance/sonic v1.14.0/go.mod h1:WoEbx8WTcFJfzCe0hbmyTGrfjt8PzNEBdxlNUO24NhA=
github.com/bytedance/sonic/loader v0.3.0 h1:dskwH8edlzNMctoruo8FPTJDF3vLtDT0sXZwvZJyqeA=
Expand All @@ -18,6 +20,8 @@ github.com/gin-contrib/sse v1.1.0 h1:n0w2GMuUpWDVp7qSpvze6fAu9iRxJY4Hmj6AmBOU05w
github.com/gin-contrib/sse v1.1.0/go.mod h1:hxRZ5gVpWMT7Z0B0gSNYqqsSCNIJMjzvm6fqCz9vjwM=
github.com/gin-gonic/gin v1.11.0 h1:OW/6PLjyusp2PPXtyxKHU0RbX6I/l28FTdDlae5ueWk=
github.com/gin-gonic/gin v1.11.0/go.mod h1:+iq/FyxlGzII0KHiBGjuNn4UNENUlKbGlNmc+W50Dls=
github.com/go-chi/chi/v5 v5.2.2 h1:CMwsvRVTbXVytCk1Wd72Zy1LAsAh9GxMmSNWLHCG618=
github.com/go-chi/chi/v5 v5.2.2/go.mod h1:L2yAIGWB3H+phAw1NxKwWM+7eUH/lU8pOMm5hHcoops=
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
Expand All @@ -35,6 +39,16 @@ github.com/goccy/go-yaml v1.18.0/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7Lk
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/gorilla/context v1.1.1 h1:AWwleXJkX/nhcU9bZSnZoi3h/qGYqQAGhq6zZe/aQW8=
github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
github.com/gorilla/mux v1.6.2 h1:Pgr17XVTNXAk3q/r4CpKzC5xBM/qW1uVLV+IhRZpIIk=
github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/gorilla/securecookie v1.1.2 h1:YCIWL56dvtr73r6715mJs5ZvhtnY73hBvEF8kXD8ePA=
github.com/gorilla/securecookie v1.1.2/go.mod h1:NfCASbcHqRSY+3a8tlWJwsQap2VX5pwzwo4h3eOamfo=
github.com/gorilla/sessions v1.4.0 h1:kpIYOp/oi6MG/p5PgxApU8srsSw9tuFbt46Lt7auzqQ=
github.com/gorilla/sessions v1.4.0/go.mod h1:FLWm50oby91+hl7p/wRxDth9bWSuk0qVL2emc7lT5ik=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
Expand All @@ -61,6 +75,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
github.com/markbates/goth v1.82.0 h1:8j/c34AjBSTNzO7zTsOyP5IYCQCMBTRBHAbBt/PI0bQ=
github.com/markbates/goth v1.82.0/go.mod h1:/DRlcq0pyqkKToyZjsL2KgiA1zbF1HIjE7u2uC79rUk=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
Expand All @@ -75,8 +91,8 @@ github.com/quic-go/qpack v0.5.1 h1:giqksBPnT/HDtZ6VhtFKgoLOWmlyo9Ei6u9PqzIMbhI=
github.com/quic-go/qpack v0.5.1/go.mod h1:+PC4XFrEskIVkcLzpEkbLqq1uCoxPhQuvK5rH1ZgaEg=
github.com/quic-go/quic-go v0.54.0 h1:6s1YB9QotYI6Ospeiguknbp2Znb/jZYjZLRXn9kMQBg=
github.com/quic-go/quic-go v0.54.0/go.mod h1:e68ZEaCdyviluZmy44P6Iey98v/Wfz6HCjQEm+l8zTY=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sagikazarmark/locafero v0.11.0 h1:1iurJgmM9G3PA/I+wWYIOw/5SyBtxapeHDcg+AAIFXc=
github.com/sagikazarmark/locafero v0.11.0/go.mod h1:nVIGvgyzw595SUSUE6tvCp3YYTeHs15MvlmU87WwIik=
Expand Down Expand Up @@ -121,6 +137,8 @@ golang.org/x/mod v0.26.0 h1:EGMPT//Ezu+ylkCijjPc+f4Aih7sZvaAr+O3EHBxvZg=
golang.org/x/mod v0.26.0/go.mod h1:/j6NAhSk8iQ723BGAUyoAcn7SlD7s15Dp9Nd/SfeaFQ=
golang.org/x/net v0.42.0 h1:jzkYrhi3YQWD6MLBJcsklgQsoAcw89EcZbJw8Z614hs=
golang.org/x/net v0.42.0/go.mod h1:FF1RA5d3u7nAYA4z2TkclSCKh68eSXtiFwcWQpPXdt8=
golang.org/x/oauth2 v0.27.0 h1:da9Vo7/tDv5RH/7nZDz1eMGS/q1Vv1N/7FCrBhI9I3M=
golang.org/x/oauth2 v0.27.0/go.mod h1:onh5ek6nERTohokkhCD/y2cV4Do3fxFHFuAejCkRWT8=
golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw=
golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down
8 changes: 2 additions & 6 deletions internal/cli/login.go → internal/cli/commands/login.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cli
package commands

import (
"bytes"
Expand All @@ -10,11 +10,7 @@ import (
"github.com/spf13/cobra"
)

func init() {
rootCmd.AddCommand(loginCmd)
}

var loginCmd = &cobra.Command{
var LoginCmd = &cobra.Command{
Use: "login",
Short: "Login to envlink.",
Long: `Login to envlink.`,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package cli
package commands

import (
"fmt"

"github.com/spf13/cobra"
)

func init() {
rootCmd.AddCommand(projectsCmd)
}

var projectsCmd = &cobra.Command{
var ProjectsCmd = &cobra.Command{
Use: "projects",
Short: "Lists all the .envs you have stored.",
Long: `Lists all the .envs you have stored.`,
Expand Down
8 changes: 2 additions & 6 deletions internal/cli/pull.go → internal/cli/commands/pull.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package cli
package commands

import (
"fmt"

"github.com/spf13/cobra"
)

func init() {
rootCmd.AddCommand(pullCmd)
}

var pullCmd = &cobra.Command{
var PullCmd = &cobra.Command{
Use: "pull",
Short: "Pulls the project's latest changes to the .env file.",
Long: `Pulls the project's latest changes to the .env file. It will update your local .env whether it is new or not.`,
Expand Down
8 changes: 2 additions & 6 deletions internal/cli/push.go → internal/cli/commands/push.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package cli
package commands

import (
"fmt"

"github.com/spf13/cobra"
)

func init() {
rootCmd.AddCommand(pushCmd)
}

var pushCmd = &cobra.Command{
var PushCmd = &cobra.Command{
Use: "push",
Short: "Pushes your project's .env to the database.",
Long: `Pushes your project's .env to the database. It will update the entry whether there are new changes or not.`,
Expand Down
Loading
Loading