Skip to content

Commit

Permalink
Make Info into Infof and remove deprecated libs
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Mikusa <[email protected]>
  • Loading branch information
dmikusa committed May 22, 2024
1 parent 3a84439 commit 82499a2
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 34 deletions.
8 changes: 2 additions & 6 deletions dare/build_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2020 the original author or authors.
* Copyright 2018-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,7 +17,6 @@
package dare_test

import (
"io/ioutil"
"os"
"testing"

Expand All @@ -41,10 +40,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
)

it.Before(func() {
var err error

ctx.Application.Path, err = ioutil.TempDir("", "build")
Expect(err).NotTo(HaveOccurred())
ctx.Application.Path = t.TempDir()

kp = &mocks.KeyProvider{}
build.KeyProviders = append(build.KeyProviders, kp)
Expand Down
7 changes: 3 additions & 4 deletions dare/encrypt.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2020 the original author or authors.
* Copyright 2018-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,7 +21,6 @@ import (
"crypto/sha256"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"

Expand Down Expand Up @@ -68,7 +67,7 @@ func (e Encrypt) Contribute(layer libcnb.Layer) (libcnb.Layer, error) {

e.Logger.Body("Writing salt")
file := filepath.Join(layer.Path, "salt")
if err := ioutil.WriteFile(file, salt[:], 0644); err != nil {
if err := os.WriteFile(file, salt[:], 0644); err != nil {
return libcnb.Layer{}, fmt.Errorf("unable to write %s\n%w", file, err)
}
layer.LaunchEnvironment.Default("BPI_EAR_SALT_PATH", file)
Expand Down Expand Up @@ -110,7 +109,7 @@ func (e Encrypt) Contribute(layer libcnb.Layer) (libcnb.Layer, error) {
}

e.Logger.Header("Removing source code")
cs, err := ioutil.ReadDir(e.ApplicationPath)
cs, err := os.ReadDir(e.ApplicationPath)
if err != nil {
return libcnb.Layer{}, fmt.Errorf("unable to list children of %s\n%w", e.ApplicationPath, err)
}
Expand Down
16 changes: 5 additions & 11 deletions dare/encrypt_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2020 the original author or authors.
* Copyright 2018-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,7 +21,6 @@ import (
"crypto/sha256"
"encoding/hex"
"io"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand All @@ -43,13 +42,8 @@ func testEncrypt(t *testing.T, context spec.G, it spec.S) {
)

it.Before(func() {
var err error

ctx.Application.Path, err = ioutil.TempDir("", "encrypt-application")
Expect(err).NotTo(HaveOccurred())

ctx.Layers.Path, err = ioutil.TempDir("", "encrypt-layers")
Expect(err).NotTo(HaveOccurred())
ctx.Application.Path = t.TempDir()
ctx.Layers.Path = t.TempDir()
})

it.After(func() {
Expand All @@ -58,7 +52,7 @@ func testEncrypt(t *testing.T, context spec.G, it spec.S) {
})

it("contributes encrypt", func() {
Expect(ioutil.WriteFile(filepath.Join(ctx.Application.Path, "fixture-marker"), []byte{}, 0644)).To(Succeed())
Expect(os.WriteFile(filepath.Join(ctx.Application.Path, "fixture-marker"), []byte{}, 0644)).To(Succeed())

master, err := hex.DecodeString("E48F0660412A993E62FB11CA086C2D353C95359AD3A3480E778FBA43DB694E60")
Expect(err).NotTo(HaveOccurred())
Expand All @@ -81,7 +75,7 @@ func testEncrypt(t *testing.T, context spec.G, it spec.S) {

Expect(layer.LaunchEnvironment["BPI_EAR_DECRYPTED_APPLICATION.default"]).To(Equal(ctx.Application.Path))

salt, err := ioutil.ReadFile(filepath.Join(layer.Path, "salt"))
salt, err := os.ReadFile(filepath.Join(layer.Path, "salt"))
Expect(err).NotTo(HaveOccurred())

var key [32]byte
Expand Down
9 changes: 4 additions & 5 deletions helper/decrypt.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2020 the original author or authors.
* Copyright 2018-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,7 +21,6 @@ import (
"encoding/hex"
"fmt"
"io"
"io/ioutil"
"os"

"github.com/minio/sio"
Expand Down Expand Up @@ -50,7 +49,7 @@ func (d Decrypt) Execute() (map[string]string, error) {
if !ok {
return nil, fmt.Errorf("$BPI_EAR_SALT_PATH must be set")
}
salt, err := ioutil.ReadFile(file)
salt, err := os.ReadFile(file)
if err != nil {
return nil, fmt.Errorf("unable to open %s\n%w", file, err)
}
Expand All @@ -70,7 +69,7 @@ func (d Decrypt) Execute() (map[string]string, error) {
return nil, fmt.Errorf("$BPI_EAR_DECRYPTED_APPLICATION must be set")
}
if unix.Access(file, unix.W_OK) != nil {
d.Logger.Info("ERROR: Unable to decrypt application because %s is not writable", file)
d.Logger.Infof("ERROR: Unable to decrypt application because %s is not writable", file)
return nil, fmt.Errorf("unable to write to %s", file)
}
out := file
Expand All @@ -86,7 +85,7 @@ func (d Decrypt) Execute() (map[string]string, error) {
return nil, fmt.Errorf("unable to create encrypted reader\n%w", err)
}

if err := crush.ExtractTar(r, out, 0); err != nil {
if err := crush.Extract(r, out, 0); err != nil {
return nil, fmt.Errorf("unable to extract TAR %s to %s\n%w", in.Name(), out, err)
}

Expand Down
14 changes: 6 additions & 8 deletions helper/decrypt_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2020 the original author or authors.
* Copyright 2018-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,7 +22,6 @@ import (
"encoding/hex"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -50,17 +49,16 @@ func testDecrypt(t *testing.T, context spec.G, it spec.S) {
it.Before(func() {
var err error

decryptedPath, err = ioutil.TempDir("", "decrypt-decrypted")
Expect(err).NotTo(HaveOccurred())
decryptedPath = t.TempDir()

f, err := ioutil.TempFile("", "decrypt-encrypted")
f, err := os.CreateTemp("", "decrypt-encrypted")
Expect(err).NotTo(HaveOccurred())
Expect(f.Close()).To(Succeed())
encryptedPath = f.Name()

key = "E48F0660412A993E62FB11CA086C2D353C95359AD3A3480E778FBA43DB694E60"

f, err = ioutil.TempFile("", "decrypt-salt")
f, err = os.CreateTemp("", "decrypt-salt")
Expect(err).NotTo(HaveOccurred())
Expect(f.Close()).To(Succeed())
saltPath = f.Name()
Expand Down Expand Up @@ -138,7 +136,7 @@ func testDecrypt(t *testing.T, context spec.G, it spec.S) {
var salt [32]byte
_, err = io.ReadFull(rand.Reader, salt[:])
Expect(err).NotTo(HaveOccurred())
Expect(ioutil.WriteFile(saltPath, salt[:], 0644)).To(Succeed())
Expect(os.WriteFile(saltPath, salt[:], 0644)).To(Succeed())

var key [32]byte
kdf := hkdf.New(sha256.New, primary, salt[:], nil)
Expand All @@ -152,7 +150,7 @@ func testDecrypt(t *testing.T, context spec.G, it spec.S) {
Expect(err).NotTo(HaveOccurred())

file := filepath.Join(decryptedPath, "fixture-marker")
Expect(ioutil.WriteFile(file, []byte{}, 0644)).To(Succeed())
Expect(os.WriteFile(file, []byte{}, 0644)).To(Succeed())
Expect(crush.CreateTar(w, decryptedPath)).To(Succeed())
Expect(os.RemoveAll(file)).To(Succeed())

Expand Down

0 comments on commit 82499a2

Please sign in to comment.