Skip to content
Merged
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
8 changes: 5 additions & 3 deletions .github/workflows/buildandtest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ on:
branches:
- main
- develop

permissions:
contents: read

jobs:

buildandtest:
Expand All @@ -20,13 +22,13 @@ jobs:

steps:
- name: Set up Go ${{matrix.go}}
uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version: ${{matrix.go}}
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Test Go packages
run: go test -run IEDData -v -p 1 -race -exec sudo ./...
8 changes: 4 additions & 4 deletions .github/workflows/codeql-analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Initialize CodeQL
uses: github/codeql-action/init@b8d3b6e8af63cde30bdc382c0bc28114f4346c88 # v2
uses: github/codeql-action/init@cdf488f595d80d6e07e03d4674febd5ab45fa938 # v4.37.9
with:
languages: ${{ matrix.language }}

- name: Autobuild
uses: github/codeql-action/autobuild@b8d3b6e8af63cde30bdc382c0bc28114f4346c88 # v2
uses: github/codeql-action/autobuild@cdf488f595d80d6e07e03d4674febd5ab45fa938 # v4.37.9

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@b8d3b6e8af63cde30bdc382c0bc28114f4346c88 # v2
uses: github/codeql-action/analyze@cdf488f595d80d6e07e03d4674febd5ab45fa938 # v4.37.9
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
![goroutines](https://img.shields.io/badge/go%20routines-not%20leaking-success)
![file descriptors](https://img.shields.io/badge/file%20descriptors-not%20leaking-success)
[![Go Report Card](https://goreportcard.com/badge/github.com/siemens/ieddata)](https://goreportcard.com/report/github.com/siemens/ieddata)
![Coverage](https://img.shields.io/badge/Coverage-90.6%25-brightgreen)
![Coverage](https://img.shields.io/badge/Coverage-90.2%25-brightgreen)

`iedata` provides querying information about a Siemens Industrial Edge (virtual)
device from an app inside the IE(v)D.
Expand Down
9 changes: 5 additions & 4 deletions apps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ package ieddata

import (
"os"
"path"
"path/filepath"
"time"

"github.com/thediveo/lxkns/model"
"github.com/thediveo/procfsroot/wormholes"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand All @@ -29,8 +29,9 @@ var _ = Describe("IED app engine installed apps", func() {
It("reads installed app information", func() {
// Use a local test database, so we don't need to rely on an (fake) edge
// core running.
cwd := Successful(os.Getwd())
db := Successful(open(path.Join(cwd, "tests/sqlite-alpine-appengine-db/test-apps-and-device.db"), model.PIDType(os.Getpid())))
vfs := wormholes.New(os.Getpid())
db := Successful(open(vfs,
Successful(filepath.Abs("tests/sqlite-alpine-appengine-db/test-apps-and-device.db"))[1:]))
defer func() { _ = db.Close() }()

apps := Successful(db.Apps())
Expand Down
39 changes: 21 additions & 18 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ package ieddata
import (
"fmt"
"io"
"io/fs"
"os"
"path"
"regexp"
"strings"
"sync"

"github.com/jmoiron/sqlx"
"github.com/thediveo/lxkns/model"
"github.com/thediveo/procfsroot"
"github.com/thediveo/procfsroot/wormholes"
_ "modernc.org/sqlite"
)

Expand Down Expand Up @@ -65,8 +67,19 @@ func OpenInPID(dbname string, pid model.PIDType) (*AppEngineDB, error) {
// OpenPathInPID works like OpenInPID but take a full path and database name as
// well as a PID within which to resolve the pathname. Use this primarily in
// (unit) tests where spinning up a fake IED runtime container is overkill.
//
// Deprecated: use [OpenFS] with a [wormholes.FS] instead.
// instead.
func OpenPathInPID(pathname string, pid model.PIDType) (*AppEngineDB, error) {
return open(pathname, pid)
pathname = strings.TrimPrefix(pathname, "/")
vfs := wormholes.New(int(pid))
return open(vfs, pathname)
}

// OpenFS works like Open but opens the specified database in the passed
// fs.FS.
func OpenFS(fsys fs.FS, pathname string) (*AppEngineDB, error) {
return open(fsys, pathname)
}

var onlyAlphaNumsAndMore = regexp.MustCompile(`[^a-zA-Z0-9\-_.]+`)
Expand All @@ -80,11 +93,8 @@ func sanitize(basename string) string {
return noDotDots.ReplaceAllString(onlyAlphaNumsAndMore.ReplaceAllString(basename, "_"), "_")
}

// open actually opens the SQLite database read-only specified by its full path,
// with the help of a mountineer. Separating this out gives us a chance to reuse
// it in some tests without the need for a correctly set-up fake edge runtime
// container. Please note that any caller must have sanitized the name parameter
// first.
// open actually opens the SQLite database read-only at the given path (that
// must follow fs.FS semantics and thus not start with "/") on the passed fs.FS.
//
// As it turns out there are some situations which we don't yet fully understand
// but that causes opening the database via a proc path to fail, even if it
Expand All @@ -94,17 +104,10 @@ func sanitize(basename string) string {
// https://github.com/mathaou/termdbms/blob/be6f397196077cc7c9ced86e6460470e3b223f3e/main.go#L132.
//
// Well, what's good for the goose is good for the gander, so copy it is. Sigh.
func open(pathname string, pid model.PIDType) (*AppEngineDB, error) {
rootpath := fmt.Sprintf("/proc/%d/root", pid)
dbpath, err := procfsroot.EvalSymlinks(pathname, rootpath, procfsroot.EvalFullPath)
if err != nil {
return nil, fmt.Errorf("cannot determine full database path, reason: %w", err)
}
dbpath = path.Join(rootpath, dbpath)

func open(fsys fs.FS, pathname string) (*AppEngineDB, error) {
// Make a temporary copy of the database so we can open it successfully in
// all our cases.
origdbf, err := os.Open(dbpath)
origdbf, err := fsys.Open(pathname)
if err != nil {
return nil, fmt.Errorf("unable to open database, reason: %w", err)
}
Expand All @@ -120,7 +123,7 @@ func open(pathname string, pid model.PIDType) (*AppEngineDB, error) {
}

// When available, make a copy of the accompanying WAL file also.
if walf, err := os.Open(dbpath + "-wal"); err == nil {
if walf, err := fsys.Open(pathname + "-wal"); err == nil {
defer func() { _ = walf.Close() }()
if tmpwalf, err := os.Create(tmpdbf.Name() + "-wal"); err == nil {
defer func() { _ = tmpwalf.Close() }()
Expand All @@ -135,7 +138,7 @@ func open(pathname string, pid model.PIDType) (*AppEngineDB, error) {
// As sql.Open might just "validate its parameters" and this might mean near
// to nothing, we explicitly ping the database in order to see that it is
// okay.
dbpath = tmpdbf.Name()
dbpath := tmpdbf.Name()
_ = tmpdbf.Close()
db, err := sqlx.Open(dbDriverName, dbpath)
if err != nil {
Expand Down
11 changes: 4 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ go 1.26.3
require (
github.com/jmoiron/sqlx v1.4.0
github.com/onsi/ginkgo/v2 v2.32.1
github.com/onsi/gomega v1.42.1
github.com/onsi/gomega v1.43.0
github.com/thediveo/fdooze v0.3.4
github.com/thediveo/lxkns v0.47.1
github.com/thediveo/morbyd/v2 v2.2.4
github.com/thediveo/procfsroot v1.0.3
github.com/thediveo/procfsroot v1.1.0
github.com/thediveo/success v1.3.1
github.com/thediveo/whalewatcher/v2 v2.1.0
golang.org/x/sys v0.47.0
Expand Down Expand Up @@ -42,8 +42,6 @@ require (
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
github.com/gofrs/flock v0.13.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/go-cmp v0.7.0 // indirect
github.com/google/pprof v0.0.0-20260802141513-ef3492d7dac3 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
Expand Down Expand Up @@ -95,12 +93,11 @@ require (
go.opentelemetry.io/otel/trace v1.44.0 // indirect
go.opentelemetry.io/proto/otlp v1.10.0 // indirect
go.yaml.in/yaml/v3 v3.0.4 // indirect
golang.org/x/crypto v0.54.0 // indirect
golang.org/x/exp v0.0.0-20260603202125-055de637280b // indirect
golang.org/x/crypto v0.55.0 // indirect
golang.org/x/mod v0.38.0 // indirect
golang.org/x/net v0.57.0 // indirect
golang.org/x/sync v0.22.0 // indirect
golang.org/x/text v0.40.0 // indirect
golang.org/x/text v0.41.0 // indirect
golang.org/x/time v0.15.0 // indirect
golang.org/x/tools v0.48.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20260526163538-3dc84a4a5aaa // indirect
Expand Down
Loading
Loading