mirror of
https://github.com/kairos-io/kcrypt.git
synced 2025-05-09 16:56:57 +00:00
Merge pull request #15 from kairos-io/bump-go-version-to-1.20.2
⬆️ bump go version to 1.20.2
This commit is contained in:
commit
92c79f4e75
28
.github/workflows/lint.yaml
vendored
Normal file
28
.github/workflows/lint.yaml
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
name: Lint
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
pull_request:
|
||||
paths:
|
||||
- '**'
|
||||
env:
|
||||
FORCE_COLOR: 1
|
||||
jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Install Go
|
||||
uses: actions/setup-go@v4
|
||||
- name: Install earthly
|
||||
uses: Luet-lab/luet-install-action@v1
|
||||
with:
|
||||
repository: quay.io/kairos/packages
|
||||
packages: utils/earthly
|
||||
- name: Run Lint checks
|
||||
run: |
|
||||
earthly +lint
|
10
.github/workflows/unit-tests.yml
vendored
10
.github/workflows/unit-tests.yml
vendored
@ -1,9 +1,9 @@
|
||||
name: Unit tests
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
unit-tests:
|
||||
@ -16,7 +16,7 @@ jobs:
|
||||
- name: Install Go
|
||||
uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: '^1.18'
|
||||
go-version: '^1.20'
|
||||
|
||||
- name: Install Ginkgo
|
||||
run: go install github.com/onsi/ginkgo/v2/ginkgo@v2.5.0
|
||||
|
21
.yamllint
Normal file
21
.yamllint
Normal file
@ -0,0 +1,21 @@
|
||||
extends: default
|
||||
|
||||
rules:
|
||||
# 80 chars should be enough, but don't fail if a line is longer
|
||||
line-length:
|
||||
max: 150
|
||||
level: warning
|
||||
|
||||
# accept both key:
|
||||
# - item
|
||||
#
|
||||
# and key:
|
||||
# - item
|
||||
indentation:
|
||||
indent-sequences: whatever
|
||||
|
||||
truthy:
|
||||
check-keys: false
|
||||
|
||||
document-start:
|
||||
present: false
|
21
Earthfile
21
Earthfile
@ -3,6 +3,9 @@ VERSION 0.6
|
||||
# TODO: This needs to come from pre-built kernels in c3os repos, kcrypt included.
|
||||
# Framework images should use our initrd
|
||||
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:
|
||||
FROM golang:alpine
|
||||
@ -63,3 +66,21 @@ iso:
|
||||
RUN sha256sum $ISO_NAME.iso > $ISO_NAME.iso.sha256
|
||||
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
|
||||
|
||||
lint:
|
||||
BUILD +golint
|
||||
BUILD +yamllint
|
||||
|
||||
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:
|
||||
FROM cytopia/yamllint
|
||||
COPY . .
|
||||
RUN yamllint .github/workflows/
|
||||
|
2
go.mod
2
go.mod
@ -1,6 +1,6 @@
|
||||
module github.com/kairos-io/kcrypt
|
||||
|
||||
go 1.18
|
||||
go 1.20
|
||||
|
||||
require (
|
||||
github.com/anatol/luks.go v0.0.0-20230125211543-ada2562d4206
|
||||
|
38
main.go
38
main.go
@ -2,7 +2,6 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
@ -24,8 +23,11 @@ var Version = "v0.0.0-dev"
|
||||
|
||||
func waitdevice(device string, attempts int) error {
|
||||
for tries := 0; tries < attempts; tries++ {
|
||||
sh("udevadm settle")
|
||||
_, err := os.Lstat(device)
|
||||
_, err := sh("udevadm settle")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = os.Lstat(device)
|
||||
if !os.IsNotExist(err) {
|
||||
return nil
|
||||
}
|
||||
@ -44,7 +46,10 @@ func getPassword(b *block.Partition) (password string, err 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 == "" {
|
||||
return password, fmt.Errorf("received empty password")
|
||||
@ -95,19 +100,6 @@ func createLuks(dev, password, version string, cryptsetupArgs ...string) error {
|
||||
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
|
||||
// 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
|
||||
func extractInitrd(initrd string, dst string) error {
|
||||
os.MkdirAll(dst, os.ModePerm)
|
||||
var out string
|
||||
var err error
|
||||
err = os.MkdirAll(dst, os.ModePerm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
format, err := detect(initrd)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -256,7 +252,7 @@ func injectInitrd(initrd string, file, dst string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tmp, err := ioutil.TempDir("", "kcrypt")
|
||||
tmp, err := os.MkdirTemp("", "kcrypt")
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot create tempdir, %s", err)
|
||||
}
|
||||
@ -297,8 +293,8 @@ func unlockAll() error {
|
||||
if p.Type == "crypto_LUKS" {
|
||||
p.Label = config.LookupLabelForUUID(p.UUID)
|
||||
fmt.Printf("Unmounted Luks found at '%s' LABEL '%s' \n", p.Name, p.Label)
|
||||
err = multierror.Append(err, unlockDisk(p))
|
||||
if err != nil {
|
||||
multiError := multierror.Append(err, unlockDisk(p))
|
||||
if multiError.ErrorOrNil() != nil {
|
||||
fmt.Printf("Unlocking failed: '%s'\n", err.Error())
|
||||
}
|
||||
time.Sleep(10 * time.Second)
|
||||
|
@ -4,7 +4,7 @@ package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/jaypipes/ghw/pkg/block"
|
||||
@ -97,7 +97,7 @@ func (c *Config) WriteMappings(fileName string) error {
|
||||
|
||||
data = append([]byte(collector.DefaultHeader+"\n"), data...)
|
||||
|
||||
err = ioutil.WriteFile(fileName, data, 0744)
|
||||
err = os.WriteFile(fileName, data, 0744)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "writing the kcrypt configuration file")
|
||||
}
|
||||
|
@ -124,8 +124,10 @@ kcrypt:
|
||||
})
|
||||
|
||||
It("replaces the file contents", func() {
|
||||
c.SetMapping("COS_PERSISTENT:the_new_name:the_new_uuid")
|
||||
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())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(collector.HasValidHeader(string(data))).To(BeTrue())
|
||||
@ -145,8 +147,9 @@ kcrypt:
|
||||
})
|
||||
|
||||
It("creates the file with the given mappings", func() {
|
||||
c.SetMapping("COS_PERSISTENT:the_new_name:the_new_uuid")
|
||||
err := 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())
|
||||
|
||||
newConfig, err := configpkg.GetConfiguration([]string{tmpDir})
|
||||
@ -164,8 +167,10 @@ kcrypt:
|
||||
tmpFile, err = os.CreateTemp(tmpDir, "config-*.yaml")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
// Should trim the whitespace
|
||||
c.SetMapping("COS_PERSISTENT:the_new_name:some_uuid_1\n")
|
||||
c.WriteMappings(tmpFile.Name())
|
||||
err = c.SetMapping("COS_PERSISTENT:the_new_name:some_uuid_1\n")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
err = c.WriteMappings(tmpFile.Name())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
})
|
||||
|
||||
It("returns the correct UUID", func() {
|
||||
@ -192,8 +197,10 @@ kcrypt:
|
||||
BeforeEach(func() {
|
||||
tmpFile, err = os.CreateTemp(tmpDir, "config-*.yaml")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
c.SetMapping("COS_PERSISTENT:the_new_name:some_uuid_1")
|
||||
c.WriteMappings(tmpFile.Name())
|
||||
err = c.SetMapping("COS_PERSISTENT:the_new_name:some_uuid_1")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
err = c.WriteMappings(tmpFile.Name())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
})
|
||||
|
||||
It("returns the correct label", func() {
|
||||
|
Loading…
Reference in New Issue
Block a user