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

Release v0.15.1 #430

Merged
merged 24 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
2f6fd4d
Close VARA modem before re-initializing
martinhpedersen May 30, 2023
ca01538
fsnotify cleanup
martinhpedersen Jun 16, 2023
13448c8
Don't attempt to convert SVG attachments
martinhpedersen Jul 24, 2023
a1555a9
[email protected]
martinhpedersen Jul 31, 2023
6b75f18
Only attach Forms XML if a viewer file is defined
martinhpedersen Jul 29, 2023
8da9a16
[email protected] (libhamlib v4.2 compatibility)
martinhpedersen Oct 7, 2023
b62dbc7
fix tests and compilation with `TAGS=libhamlib`
as3ii Oct 3, 2023
49bb71f
Cleanup of HTTP routing
martinhpedersen Oct 13, 2023
2f30d0f
Refactor date parsing in forms and add tests
martinhpedersen Oct 15, 2023
0f183d0
Fix incorrect time layout strings for UTC variants
martinhpedersen Oct 15, 2023
4f1b7e5
Update node version and transitive deps
xylo04 Oct 16, 2023
2b23ce2
[email protected] (requires Go 1.19)
martinhpedersen Oct 18, 2023
a02a25c
Merge branch 'master' into develop
martinhpedersen Oct 18, 2023
5f72812
ci: Push docker images only when new tag is pushed
martinhpedersen Oct 18, 2023
c76b660
[email protected]
martinhpedersen Oct 21, 2023
f0df19a
go fmt ./...
martinhpedersen Oct 21, 2023
8da5719
[email protected] (fix hamlib vfo mode)
martinhpedersen Oct 27, 2023
60dac56
Include Root CA certificates in Docker image
martinhpedersen Oct 27, 2023
230e2cf
[email protected] (FW_AUX_ONLY_EXPERIMENT)
martinhpedersen Nov 4, 2023
77cc83b
Support config overrides using env variables
martinhpedersen Nov 4, 2023
66cd955
docker: Make it easier to run on-off commands
martinhpedersen Nov 5, 2023
8e4aa1b
docker: Set HTTP listen address by env variable
martinhpedersen Nov 5, 2023
2e61f66
Support defining hamlib_rigs through env variables
martinhpedersen Nov 7, 2023
b9f4b00
Bump version (v0.15.1)
martinhpedersen Nov 7, 2023
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
6 changes: 3 additions & 3 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ name: docker-push
on:
push:
branches:
- 'docker'
- 'master'
- 'ci-test/*'
- 'release/*'
tags:
- 'v*'

Expand Down Expand Up @@ -37,6 +37,6 @@ jobs:
with:
context: .
platforms: linux/amd64,linux/386,linux/arm64/v8,linux/arm/v7,linux/arm/v6
push: true
push: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
2 changes: 1 addition & 1 deletion .github/workflows/go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
go-version: [ '1.x' ]
include:
- os: ubuntu-latest
go-version: '1.16'
go-version: '1.19'
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
Expand Down
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM golang:alpine as builder
RUN apk add --no-cache git
RUN apk add --no-cache git ca-certificates
WORKDIR /src
ADD go.mod go.sum ./
RUN go mod download
Expand All @@ -10,11 +10,14 @@ FROM scratch
LABEL org.opencontainers.image.source=https://github.com/la5nta/pat
LABEL org.opencontainers.image.description="Pat - A portable Winlink client for amateur radio email"
LABEL org.opencontainers.image.licenses=MIT
COPY --from=builder /etc/ssl/certs /etc/ssl/certs
COPY --from=builder /src/pat /bin/pat
USER 65534:65534
WORKDIR /app
ENV XDG_CONFIG_HOME=/app
ENV XDG_DATA_HOME=/app
ENV XDG_STATE_HOME=/app
ENV PAT_HTTPADDR=:8080
EXPOSE 8080
ENTRYPOINT ["/bin/pat", "http", "--addr", ":8080"]
ENTRYPOINT ["/bin/pat"]
CMD ["http"]
2 changes: 1 addition & 1 deletion cfg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ type Config struct {
}

type HamlibConfig struct {
// The network type ("serial" or "tcp"). Use 'tcp' for rigctld.
// The network type ("serial" or "tcp"). Use 'tcp' for rigctld (default).
//
// (For serial support: build with "-tags libhamlib".)
Network string `json:"network,omitempty"`
Expand Down
8 changes: 5 additions & 3 deletions cli_composer.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ func readAttachment(path string) (*fbb.File, error) {
name := filepath.Base(path)

var resizeImage bool
if isImageMediaType(name, "") {
if isConvertableImageMediaType(name, "") {
fmt.Print("This seems to be an image. Auto resize? [Y/n]: ")
ans := readLine()
resizeImage = ans == "" || strings.EqualFold("y", ans)
Expand Down Expand Up @@ -332,8 +332,10 @@ func composeFormReport(ctx context.Context, args []string) {

msg.SetBody(formMsg.Body)

attachmentFile := fbb.NewFile(formMsg.AttachmentName, []byte(formMsg.AttachmentXML))
msg.AddFile(attachmentFile)
if xml := formMsg.AttachmentXML; xml != "" {
attachmentFile := fbb.NewFile(formMsg.AttachmentName, []byte(xml))
msg.AddFile(attachmentFile)
}

postMessage(msg)
}
58 changes: 55 additions & 3 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,36 @@ package main

import (
"encoding/json"
"fmt"
"log"
"os"
"path"
"strings"

"github.com/kelseyhightower/envconfig"
"github.com/la5nta/pat/cfg"
"github.com/la5nta/pat/internal/buildinfo"
"github.com/la5nta/pat/internal/debug"
)

func LoadConfig(cfgPath string, fallback cfg.Config) (config cfg.Config, err error) {
config, err = ReadConfig(cfgPath)
if os.IsNotExist(err) {
return fallback, WriteConfig(fallback, cfgPath)
} else if err != nil {
switch {
case os.IsNotExist(err):
config = fallback
if err := WriteConfig(config, cfgPath); err != nil {
return config, err
}
case err != nil:
return config, err
}

// Environment variables overrides values from the config file
if err := envconfig.Process(buildinfo.AppName, &config); err != nil {
return config, err
}
// Environment variables for hamlib rigs (custom syntax not handled by envconfig)
if err := readRigsFromEnv(&config.HamlibRigs); err != nil {
return config, err
}

Expand Down Expand Up @@ -110,6 +126,42 @@ func LoadConfig(cfgPath string, fallback cfg.Config) (config cfg.Config, err err
return config, nil
}

// readRigsFromEnv reads hamlib rigs config from environment.
// Syntax: PAT_HAMLIB_RIGS_{rig name}_{ATTRIBUTE}
// _{ATTRIBUTE} is optional (defaults to _ADDRESS).
// Examples:
// - PAT_HAMLIB_RIGS_rig1_NETWORK=tcp
// - PAT_HAMLIB_RIGS_rig1_ADDRESS=localhost:8080
// - PAT_HAMLIB_RIGS_rig1_VFO=A
// - PAT_HAMLIB_RIGS_rig2=localhost:8080
func readRigsFromEnv(rigs *map[string]cfg.HamlibConfig) error {
prefix := strings.ToUpper(buildinfo.AppName) + "_HAMLIB_RIGS_"
for _, env := range os.Environ() {
attribute, value, _ := strings.Cut(env, "=")
if !strings.HasPrefix(attribute, prefix) {
continue
}
attribute = strings.TrimPrefix(attribute, prefix)
name, attribute, _ := strings.Cut(attribute, "_")
if *rigs == nil {
*rigs = make(map[string]cfg.HamlibConfig)
}
rig := (*rigs)[name]
switch attribute {
case "ADDRESS", "":
rig.Address = value
case "NETWORK":
rig.Network = value
case "VFO":
rig.VFO = value
default:
return fmt.Errorf("invalid attribute '%s' for rig '%s'", attribute, name)
}
(*rigs)[name] = rig
}
return nil
}

func ReadConfig(path string) (config cfg.Config, err error) {
data, err := os.ReadFile(path)
if err != nil {
Expand Down
62 changes: 62 additions & 0 deletions config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package main

import (
"os"
"strings"
"testing"

"github.com/la5nta/pat/cfg"
)

func TestReadRigsFromEnv(t *testing.T) {
const prefix = "PAT_HAMLIB_RIGS"
unset := func() {
for _, env := range os.Environ() {
key, _, _ := strings.Cut(env, "=")
if strings.HasPrefix(key, prefix) {
os.Unsetenv(key)
}
}
}
t.Run("simple", func(t *testing.T) {
defer unset()
var rigs map[string]cfg.HamlibConfig
os.Setenv(prefix+"_rig", "localhost:4532")
if err := readRigsFromEnv(&rigs); err != nil {
t.Fatal(err)
}
if got := rigs["rig"]; (got != cfg.HamlibConfig{Address: "localhost:4532"}) {
t.Fatalf("Got unexpected config: %#v", got)
}
})
t.Run("with VFO", func(t *testing.T) {
defer unset()
var rigs map[string]cfg.HamlibConfig
os.Setenv(prefix+"_rig", "localhost:4532")
os.Setenv(prefix+"_rig_VFO", "A")
if err := readRigsFromEnv(&rigs); err != nil {
t.Fatal(err)
}
if got := rigs["rig"]; (got != cfg.HamlibConfig{Address: "localhost:4532", VFO: "A"}) {
t.Fatalf("Got unexpected config: %#v", got)
}
})
t.Run("full", func(t *testing.T) {
defer unset()
var rigs map[string]cfg.HamlibConfig
os.Setenv(prefix+"_rig_ADDRESS", "/dev/ttyS0")
os.Setenv(prefix+"_rig_NETWORK", "serial")
os.Setenv(prefix+"_rig_VFO", "B")
if err := readRigsFromEnv(&rigs); err != nil {
t.Fatal(err)
}
expect := cfg.HamlibConfig{
Address: "/dev/ttyS0",
Network: "serial",
VFO: "B",
}
if got := rigs["rig"]; got != expect {
t.Fatalf("Got unexpected config: %#v", got)
}
})
}
6 changes: 6 additions & 0 deletions connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,9 @@ func initVaraHFModem() error {
if varaHFModem != nil && varaHFModem.Ping() {
return nil
}
if varaHFModem != nil {
varaHFModem.Close()
}
m, err := initVaraModem(MethodVaraHF, config.VaraHF)
if err != nil {
return err
Expand All @@ -334,6 +337,9 @@ func initVaraFMModem() error {
if varaFMModem != nil && varaFMModem.Ping() {
return nil
}
if varaFMModem != nil {
varaFMModem.Close()
}
m, err := initVaraModem(MethodVaraFM, config.VaraFM)
if err != nil {
return err
Expand Down
10 changes: 8 additions & 2 deletions convert_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/nfnt/resize"
)

func isImageMediaType(filename, contentType string) bool {
func isConvertableImageMediaType(filename, contentType string) bool {
var mediaType string
if contentType != "" {
mediaType, _, _ = mime.ParseMediaType(contentType)
Expand All @@ -26,7 +26,13 @@ func isImageMediaType(filename, contentType string) bool {
mediaType = mime.TypeByExtension(path.Ext(filename))
}

return strings.HasPrefix(mediaType, "image/")
switch mediaType {
case "image/svg+xml":
// This is a text file
return false
default:
return strings.HasPrefix(mediaType, "image/")
}
}

func convertImage(orig []byte) ([]byte, error) {
Expand Down
14 changes: 14 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
pat (0.15.1) stable; urgency=medium

* Support config overrides using env variables
* Only attach Forms XML if a viewer file is defined
* Fix handling of SVG attachments (don't attempt auto resize)
* VARA: Silence "got a vara command I wasn't expecting..." messages
* VARA: Fix leak when re-initializing the modem connection
* hamlib: Fix compatibility with rigctld in VFO Mode
* hamlib: Fix tests and compilation when statically linking libhamlib
* New experiment FW_AUX_ONLY_EXPERIMENT (disabled by default)
* Require Go 1.19 or later (due to updated dependencies)

-- Martin Hebnes Pedersen <[email protected]> Sun, 5 Nov 2023 12:44:08 +0100

pat (0.15.0) stable; urgency=medium

* Restore previous connect parameters from browser's local storage
Expand Down
22 changes: 18 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/la5nta/pat

go 1.16
go 1.19

require (
github.com/adrg/xdg v0.3.3
Expand All @@ -12,15 +12,29 @@ require (
github.com/gorilla/websocket v1.4.2
github.com/harenber/ptc-go/v2 v2.2.3
github.com/howeyc/gopass v0.0.0-20190910152052-7cb4b85ec19c
github.com/la5nta/wl2k-go v0.11.4
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/kelseyhightower/envconfig v1.4.0
github.com/la5nta/wl2k-go v0.11.8
github.com/microcosm-cc/bluemonday v1.0.16
github.com/n8jja/Pat-Vara v1.1.2
github.com/n8jja/Pat-Vara v1.1.4
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
github.com/pd0mz/go-maidenhead v1.0.0
github.com/peterh/liner v1.2.1
github.com/spf13/pflag v1.0.5
)

require (
dario.cat/mergo v1.0.0 // indirect
github.com/albenik/go-serial/v2 v2.6.0 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/creack/goselect v0.1.2 // indirect
github.com/gorilla/css v1.0.0 // indirect
github.com/howeyc/crc16 v0.0.0-20171223171357-2b2a61e366a6 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/paulrosania/go-charset v0.0.0-20190326053356-55c9d7a5834c // indirect
github.com/rivo/uniseg v0.2.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.0.0-20210813211128-0a44fdfbc16e // indirect
golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b // indirect
)
Loading
Loading