mirror of
https://github.com/kairos-io/kcrypt.git
synced 2025-09-03 16:07:07 +00:00
Add golint
Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com>
This commit is contained in:
12
Earthfile
12
Earthfile
@@ -3,6 +3,9 @@ VERSION 0.6
|
|||||||
# TODO: This needs to come from pre-built kernels in c3os repos, kcrypt included.
|
# TODO: This needs to come from pre-built kernels in c3os repos, kcrypt included.
|
||||||
# Framework images should use our initrd
|
# Framework images should use our initrd
|
||||||
ARG BASE_IMAGE=quay.io/kairos/core-opensuse
|
ARG BASE_IMAGE=quay.io/kairos/core-opensuse
|
||||||
|
# renovate: datasource=docker depName=golang
|
||||||
|
ARG GO_VERSION=1.20.2
|
||||||
|
ARG GOLINT_VERSION=1.52.2
|
||||||
|
|
||||||
build-kcrypt:
|
build-kcrypt:
|
||||||
FROM golang:alpine
|
FROM golang:alpine
|
||||||
@@ -64,6 +67,15 @@ iso:
|
|||||||
SAVE ARTIFACT /build/$ISO_NAME.iso iso AS LOCAL build/$ISO_NAME.iso
|
SAVE ARTIFACT /build/$ISO_NAME.iso iso AS LOCAL build/$ISO_NAME.iso
|
||||||
SAVE ARTIFACT /build/$ISO_NAME.iso.sha256 sha256 AS LOCAL build/$ISO_NAME.iso.sha256
|
SAVE ARTIFACT /build/$ISO_NAME.iso.sha256 sha256 AS LOCAL build/$ISO_NAME.iso.sha256
|
||||||
|
|
||||||
|
golint:
|
||||||
|
ARG GO_VERSION
|
||||||
|
FROM golang:$GO_VERSION
|
||||||
|
ARG GOLINT_VERSION
|
||||||
|
RUN wget -O- -nv https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v$GOLINT_VERSION
|
||||||
|
WORKDIR /build
|
||||||
|
COPY . .
|
||||||
|
RUN golangci-lint run
|
||||||
|
|
||||||
yamllint:
|
yamllint:
|
||||||
FROM cytopia/yamllint
|
FROM cytopia/yamllint
|
||||||
COPY . .
|
COPY . .
|
||||||
|
38
main.go
38
main.go
@@ -2,7 +2,6 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@@ -24,8 +23,11 @@ var Version = "v0.0.0-dev"
|
|||||||
|
|
||||||
func waitdevice(device string, attempts int) error {
|
func waitdevice(device string, attempts int) error {
|
||||||
for tries := 0; tries < attempts; tries++ {
|
for tries := 0; tries < attempts; tries++ {
|
||||||
sh("udevadm settle")
|
_, err := sh("udevadm settle")
|
||||||
_, err := os.Lstat(device)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = os.Lstat(device)
|
||||||
if !os.IsNotExist(err) {
|
if !os.IsNotExist(err) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -44,7 +46,10 @@ func getPassword(b *block.Partition) (password string, err error) {
|
|||||||
err = fmt.Errorf("failed discovery: %s", r.Error)
|
err = fmt.Errorf("failed discovery: %s", r.Error)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
bus.Manager.Publish(bus.EventDiscoveryPassword, b)
|
_, err = bus.Manager.Publish(bus.EventDiscoveryPassword, b)
|
||||||
|
if err != nil {
|
||||||
|
return password, err
|
||||||
|
}
|
||||||
|
|
||||||
if password == "" {
|
if password == "" {
|
||||||
return password, fmt.Errorf("received empty password")
|
return password, fmt.Errorf("received empty password")
|
||||||
@@ -95,19 +100,6 @@ func createLuks(dev, password, version string, cryptsetupArgs ...string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createDiskImage() (*os.File, error) {
|
|
||||||
disk, err := ioutil.TempFile("", "luksv2.go.disk")
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := disk.Truncate(24 * 1024 * 1024); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return disk, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: A crypt disk utility to call after install, that with discovery discoveries the password that should be used
|
// TODO: A crypt disk utility to call after install, that with discovery discoveries the password that should be used
|
||||||
// this function should delete COS_PERSISTENT. delete the partition and create a luks+type in place.
|
// this function should delete COS_PERSISTENT. delete the partition and create a luks+type in place.
|
||||||
|
|
||||||
@@ -210,9 +202,13 @@ func detect(archive string) (string, error) {
|
|||||||
|
|
||||||
// TODO: replace with golang native code
|
// TODO: replace with golang native code
|
||||||
func extractInitrd(initrd string, dst string) error {
|
func extractInitrd(initrd string, dst string) error {
|
||||||
os.MkdirAll(dst, os.ModePerm)
|
|
||||||
var out string
|
var out string
|
||||||
var err error
|
var err error
|
||||||
|
err = os.MkdirAll(dst, os.ModePerm)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
format, err := detect(initrd)
|
format, err := detect(initrd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -256,7 +252,7 @@ func injectInitrd(initrd string, file, dst string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
tmp, err := ioutil.TempDir("", "kcrypt")
|
tmp, err := os.MkdirTemp("", "kcrypt")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot create tempdir, %s", err)
|
return fmt.Errorf("cannot create tempdir, %s", err)
|
||||||
}
|
}
|
||||||
@@ -297,8 +293,8 @@ func unlockAll() error {
|
|||||||
if p.Type == "crypto_LUKS" {
|
if p.Type == "crypto_LUKS" {
|
||||||
p.Label = config.LookupLabelForUUID(p.UUID)
|
p.Label = config.LookupLabelForUUID(p.UUID)
|
||||||
fmt.Printf("Unmounted Luks found at '%s' LABEL '%s' \n", p.Name, p.Label)
|
fmt.Printf("Unmounted Luks found at '%s' LABEL '%s' \n", p.Name, p.Label)
|
||||||
err = multierror.Append(err, unlockDisk(p))
|
multiError := multierror.Append(err, unlockDisk(p))
|
||||||
if err != nil {
|
if multiError.ErrorOrNil() != nil {
|
||||||
fmt.Printf("Unlocking failed: '%s'\n", err.Error())
|
fmt.Printf("Unlocking failed: '%s'\n", err.Error())
|
||||||
}
|
}
|
||||||
time.Sleep(10 * time.Second)
|
time.Sleep(10 * time.Second)
|
||||||
|
@@ -4,7 +4,7 @@ package config
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/jaypipes/ghw/pkg/block"
|
"github.com/jaypipes/ghw/pkg/block"
|
||||||
@@ -97,7 +97,7 @@ func (c *Config) WriteMappings(fileName string) error {
|
|||||||
|
|
||||||
data = append([]byte(collector.DefaultHeader+"\n"), data...)
|
data = append([]byte(collector.DefaultHeader+"\n"), data...)
|
||||||
|
|
||||||
err = ioutil.WriteFile(fileName, data, 0744)
|
err = os.WriteFile(fileName, data, 0744)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "writing the kcrypt configuration file")
|
return errors.Wrap(err, "writing the kcrypt configuration file")
|
||||||
}
|
}
|
||||||
|
@@ -124,8 +124,11 @@ kcrypt:
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("replaces the file contents", func() {
|
It("replaces the file contents", func() {
|
||||||
c.SetMapping("COS_PERSISTENT:the_new_name:the_new_uuid")
|
<<<<<<< HEAD
|
||||||
c.WriteMappings(tmpFile.Name())
|
err := c.SetMapping("COS_PERSISTENT:the_new_name:the_new_uuid")
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
err = c.WriteMappings(tmpFile.Name())
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
data, err := os.ReadFile(tmpFile.Name())
|
data, err := os.ReadFile(tmpFile.Name())
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(collector.HasValidHeader(string(data))).To(BeTrue())
|
Expect(collector.HasValidHeader(string(data))).To(BeTrue())
|
||||||
@@ -145,8 +148,9 @@ kcrypt:
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("creates the file with the given mappings", func() {
|
It("creates the file with the given mappings", func() {
|
||||||
c.SetMapping("COS_PERSISTENT:the_new_name:the_new_uuid")
|
err := c.SetMapping("COS_PERSISTENT:the_new_name:the_new_uuid")
|
||||||
err := c.WriteMappings(tmpFile.Name())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
err = c.WriteMappings(tmpFile.Name())
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
newConfig, err := configpkg.GetConfiguration([]string{tmpDir})
|
newConfig, err := configpkg.GetConfiguration([]string{tmpDir})
|
||||||
@@ -164,8 +168,10 @@ kcrypt:
|
|||||||
tmpFile, err = os.CreateTemp(tmpDir, "config-*.yaml")
|
tmpFile, err = os.CreateTemp(tmpDir, "config-*.yaml")
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
// Should trim the whitespace
|
// Should trim the whitespace
|
||||||
c.SetMapping("COS_PERSISTENT:the_new_name:some_uuid_1\n")
|
err = c.SetMapping("COS_PERSISTENT:the_new_name:some_uuid_1\n")
|
||||||
c.WriteMappings(tmpFile.Name())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
err = c.WriteMappings(tmpFile.Name())
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
})
|
})
|
||||||
|
|
||||||
It("returns the correct UUID", func() {
|
It("returns the correct UUID", func() {
|
||||||
@@ -192,8 +198,10 @@ kcrypt:
|
|||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
tmpFile, err = os.CreateTemp(tmpDir, "config-*.yaml")
|
tmpFile, err = os.CreateTemp(tmpDir, "config-*.yaml")
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
c.SetMapping("COS_PERSISTENT:the_new_name:some_uuid_1")
|
err = c.SetMapping("COS_PERSISTENT:the_new_name:some_uuid_1")
|
||||||
c.WriteMappings(tmpFile.Name())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
err = c.WriteMappings(tmpFile.Name())
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
})
|
})
|
||||||
|
|
||||||
It("returns the correct label", func() {
|
It("returns the correct label", func() {
|
||||||
|
Reference in New Issue
Block a user