Update logging behavior
This commit is contained in:
parent
3b78b06fff
commit
6f1ba24761
28 changed files with 176 additions and 137 deletions
|
|
@ -2,13 +2,13 @@ package component
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/models"
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/fsx"
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/logging"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
|
|
@ -93,7 +93,7 @@ func (bc *stagingContext) sendPath(path string) {
|
|||
return
|
||||
}
|
||||
|
||||
fmt.Fprintln(bc.progress, dst)
|
||||
logging.Progress(bc.progress, bc.ctx, dst)
|
||||
bc.manifest <- dst
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package home
|
|||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"time"
|
||||
|
||||
|
|
@ -11,6 +10,7 @@ import (
|
|||
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/control/static"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/status"
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/logging"
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/timex"
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
|
@ -18,7 +18,7 @@ import (
|
|||
func (home *Home) updateInstances(ctx context.Context, progress io.Writer) {
|
||||
go func() {
|
||||
for t := range timex.TickContext(ctx, home.RefreshInterval) {
|
||||
fmt.Fprintf(progress, "[%s]: reloading instance list\n", t.Format(time.Stamp))
|
||||
logging.ProgressF(progress, ctx, "[%s]: reloading instance list\n", t.Format(time.Stamp))
|
||||
|
||||
err := (func() error {
|
||||
ctx, cancel := context.WithTimeout(ctx, home.RefreshInterval)
|
||||
|
|
@ -33,7 +33,7 @@ func (home *Home) updateInstances(ctx context.Context, progress io.Writer) {
|
|||
return nil
|
||||
})()
|
||||
if err != nil {
|
||||
fmt.Fprintf(progress, "error reloading instances: %s", err.Error())
|
||||
logging.ProgressF(progress, ctx, "error reloading instances: %s", err.Error())
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
|
@ -55,7 +55,7 @@ func (home *Home) instanceMap(ctx context.Context) (map[string]struct{}, error)
|
|||
func (home *Home) updateRender(ctx context.Context, progress io.Writer) {
|
||||
go func() {
|
||||
for t := range timex.TickContext(ctx, home.RefreshInterval) {
|
||||
fmt.Fprintf(progress, "[%s]: reloading home render list\n", t.Format(time.Stamp))
|
||||
logging.ProgressF(progress, ctx, "[%s]: reloading home render list\n", t.Format(time.Stamp))
|
||||
|
||||
err := (func() error {
|
||||
ctx, cancel := context.WithTimeout(ctx, home.RefreshInterval)
|
||||
|
|
@ -70,7 +70,7 @@ func (home *Home) updateRender(ctx context.Context, progress io.Writer) {
|
|||
return nil
|
||||
})()
|
||||
if err != nil {
|
||||
fmt.Fprintf(progress, "error reloading instances: %s", err.Error())
|
||||
logging.ProgressF(progress, ctx, "error reloading instances: %s", err.Error())
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
|
|
|||
|
|
@ -3,19 +3,19 @@ package home
|
|||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/logging"
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/timex"
|
||||
)
|
||||
|
||||
func (home *Home) updateRedirect(ctx context.Context, progress io.Writer) {
|
||||
go func() {
|
||||
for t := range timex.TickContext(ctx, home.RefreshInterval) {
|
||||
fmt.Fprintf(progress, "[%s]: reloading overrides\n", t.Format(time.Stamp))
|
||||
logging.ProgressF(progress, ctx, "[%s]: reloading overrides\n", t.Format(time.Stamp))
|
||||
|
||||
err := (func() error {
|
||||
ctx, cancel := context.WithTimeout(ctx, home.RefreshInterval)
|
||||
|
|
@ -30,7 +30,7 @@ func (home *Home) updateRedirect(ctx context.Context, progress io.Writer) {
|
|||
return nil
|
||||
})()
|
||||
if err != nil {
|
||||
fmt.Fprintf(progress, "error reloading overrides: %s", err.Error())
|
||||
logging.ProgressF(progress, ctx, "error reloading overrides: %s", err.Error())
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,9 +2,10 @@ package control
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/logging"
|
||||
)
|
||||
|
||||
// Server returns an http.Mux that implements the main server instance.
|
||||
|
|
@ -18,7 +19,7 @@ func (control *Control) Server(ctx context.Context, progress io.Writer) (*http.S
|
|||
// add all the servable routes!
|
||||
for _, s := range control.Servables {
|
||||
for _, route := range s.Routes() {
|
||||
fmt.Fprintf(progress, "mounting %s\n", route)
|
||||
logging.ProgressF(progress, ctx, "mounting %s\n", route)
|
||||
handler, err := s.Handler(ctx, route, progress)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ func (exporter *Exporter) NewBackup(ctx context.Context, progress io.Writer, des
|
|||
backup.EndTime = time.Now().UTC()
|
||||
|
||||
return nil
|
||||
}, progress, "Writing backup files")
|
||||
}, progress, ctx, "Writing backup files")
|
||||
|
||||
return
|
||||
}
|
||||
|
|
@ -110,7 +110,7 @@ func (backup *Backup) run(ctx context.Context, progress io.Writer, exporter *Exp
|
|||
}
|
||||
|
||||
return nil
|
||||
}, progress, "Backing up core components")
|
||||
}, progress, ctx, "Backing up core components")
|
||||
|
||||
// backup instances
|
||||
logging.LogOperation(func() error {
|
||||
|
|
@ -165,6 +165,6 @@ func (backup *Backup) run(ctx context.Context, progress io.Writer, exporter *Exp
|
|||
})
|
||||
|
||||
return nil
|
||||
}, progress, "Creating instance snapshots")
|
||||
}, progress, ctx, "Creating instance snapshots")
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package exporter
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"path/filepath"
|
||||
|
||||
|
|
@ -53,7 +52,7 @@ func (exporter *Exporter) MakeExport(ctx context.Context, progress io.Writer, ta
|
|||
}
|
||||
|
||||
// determine target paths
|
||||
logging.LogMessage(progress, "Determining target paths")
|
||||
logging.LogMessage(progress, ctx, "Determining target paths")
|
||||
var stagingDir, archivePath string
|
||||
if task.StagingOnly {
|
||||
stagingDir = task.Dest
|
||||
|
|
@ -69,11 +68,11 @@ func (exporter *Exporter) MakeExport(ctx context.Context, progress io.Writer, ta
|
|||
if !task.StagingOnly && archivePath == "" {
|
||||
archivePath = exporter.NewArchivePath(Slug)
|
||||
}
|
||||
fmt.Fprintf(progress, "Staging Directory: %s\n", stagingDir)
|
||||
fmt.Fprintf(progress, "Archive Path: %s\n", archivePath)
|
||||
logging.ProgressF(progress, ctx, "Staging Directory: %s\n", stagingDir)
|
||||
logging.ProgressF(progress, ctx, "Archive Path: %s\n", archivePath)
|
||||
|
||||
// create the staging directory
|
||||
logging.LogMessage(progress, "Creating staging directory")
|
||||
logging.LogMessage(progress, ctx, "Creating staging directory")
|
||||
err = exporter.Environment.Mkdir(stagingDir, environment.DefaultDirPerm)
|
||||
if !environment.IsExist(err) && err != nil {
|
||||
return err
|
||||
|
|
@ -83,7 +82,7 @@ func (exporter *Exporter) MakeExport(ctx context.Context, progress io.Writer, ta
|
|||
// we need the staging directory to be deleted at the end
|
||||
if !task.StagingOnly {
|
||||
defer func() {
|
||||
logging.LogMessage(progress, "Removing staging directory")
|
||||
logging.LogMessage(progress, ctx, "Removing staging directory")
|
||||
exporter.Environment.RemoveAll(stagingDir)
|
||||
}()
|
||||
}
|
||||
|
|
@ -109,7 +108,7 @@ func (exporter *Exporter) MakeExport(ctx context.Context, progress io.Writer, ta
|
|||
|
||||
// find the report path
|
||||
reportPath := filepath.Join(stagingDir, "report.txt")
|
||||
fmt.Fprintln(progress, reportPath)
|
||||
logging.ProgressF(progress, ctx, reportPath)
|
||||
|
||||
// create the path
|
||||
report, err := exporter.Environment.Create(reportPath, environment.DefaultFilePerm)
|
||||
|
|
@ -122,26 +121,26 @@ func (exporter *Exporter) MakeExport(ctx context.Context, progress io.Writer, ta
|
|||
_, err := sl.Report(report)
|
||||
return err
|
||||
}
|
||||
}, progress, "Generating %s", Title)
|
||||
}, progress, ctx, "Generating %s", Title)
|
||||
|
||||
// if we only requested staging
|
||||
// all that is left is to write the log entry
|
||||
if task.StagingOnly {
|
||||
logging.LogMessage(progress, "Writing Log Entry")
|
||||
logging.LogMessage(progress, ctx, "Writing Log Entry")
|
||||
|
||||
// write out the log entry
|
||||
entry.Path = stagingDir
|
||||
entry.Packed = false
|
||||
exporter.ExporterLogger.Add(ctx, entry)
|
||||
|
||||
fmt.Fprintf(progress, "Wrote %s\n", stagingDir)
|
||||
logging.ProgressF(progress, ctx, "Wrote %s\n", stagingDir)
|
||||
return nil
|
||||
}
|
||||
|
||||
// package everything up as an archive!
|
||||
if err := logging.LogOperation(func() error {
|
||||
var count int64
|
||||
defer func() { fmt.Fprintf(progress, "Wrote %d byte(s) to %s\n", count, archivePath) }()
|
||||
defer func() { logging.ProgressF(progress, ctx, "Wrote %d byte(s) to %s\n", count, archivePath) }()
|
||||
|
||||
st := status.NewWithCompat(progress, 1)
|
||||
st.Start()
|
||||
|
|
@ -152,12 +151,12 @@ func (exporter *Exporter) MakeExport(ctx context.Context, progress io.Writer, ta
|
|||
})
|
||||
|
||||
return err
|
||||
}, progress, "Writing archive"); err != nil {
|
||||
}, progress, ctx, "Writing archive"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// write out the log entry
|
||||
logging.LogMessage(progress, "Writing Log Entry")
|
||||
logging.LogMessage(progress, ctx, "Writing Log Entry")
|
||||
entry.Path = archivePath
|
||||
entry.Packed = true
|
||||
exporter.ExporterLogger.Add(ctx, entry)
|
||||
|
|
|
|||
|
|
@ -2,10 +2,11 @@ package exporter
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/logging"
|
||||
)
|
||||
|
||||
// ShouldPrune determines if a file with the provided modification time should be
|
||||
|
|
@ -43,7 +44,7 @@ func (exporter *Exporter) PruneExports(ctx context.Context, progress io.Writer)
|
|||
|
||||
// assemble path, and then remove the file!
|
||||
path := filepath.Join(sPath, entry.Name())
|
||||
fmt.Fprintf(progress, "Removing %s cause it is older than %d days\n", path, exporter.Config.MaxBackupAge)
|
||||
logging.ProgressF(progress, ctx, "Removing %s cause it is older than %d days\n", path, exporter.Config.MaxBackupAge)
|
||||
|
||||
if err := exporter.Still.Environment.Remove(path); err != nil {
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -46,18 +46,18 @@ type Snapshot struct {
|
|||
// Snapshot creates a new snapshot of this instance into dest
|
||||
func (snapshots *Exporter) NewSnapshot(ctx context.Context, instance *wisski.WissKI, progress io.Writer, desc SnapshotDescription) (snapshot Snapshot) {
|
||||
|
||||
logging.LogMessage(progress, "Locking instance")
|
||||
logging.LogMessage(progress, ctx, "Locking instance")
|
||||
if !instance.Locker().TryLock(ctx) {
|
||||
err := locker.Locked
|
||||
fmt.Fprintln(progress, err)
|
||||
logging.LogMessage(progress, "Aborting snapshot creation")
|
||||
logging.ProgressF(progress, ctx, "%v", err)
|
||||
logging.LogMessage(progress, ctx, "Aborting snapshot creation")
|
||||
|
||||
return Snapshot{
|
||||
ErrPanic: err,
|
||||
}
|
||||
}
|
||||
defer func() {
|
||||
logging.LogMessage(progress, "Unlocking instance")
|
||||
logging.LogMessage(progress, ctx, "Unlocking instance")
|
||||
instance.Locker().Unlock(ctx)
|
||||
}()
|
||||
|
||||
|
|
@ -79,7 +79,7 @@ func (snapshots *Exporter) NewSnapshot(ctx context.Context, instance *wisski.Wis
|
|||
|
||||
snapshot.EndTime = time.Now().UTC()
|
||||
return nil
|
||||
}, progress, "Writing snapshot files")
|
||||
}, progress, ctx, "Writing snapshot files")
|
||||
|
||||
slices.Sort(snapshot.Manifest)
|
||||
return
|
||||
|
|
@ -89,11 +89,11 @@ func (snapshot *Snapshot) makeParts(ctx context.Context, progress io.Writer, sna
|
|||
if !needsRunning && !snapshot.Description.Keepalive {
|
||||
stack := instance.Barrel().Stack()
|
||||
|
||||
logging.LogMessage(progress, "Stopping instance")
|
||||
logging.LogMessage(progress, ctx, "Stopping instance")
|
||||
snapshot.ErrStop = stack.Down(ctx, progress)
|
||||
|
||||
defer func() {
|
||||
logging.LogMessage(progress, "Starting instance")
|
||||
logging.LogMessage(progress, ctx, "Starting instance")
|
||||
snapshot.ErrStart = stack.Up(ctx, progress)
|
||||
}()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@ package instances
|
|||
import (
|
||||
"context"
|
||||
"embed"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/logging"
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/unpack"
|
||||
"github.com/tkw1536/goprogram/exit"
|
||||
)
|
||||
|
|
@ -23,7 +23,7 @@ var runtimeResources embed.FS
|
|||
// Update installs or updates runtime components needed by this component.
|
||||
func (instances *Instances) Update(ctx context.Context, progress io.Writer) error {
|
||||
err := unpack.InstallDir(instances.Still.Environment, instances.Config.RuntimeDir(), "runtime", runtimeResources, func(dst, src string) {
|
||||
fmt.Fprintf(progress, "[copy] %s\n", dst)
|
||||
logging.ProgressF(progress, ctx, "[copy] %s\n", dst)
|
||||
})
|
||||
if err != nil {
|
||||
return errBootstrapFailedRuntime.Wrap(err)
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@ package resolver
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"time"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/logging"
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/timex"
|
||||
)
|
||||
|
||||
|
|
@ -13,7 +13,7 @@ import (
|
|||
func (resolver *Resolver) updatePrefixes(ctx context.Context, progress io.Writer) {
|
||||
go func() {
|
||||
for t := range timex.TickContext(ctx, resolver.RefreshInterval) {
|
||||
fmt.Fprintf(progress, "[%s]: reloading prefixes\n", t.Format(time.Stamp))
|
||||
logging.ProgressF(progress, ctx, "[%s]: reloading prefixes\n", t.Format(time.Stamp))
|
||||
|
||||
err := (func() (err error) {
|
||||
ctx, cancel := context.WithTimeout(ctx, resolver.RefreshInterval)
|
||||
|
|
@ -28,7 +28,7 @@ func (resolver *Resolver) updatePrefixes(ctx context.Context, progress io.Writer
|
|||
return nil
|
||||
})()
|
||||
if err != nil {
|
||||
fmt.Fprintf(progress, "error reloading prefixes: %s", err.Error())
|
||||
logging.ProgressF(progress, ctx, "error reloading prefixes: %s", err.Error())
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import (
|
|||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/instances"
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/lazy"
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/logging"
|
||||
)
|
||||
|
||||
type Resolver struct {
|
||||
|
|
@ -45,13 +46,13 @@ func (resolver *Resolver) Handler(ctx context.Context, route string, progress io
|
|||
domainName := resolver.Config.DefaultDomain
|
||||
if domainName != "" {
|
||||
fallback.Data[fmt.Sprintf("^https?://(.*)\\.%s", regexp.QuoteMeta(domainName))] = fmt.Sprintf("https://$1.%s", domainName)
|
||||
fmt.Fprintf(progress, "registering default domain %s\n", domainName)
|
||||
logging.ProgressF(progress, ctx, "registering default domain %s\n", domainName)
|
||||
}
|
||||
|
||||
// handle the extra domains!
|
||||
for _, domain := range resolver.Config.SelfExtraDomains {
|
||||
fallback.Data[fmt.Sprintf("^https?://(.*)\\.%s", regexp.QuoteMeta(domain))] = fmt.Sprintf("https://$1.%s", domainName)
|
||||
fmt.Fprintf(progress, "registering legacy domain %s\n", domain)
|
||||
logging.ProgressF(progress, ctx, "registering legacy domain %s\n", domain)
|
||||
}
|
||||
|
||||
// start updating prefixes
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ func (sql *SQL) Update(ctx context.Context, progress io.Writer) error {
|
|||
if err := sql.unsafeWaitShell(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
logging.LogMessage(progress, "Creating administrative user")
|
||||
logging.LogMessage(progress, ctx, "Creating administrative user")
|
||||
{
|
||||
username := sql.Config.MysqlAdminUser
|
||||
password := sql.Config.MysqlAdminPassword
|
||||
|
|
@ -63,7 +63,7 @@ func (sql *SQL) Update(ctx context.Context, progress io.Writer) error {
|
|||
}
|
||||
|
||||
// create the admin user
|
||||
logging.LogMessage(progress, "Creating sql database")
|
||||
logging.LogMessage(progress, ctx, "Creating sql database")
|
||||
{
|
||||
if !sqle.IsSafeDatabaseLiteral(sql.Config.DistilleryDatabase) {
|
||||
return errSQLUnsafeDatabaseName
|
||||
|
|
@ -75,7 +75,7 @@ func (sql *SQL) Update(ctx context.Context, progress io.Writer) error {
|
|||
}
|
||||
|
||||
// wait for the database to come up
|
||||
logging.LogMessage(progress, "Waiting for database update to be complete")
|
||||
logging.LogMessage(progress, ctx, "Waiting for database update to be complete")
|
||||
sql.WaitQueryTable(ctx)
|
||||
|
||||
tables := []struct {
|
||||
|
|
@ -108,7 +108,7 @@ func (sql *SQL) Update(ctx context.Context, progress io.Writer) error {
|
|||
// migrate all of the tables!
|
||||
return logging.LogOperation(func() error {
|
||||
for _, table := range tables {
|
||||
logging.LogMessage(progress, "migrating %q table", table.name)
|
||||
logging.LogMessage(progress, ctx, "migrating %q table", table.name)
|
||||
db, err := sql.QueryTable(ctx, false, table.table)
|
||||
if err != nil {
|
||||
return errSQLUnableToMigrate.WithMessageF(table.name, "unable to access table")
|
||||
|
|
@ -119,5 +119,5 @@ func (sql *SQL) Update(ctx context.Context, progress io.Writer) error {
|
|||
}
|
||||
}
|
||||
return nil
|
||||
}, progress, "migrating database tables")
|
||||
}, progress, ctx, "migrating database tables")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,10 +13,10 @@ const (
|
|||
)
|
||||
|
||||
// Server returns an ssh server that implements the main ssh server
|
||||
func (ssh2 *SSH2) Server(context context.Context, privateKeyPath string, progress io.Writer) (*ssh.Server, error) {
|
||||
func (ssh2 *SSH2) Server(ctx context.Context, privateKeyPath string, progress io.Writer) (*ssh.Server, error) {
|
||||
var server ssh.Server
|
||||
|
||||
if err := ssh2.setupHostKeys(progress, privateKeyPath, &server); err != nil {
|
||||
if err := ssh2.setupHostKeys(progress, ctx, privateKeyPath, &server); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,37 +1,38 @@
|
|||
package ssh2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/ed25519"
|
||||
"crypto/rand"
|
||||
"crypto/rsa"
|
||||
"crypto/x509"
|
||||
"encoding/pem"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/logging"
|
||||
"github.com/gliderlabs/ssh"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
gossh "golang.org/x/crypto/ssh"
|
||||
)
|
||||
|
||||
func (ssh2 *SSH2) setupHostKeys(progress io.Writer, privateKeyPath string, server *ssh.Server) error {
|
||||
return ssh2.UseOrMakeHostKeys(progress, server, privateKeyPath, nil)
|
||||
func (ssh2 *SSH2) setupHostKeys(progress io.Writer, ctx context.Context, privateKeyPath string, server *ssh.Server) error {
|
||||
return ssh2.UseOrMakeHostKeys(progress, ctx, server, privateKeyPath, nil)
|
||||
}
|
||||
|
||||
// UseOrMakeHostKeys is like UseOrMakeHostKey except that it accepts multiple HostKeyAlgorithms.
|
||||
// For each key algorithm, the privateKeyPath is appended with "_" + the name of the algorithm in question.
|
||||
//
|
||||
// When algorithms is nil, picks a reasonable set of default algorithms.
|
||||
func (ssh2 *SSH2) UseOrMakeHostKeys(progress io.Writer, server *ssh.Server, privateKeyPath string, algorithms []HostKeyAlgorithm) error {
|
||||
func (ssh2 *SSH2) UseOrMakeHostKeys(progress io.Writer, ctx context.Context, server *ssh.Server, privateKeyPath string, algorithms []HostKeyAlgorithm) error {
|
||||
if algorithms == nil {
|
||||
algorithms = []HostKeyAlgorithm{RSAAlgorithm, ED25519Algorithm}
|
||||
}
|
||||
|
||||
for _, algorithm := range algorithms {
|
||||
path := privateKeyPath + "_" + string(algorithm)
|
||||
if err := ssh2.UseOrMakeHostKey(progress, server, path, algorithm); err != nil {
|
||||
if err := ssh2.UseOrMakeHostKey(progress, ctx, server, path, algorithm); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
@ -44,8 +45,8 @@ func (ssh2 *SSH2) UseOrMakeHostKeys(progress io.Writer, server *ssh.Server, priv
|
|||
//
|
||||
// All parameters except the server are passed to ReadOrMakeHostKey.
|
||||
// Please see the appropriate documentation for that function.
|
||||
func (ssh2 *SSH2) UseOrMakeHostKey(progress io.Writer, server *ssh.Server, privateKeyPath string, algorithm HostKeyAlgorithm) error {
|
||||
key, err := ssh2.ReadOrMakeHostKey(progress, privateKeyPath, algorithm)
|
||||
func (ssh2 *SSH2) UseOrMakeHostKey(progress io.Writer, ctx context.Context, server *ssh.Server, privateKeyPath string, algorithm HostKeyAlgorithm) error {
|
||||
key, err := ssh2.ReadOrMakeHostKey(progress, ctx, privateKeyPath, algorithm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -60,17 +61,17 @@ func (ssh2 *SSH2) UseOrMakeHostKey(progress io.Writer, server *ssh.Server, priva
|
|||
//
|
||||
// This function assumes that if there is a host key in privateKeyPath it uses the provided HostKeyAlgorithm.
|
||||
// It makes no attempt at verifiying this; the key mail fail to load and return an error, or it may load incorrect data.
|
||||
func (ssh2 *SSH2) ReadOrMakeHostKey(progress io.Writer, privateKeyPath string, algorithm HostKeyAlgorithm) (key gossh.Signer, err error) {
|
||||
func (ssh2 *SSH2) ReadOrMakeHostKey(progress io.Writer, ctx context.Context, privateKeyPath string, algorithm HostKeyAlgorithm) (key gossh.Signer, err error) {
|
||||
hostKey := NewHostKey(algorithm)
|
||||
|
||||
if _, e := ssh2.Environment.Lstat(privateKeyPath); environment.IsNotExist(e) { // path doesn't exist => generate a new key there!
|
||||
err = ssh2.makeHostKey(progress, hostKey, privateKeyPath)
|
||||
err = ssh2.makeHostKey(progress, ctx, hostKey, privateKeyPath)
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "Unable to generate new host key")
|
||||
return
|
||||
}
|
||||
}
|
||||
err = ssh2.loadHostKey(progress, hostKey, privateKeyPath)
|
||||
err = ssh2.loadHostKey(progress, ctx, hostKey, privateKeyPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -78,8 +79,8 @@ func (ssh2 *SSH2) ReadOrMakeHostKey(progress io.Writer, privateKeyPath string, a
|
|||
}
|
||||
|
||||
// loadHostKey loadsa host key
|
||||
func (ssh2 *SSH2) loadHostKey(progress io.Writer, key HostKey, path string) (err error) {
|
||||
fmt.Fprintf(progress, "Loading hostkey (algorithm %s) from %q", key.Algorithm(), path)
|
||||
func (ssh2 *SSH2) loadHostKey(progress io.Writer, ctx context.Context, key HostKey, path string) (err error) {
|
||||
logging.ProgressF(progress, ctx, "Loading hostkey (algorithm %s) from %q", key.Algorithm(), path)
|
||||
|
||||
// read all the bytes from the file
|
||||
privateKeyBytes, err := environment.ReadFile(ssh2.Environment, path)
|
||||
|
|
@ -104,10 +105,10 @@ func (ssh2 *SSH2) loadHostKey(progress io.Writer, key HostKey, path string) (err
|
|||
}
|
||||
|
||||
// makeHostKey makes a new host key
|
||||
func (ssh2 *SSH2) makeHostKey(progress io.Writer, key HostKey, path string) error {
|
||||
fmt.Fprintf(progress, "Writing hostkey (algorithm %s) to %q", key.Algorithm(), path)
|
||||
func (ssh2 *SSH2) makeHostKey(progress io.Writer, ctx context.Context, key HostKey, path string) error {
|
||||
logging.ProgressF(progress, ctx, "Writing hostkey (algorithm %s) to %q", key.Algorithm(), path)
|
||||
|
||||
if err := key.Generate(0, nil); err != nil {
|
||||
if err := key.Generate(ctx, 0, nil); err != nil {
|
||||
return errors.Wrap(err, "Failed to generate key")
|
||||
}
|
||||
|
||||
|
|
@ -137,7 +138,7 @@ type HostKey interface {
|
|||
//
|
||||
// keySize is the desired public key size in bits. When keySize is 0, a sensible default is used.
|
||||
// random is the source of randomness. If random is nil, crypto/rand.Reader will be used.
|
||||
Generate(keySize int, random io.Reader) error
|
||||
Generate(ctx context.Context, keySize int, random io.Reader) error
|
||||
|
||||
// MarshalPEM marshals the private key into a pem.Block to be used for exporting.
|
||||
// The format is not guaranteed to follow any kind of standard, only that it is readable with the corresponding UnmarshalPEM.
|
||||
|
|
@ -191,7 +192,7 @@ func (ek *ed25519HostKey) Algorithm() HostKeyAlgorithm {
|
|||
|
||||
var errKeySizeUnsupported = errors.New("ed25519HostKey.Generate(): keySize not supported")
|
||||
|
||||
func (ek *ed25519HostKey) Generate(keySize int, random io.Reader) (err error) {
|
||||
func (ek *ed25519HostKey) Generate(ctx context.Context, keySize int, random io.Reader) (err error) {
|
||||
if keySize != 0 && keySize != ed25519.PublicKeySize {
|
||||
return errKeySizeUnsupported
|
||||
}
|
||||
|
|
@ -251,7 +252,7 @@ func (rk *rsaHostKey) Algorithm() HostKeyAlgorithm {
|
|||
return RSAAlgorithm
|
||||
}
|
||||
|
||||
func (rk *rsaHostKey) Generate(keySize int, random io.Reader) (err error) {
|
||||
func (rk *rsaHostKey) Generate(ctx context.Context, keySize int, random io.Reader) (err error) {
|
||||
if keySize == 0 {
|
||||
keySize = rk.defaultBitSize
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,13 +5,13 @@ import (
|
|||
"bufio"
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/fsx"
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/logging"
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/unpack"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/tkw1536/goprogram/stream"
|
||||
|
|
@ -231,7 +231,7 @@ func (is StackWithResources) Install(ctx context.Context, progress io.Writer, co
|
|||
is.ContextPath,
|
||||
is.Resources,
|
||||
func(dst, src string) {
|
||||
fmt.Fprintf(progress, "[install] %s\n", dst)
|
||||
logging.ProgressF(progress, ctx, "[install] %s\n", dst)
|
||||
},
|
||||
); err != nil {
|
||||
return err
|
||||
|
|
@ -241,7 +241,7 @@ func (is StackWithResources) Install(ctx context.Context, progress io.Writer, co
|
|||
// configure .env
|
||||
envDest := filepath.Join(is.Dir, ".env")
|
||||
if is.EnvPath != "" && is.EnvContext != nil {
|
||||
fmt.Fprintf(progress, "[config] %s\n", envDest)
|
||||
logging.ProgressF(progress, ctx, "[config] %s\n", envDest)
|
||||
if err := unpack.InstallTemplate(
|
||||
env,
|
||||
envDest,
|
||||
|
|
@ -258,7 +258,7 @@ func (is StackWithResources) Install(ctx context.Context, progress io.Writer, co
|
|||
// find the destination!
|
||||
dst := filepath.Join(is.Dir, name)
|
||||
|
||||
fmt.Fprintf(progress, "[make] %s\n", dst)
|
||||
logging.ProgressF(progress, ctx, "[make] %s\n", dst)
|
||||
if is.MakeDirsPerm == fs.FileMode(0) {
|
||||
is.MakeDirsPerm = environment.DefaultDirPerm
|
||||
}
|
||||
|
|
@ -279,7 +279,7 @@ func (is StackWithResources) Install(ctx context.Context, progress io.Writer, co
|
|||
dst := filepath.Join(is.Dir, name)
|
||||
|
||||
// copy over file from context
|
||||
fmt.Fprintf(progress, "[copy] %s (from %s)\n", dst, src)
|
||||
logging.ProgressF(progress, ctx, "[copy] %s (from %s)\n", dst, src)
|
||||
if err := fsx.CopyFile(ctx, env, dst, src); err != nil {
|
||||
return errors.Wrapf(err, "Unable to copy file %s", src)
|
||||
}
|
||||
|
|
@ -290,7 +290,7 @@ func (is StackWithResources) Install(ctx context.Context, progress io.Writer, co
|
|||
// find the destination!
|
||||
dst := filepath.Join(is.Dir, name)
|
||||
|
||||
fmt.Fprintf(progress, "[touch] %s\n", dst)
|
||||
logging.ProgressF(progress, ctx, "[touch] %s\n", dst)
|
||||
if err := fsx.Touch(env, dst, is.TouchFilesPerm); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,12 +13,12 @@ import (
|
|||
var errTriplestoreFailedSecurity = errors.New("failed to enable triplestore security: request did not succeed with HTTP 200 OK")
|
||||
|
||||
func (ts Triplestore) Update(ctx context.Context, progress io.Writer) error {
|
||||
logging.LogMessage(progress, "Waiting for Triplestore")
|
||||
logging.LogMessage(progress, ctx, "Waiting for Triplestore")
|
||||
if err := ts.Wait(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
logging.LogMessage(progress, "Resetting admin user password")
|
||||
logging.LogMessage(progress, ctx, "Resetting admin user password")
|
||||
{
|
||||
res, err := ts.OpenRaw(ctx, "PUT", "/rest/security/users/"+ts.Config.TriplestoreAdminUser, TriplestoreUserPayload{
|
||||
Password: ts.Config.TriplestoreAdminPassword,
|
||||
|
|
@ -43,14 +43,14 @@ func (ts Triplestore) Update(ctx context.Context, progress io.Writer) error {
|
|||
case http.StatusUnauthorized:
|
||||
// a password is needed => security is already enabled.
|
||||
// the password may or may not work, but that's a problem for later
|
||||
logging.LogMessage(progress, "Security is already enabled")
|
||||
logging.LogMessage(progress, ctx, "Security is already enabled")
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("failed to create triplestore user: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
logging.LogMessage(progress, "Enabling Triplestore security")
|
||||
logging.LogMessage(progress, ctx, "Enabling Triplestore security")
|
||||
{
|
||||
res, err := ts.OpenRaw(ctx, "POST", "/rest/security", true, "", "")
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue