Skip to content
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
87 changes: 63 additions & 24 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,64 @@
{
"name": "Go",
"image": "mcr.microsoft.com/devcontainers/go:1.25-bookworm",
"runArgs": [
"--add-host=host.docker.internal:host-gateway"
],
"customizations": {
"vscode": {
"extensions": [
"streetsidesoftware.code-spell-checker",
"golang.go",
"DavidAnson.vscode-markdownlint"
]
}
},
"mounts": [
{
"source": "${localEnv:HOME}/.ssh",
"target": "/home/vscode/.ssh",
"type": "bind"
}
],
"remoteUser": "vscode",
"postCreateCommand": "curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin latest"
}
"name": "Go",
"image": "mcr.microsoft.com/devcontainers/go:1.25-bookworm",
"features": {
"ghcr.io/devcontainers-extra/features/mise:1": {},
"ghcr.io/roul/devcontainer-features/mise-golang:1": {
"version": "1.25.3"
}
},
"runArgs": ["--add-host=host.docker.internal:host-gateway"],
"customizations": {
"vscode": {
"extensions": [
"DavidAnson.vscode-markdownlint",
"golang.go",
"hverlin.mise-vscode",
"streetsidesoftware.code-spell-checker",
"EditorConfig.EditorConfig",
"tamasfe.even-better-toml",
"timonwong.shellcheck",
"/workspaces/magic/.devcontainer/extensions/pkl-vscode-0.21.0.vsix"
],
"settings": {
"go.testFlags": ["-v", "-race"],
"go.coverOnSingleTest": true,
"go.coverOnSingleTestFile": true,
"go.coverOnTestPackage": true,
"go.lintTool": "golangci-lint",
"go.lintOnSave": "package",
"[go]": {
"editor.codeActionsOnSave": {
"source.organizeImports": "always"
}
},
"gopls": {
"usePlaceholders": false,
"staticcheck": true,
"formatting.gofumpt": true
},
"editor.rulers": [120, 180]
}
}
},
"mounts": [
{
"source": "${localEnv:HOME}/.ssh",
"target": "/home/vscode/.ssh",
"type": "bind"
},
{
"source": "mise-data-volume",
"target": "/mnt/mise-data",
"type": "volume"
}
],
"containerEnv": {
"MISE_DATA_DIR": "/mnt/mise-data"
},
"remoteEnv": {
"PATH": "${containerEnv:PATH}:/mnt/mise-data/shims"
},
"remoteUser": "vscode",
"postCreateCommand": "bash .devcontainer/post-create.sh"
}
Binary file added .devcontainer/extensions/pkl-vscode-0.21.0.vsix
Binary file not shown.
15 changes: 15 additions & 0 deletions .devcontainer/post-create.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/env bash

set -e

sudo chown -R vscode:vscode /mnt/mise-data
curl -fsSL https://deb.nodesource.com/setup_25.x |\
DEBIAN_FRONTEND=noninteractive sudo -E bash -
sudo apt install -y -qq \
nodejs \
npm \
python3.11-venv
node -v
npm -v
mise install -y
hk install
7 changes: 4 additions & 3 deletions .github/ISSUE_TEMPLATE/bug_report.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
---
name: Bug Report
description: Create a detailed bug report to help ups improve magic
title: 'issue: '
labels: ['bug', 'triage']
title: "issue: "
labels: ["bug", "triage"]
assignees: []
body:
- type: markdown
Expand Down Expand Up @@ -60,7 +61,7 @@ body:
attributes:
label: Logs & Screenshots
description: Include relevant logs, errors, screenshots, magic dust or anything that might help us identify the bug.
placeholder: 'Attach logs from the browser console or error messages.'
placeholder: "Attach logs from the browser console or error messages."
validations:
required: true

Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
---
blank_issues_enabled: false
6 changes: 3 additions & 3 deletions .github/ISSUE_TEMPLATE/feature_request.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
---
name: Feature Request
description: Suggest something new
title: 'feat: '
labels: ['triage']
title: "feat: "
labels: ["triage"]
body:
- type: markdown
attributes:
Expand Down Expand Up @@ -41,4 +42,3 @@ body:
attributes:
label: Additional Context
description: Add any other context or screenshots about the feature request here.

22 changes: 22 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: "2"
linters:
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
paths:
- third_party$
- builtin$
- examples$
formatters:
enable:
- gofumpt
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
2 changes: 1 addition & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
---
builds:
- skip: true

31 changes: 31 additions & 0 deletions .mise.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[tools]
"go:github.com/securego/gosec/v2/cmd/gosec" = "2.23.0"
"go:golang.org/x/tools/cmd/goimports" = "0.42.0"
"go:golang.org/x/vuln/cmd/govulncheck" = "1.1.4"
"go:mvdan.cc/gofumpt" = "0.9.2"
cspell = "9.6.4"
golang = "1.25.3"
golangci-lint = "2.10.1"
goreleaser = "2.13.3"
hk = "1.36.0"
java = 'corretto-25.0.2.10.1'
npm = "9.8.0"
pipx = "1.8.0"
pkl = "0.30.2"
shellcheck = "0.11.0"
yamllint = "1.38.0"
yq = "4.30.8"
zizmor = "1.22.0"

[env]
GOLANGCI_LINT_TIMEOUT = "5m"

[tasks.test]
env = {TEST_FLAGS = "-v -cover"}
run = "go test ./... ${TEST_FLAGS}"

[tasks.build]
run = "go build ./..."

[tasks.clean]
run = "go clean ./..."
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
"program": "main.go"
}
]
}
}
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
"tink"
],
"go.diagnostic.vulncheck": "Imports"
}
}
3 changes: 3 additions & 0 deletions .yamllint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
rules:
line-length: disable
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ Before submitting major changes, here are a few guidelines to follow:
2. Open an [issue](https://github.com/tink3rlabs/magic/issues) first, to discuss a new feature or enhancement.
3. Write tests, and make sure the test suite passes locally and on CI.
4. Open a pull request, and reference the relevant issue(s).
5. After receiving feedback, [squash](https://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html) your commits and add a [great commit message](https://www.freecodecamp.org/news/how-to-write-better-git-commit-messages/).
5. After receiving feedback, [squash](https://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html) your commits and add a [great commit message](https://www.freecodecamp.org/news/how-to-write-better-git-commit-messages/).
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
42 changes: 0 additions & 42 deletions Makefile

This file was deleted.

56 changes: 56 additions & 0 deletions hk.pkl
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
amends "package://github.com/jdx/hk/releases/download/v1.36.0/hk@1.36.0#/Config.pkl"
import "package://github.com/jdx/hk/releases/download/v1.36.0/hk@1.36.0#/Builtins.pkl"

local linters = new Mapping<String, Step> {
["shellcheck"] = Builtins.shellcheck
["golangci-lint"] = (Builtins.golangci_lint) {
// Run on the whole project instead of individual files
check = "golangci-lint run --fix=false ./..."
fix = "golangci-lint run --fix ./..."
// Disable batching since we aren't passing specific files anymore
batch = false
}
["yamllint"] = Builtins.yamllint
["mixed-line-ending"] = Builtins.mixed_line_ending
["end-of-line-fixer"] = Builtins.newlines
// ["go-sec"] = (Builtins.go_sec) {
// // Run on the whole project instead of individual files
// check = "gosec ./..."
// // Disable batching since we aren't passing specific files anymore
// batch = false
// }
// ["go-vet"] = (Builtins.go_vet) {
// // Run on the whole project instead of individual files
// check = "go vet ./..."
// // Disable batching since we aren't passing specific files anymore
// batch = false
// }
// ["go-vuln-check"] = (Builtins.go_vuln_check) {
// // Run on the whole project instead of individual files
// check = "govulncheck ./..."
// // Disable batching since we aren't passing specific files anymore
// batch = false
// }
// ["zizmor"] = Builtins.zizmor # Lint Github Actions workflows

// Or define custom steps:
// ["custom"] {
// glob = "**/*.py"
// check = "mypy {{ files }}"
// }
}

hooks {
["pre-commit"] {
fix = true
stash = "git"
steps = linters
}
["fix"] {
fix = true
steps = linters
}
["check"] {
steps = linters
}
}
18 changes: 11 additions & 7 deletions leadership/leadership.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ import (
"github.com/tink3rlabs/magic/storage"
)

var leaderElectionLock = &sync.Mutex{}
var leaderElectionInstance *LeaderElection
var (
leaderElectionLock = &sync.Mutex{}
leaderElectionInstance *LeaderElection
)

const RESULT_ELECTED = "elected"
const DEFAULT_HEARTBEAT = 60 * time.Second
const (
RESULT_ELECTED = "elected"
DEFAULT_HEARTBEAT = 60 * time.Second
)

// LeaderElection provides methods for electing a leader out of eligible cluster members
type LeaderElection struct {
Expand Down Expand Up @@ -61,7 +65,7 @@ func NewLeaderElection(props LeaderElectionProps) *LeaderElection {
if heartbeatInterval == 0 {
heartbeatInterval = DEFAULT_HEARTBEAT
}
var tableName = "members"
tableName := "members"
if (props.AdditionalProps["table_name"] != "") && (props.AdditionalProps["table_name"] != nil) {
tableName = props.AdditionalProps["table_name"].(string)
}
Expand Down Expand Up @@ -122,7 +126,8 @@ func (l *LeaderElection) createLeadershipTable() error {
} else {
waiter := dynamodb.NewTableExistsWaiter(a.DB)
err = waiter.Wait(context.TODO(), &dynamodb.DescribeTableInput{
TableName: aws.String(l.tableName)}, 1*time.Minute)
TableName: aws.String(l.tableName),
}, 1*time.Minute)
if err != nil {
return err
} else {
Expand Down Expand Up @@ -227,7 +232,6 @@ func (l *LeaderElection) monitorLeader() {
} else {
slog.Info("Starting re-election due to leader inactivity", slog.String("leader_id", l.Leader.Id), slog.Duration("inactivity_duration", diff))
err = l.electLeader(true)

if err != nil {
slog.Error("failed to elect new leader", slog.Any("error", err))
}
Expand Down
Loading