Compare commits

...

4 Commits

Author SHA1 Message Date
Dimitris Karakasilis
7d077c9353 Merge pull request #6 from kairos-io/dont-let-mapping-be-nil
Don't let the mapping be nil when reading an empty file
2022-11-16 09:30:31 +02:00
Dimitris Karakasilis
0e278a89f0 Don't let the mapping be nil when reading an empty file
e.g. when we first create it

because it throws this error:

```
panic: assignment to entry in nil map

goroutine 1 [running]:
github.com/kairos-io/kcrypt/pkg/partition_info.PartitionInfo.UpdateMapping({{0xa60325?, 0x18?}, 0x0?}, {0xc000302000?, 0x1?})
	/go/pkg/mod/github.com/kairos-io/kcrypt@v0.4.2/pkg/partition_info/partition_info.go:69 +0x99

```

Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me>
2022-11-15 19:45:44 +02:00
Dimitris Karakasilis
7310c313ee Merge pull request #5 from kairos-io/fix-version-bug-and-typpos
Fix typo in name, bad function call and version of the binary
2022-11-15 15:13:05 +02:00
Dimitris Karakasilis
b9572125e1 Fix typo in name, bad function call and version of the binary
Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me>
2022-11-15 15:09:56 +02:00
4 changed files with 19 additions and 6 deletions

View File

@@ -6,9 +6,11 @@ ARG BASE_IMAGE=quay.io/kairos/core-opensuse
build-kcrypt:
FROM golang:alpine
RUN apk add git
COPY . /work
WORKDIR /work
RUN CGO_ENABLED=0 go build -o kcrypt
ARG VERSION="$(git describe --tags)"
RUN CGO_ENABLED=0 go build -o kcrypt -ldflags "-X main.Version=$VERSION"
SAVE ARTIFACT /work/kcrypt AS LOCAL kcrypt
build-dracut:

10
main.go
View File

@@ -21,6 +21,8 @@ import (
pi "github.com/kairos-io/kcrypt/pkg/partition_info"
)
var Version = "v0.0.0-dev"
func waitdevice(device string, attempts int) error {
for tries := 0; tries < attempts; tries++ {
sh("udevadm settle")
@@ -279,7 +281,7 @@ func injectInitrd(initrd string, file, dst string) error {
func unlockAll() error {
bus.Manager.Initialize()
partitionInfo, err := pi.NewPartitionInfoFromFile(pi.DefaultPartitionInfoFile)
partitionInfo, _, err := pi.NewPartitionInfoFromFile(pi.DefaultPartitionInfoFile)
if err != nil {
return err
}
@@ -305,10 +307,10 @@ func unlockAll() error {
func main() {
app := &cli.App{
Name: "keiros-kcrypt",
Version: "0.1",
Name: "kairos-kcrypt",
Version: Version,
Author: "Ettore Di Giacinto",
Usage: "keiros escrow key agent component",
Usage: "kairos escrow key agent component",
Description: ``,
UsageText: ``,
Copyright: "Ettore Di Giacinto",

View File

@@ -71,6 +71,10 @@ func (pi PartitionInfo) UpdateMapping(partitionData string) error {
return pi.save()
}
func (pi PartitionInfo) IsMappingNil() bool {
return pi.mapping == nil
}
func (pi PartitionInfo) save() error {
data, err := yaml.Marshal(&pi.mapping)
if err != nil {
@@ -107,6 +111,9 @@ func ParsePartitionInfoFile(file string) (map[string]string, error) {
if err != nil {
return result, errors.Wrap(err, "unmarshalling partition info file")
}
if result == nil {
result = map[string]string{}
}
return result, nil
}

View File

@@ -38,13 +38,15 @@ var _ = Describe("Partition Info file parsing", func() {
fmt.Sprintf("partition-info-%d.yaml", time.Now().UnixNano()))
})
It("creates the file and returns 'false' and an (empty) mapping", func() {
It("creates the file and returns 'false' and a non nil mapping", func() {
result, existed, err := pi.NewPartitionInfoFromFile(fileName)
Expect(err).ToNot(HaveOccurred())
Expect(result).ToNot(BeNil())
Expect(existed).To(BeFalse())
_, err = os.Stat(fileName)
Expect(err).ToNot(HaveOccurred())
Expect(result).ToNot(BeNil())
Expect(result.IsMappingNil()).To(BeFalse())
})
})
})