Skip to content

Commit

Permalink
fix: don't encode bytes if we don't have to
Browse files Browse the repository at this point in the history
  • Loading branch information
NeilHanlon committed Jul 25, 2024
1 parent 9bdcda7 commit cfd9d9b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion peridot/cmd/v1/peridot/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pkg_rpm(
license = "MIT",
summary = "Peridot Command Line Interface",
version = "0.2.1",
release = "0",
release = "1",
architecture = "x86_64",
description = "A command line interface to interact with the Peridot build system",
source_date_epoch = 0,
Expand Down
16 changes: 10 additions & 6 deletions peridot/cmd/v1/peridot/build_rpm_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@
package main

import (
"crypto/sha256"
"encoding/base64"
"encoding/hex"
"log"
"os"
"strings"
"time"
"crypto/sha256"
"encoding/hex"

"github.com/spf13/cobra"
"openapi.peridot.resf.org/peridotopenapi"
)
Expand Down Expand Up @@ -74,12 +75,12 @@ func isFile(path string) bool {
return true
}

func buildRpmImportMn(c *cobra.Command, args []string) {
func buildRpmImportMn(_ *cobra.Command, args []string) {
// Ensure project id exists
projectId := mustGetProjectID()

var skipUpload bool = false
var skipImport bool = false
var skipUpload = false
var skipImport = false

if skipStep != "" {
switch strings.ToLower(skipStep) {
Expand All @@ -103,19 +104,22 @@ func buildRpmImportMn(c *cobra.Command, args []string) {
var blobs []string
projectCl := getClient(serviceProject).(peridotopenapi.ProjectServiceApi)
for _, arg := range args {

bts, err := os.ReadFile(arg)
errFatal(err)
base64EncodedBytes := base64.StdEncoding.EncodeToString(bts)

hash := sha256.Sum256(bts)
shasum := hex.EncodeToString(hash[:])

if !skipUpload {
base64EncodedBytes := base64.StdEncoding.EncodeToString(bts)
_, _, err := projectCl.LookasideFileUpload(getContext()).Body(peridotopenapi.V1LookasideFileUploadRequest{
File: &base64EncodedBytes,
}).Execute()
errFatal(err)
log.Printf("Uploaded %s to lookaside", arg)
}
log.Printf("Will upload %s to lookaside for %s", shasum, arg)
blobs = append(blobs, shasum)
}

Expand Down

0 comments on commit cfd9d9b

Please sign in to comment.