fix: don't encode bytes if we don't have to

This commit is contained in:
Neil Hanlon 2024-03-11 12:02:13 -04:00
parent b3c86f8221
commit 3c00db9e36
Signed by: neil
GPG Key ID: 705BC21EC3C70F34
2 changed files with 11 additions and 7 deletions

View File

@ -65,7 +65,7 @@ pkg_rpm(
license = "MIT", license = "MIT",
summary = "Peridot Command Line Interface", summary = "Peridot Command Line Interface",
version = "0.2.1", version = "0.2.1",
release = "0", release = "1",
architecture = "x86_64", architecture = "x86_64",
description = "A command line interface to interact with the Peridot build system", description = "A command line interface to interact with the Peridot build system",
source_date_epoch = 0, source_date_epoch = 0,

View File

@ -31,13 +31,14 @@
package main package main
import ( import (
"crypto/sha256"
"encoding/base64" "encoding/base64"
"encoding/hex"
"log" "log"
"os" "os"
"strings" "strings"
"time" "time"
"crypto/sha256"
"encoding/hex"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"openapi.peridot.resf.org/peridotopenapi" "openapi.peridot.resf.org/peridotopenapi"
) )
@ -74,12 +75,12 @@ func isFile(path string) bool {
return true return true
} }
func buildRpmImportMn(c *cobra.Command, args []string) { func buildRpmImportMn(_ *cobra.Command, args []string) {
// Ensure project id exists // Ensure project id exists
projectId := mustGetProjectID() projectId := mustGetProjectID()
var skipUpload bool = false var skipUpload = false
var skipImport bool = false var skipImport = false
if skipStep != "" { if skipStep != "" {
switch strings.ToLower(skipStep) { switch strings.ToLower(skipStep) {
@ -103,19 +104,22 @@ func buildRpmImportMn(c *cobra.Command, args []string) {
var blobs []string var blobs []string
projectCl := getClient(serviceProject).(peridotopenapi.ProjectServiceApi) projectCl := getClient(serviceProject).(peridotopenapi.ProjectServiceApi)
for _, arg := range args { for _, arg := range args {
bts, err := os.ReadFile(arg) bts, err := os.ReadFile(arg)
errFatal(err) errFatal(err)
base64EncodedBytes := base64.StdEncoding.EncodeToString(bts)
hash := sha256.Sum256(bts) hash := sha256.Sum256(bts)
shasum := hex.EncodeToString(hash[:]) shasum := hex.EncodeToString(hash[:])
if !skipUpload { if !skipUpload {
base64EncodedBytes := base64.StdEncoding.EncodeToString(bts)
_, _, err := projectCl.LookasideFileUpload(getContext()).Body(peridotopenapi.V1LookasideFileUploadRequest{ _, _, err := projectCl.LookasideFileUpload(getContext()).Body(peridotopenapi.V1LookasideFileUploadRequest{
File: &base64EncodedBytes, File: &base64EncodedBytes,
}).Execute() }).Execute()
errFatal(err) errFatal(err)
log.Printf("Uploaded %s to lookaside", arg) log.Printf("Uploaded %s to lookaside", arg)
} }
log.Printf("Will upload %s to lookaside for %s", shasum, arg)
blobs = append(blobs, shasum) blobs = append(blobs, shasum)
} }