Skip to content

Commit

Permalink
feat: allow rpm import to skip upload OR import step
Browse files Browse the repository at this point in the history
n.b. skipping both steps can be accomplished by not running the command
:)
  • Loading branch information
NeilHanlon committed Jul 25, 2024
1 parent dba4868 commit 9bdcda7
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 11 deletions.
23 changes: 23 additions & 0 deletions peridot/cmd/v1/peridot/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,26 @@ go_binary(
embed = [":peridot_lib"],
visibility = ["//visibility:public"],
)

pkg_files(
name = "peridot-files",
srcs = [":peridot"],
attributes = pkg_attributes(
user = "root",
group = "root",
mode = "0755",
),
prefix = "/usr/bin"
)

pkg_rpm(
name = "peridot-cli",
srcs = [":peridot-files"],
license = "MIT",
summary = "Peridot Command Line Interface",
version = "0.2.1",
release = "0",
architecture = "x86_64",
description = "A command line interface to interact with the Peridot build system",
source_date_epoch = 0,
)
48 changes: 37 additions & 11 deletions peridot/cmd/v1/peridot/build_rpm_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ package main

import (
"encoding/base64"
"github.com/spf13/cobra"
"io/ioutil"
"log"
"openapi.peridot.resf.org/peridotopenapi"
"os"
"strings"
"time"
"crypto/sha256"
"encoding/hex"
"github.com/spf13/cobra"
"openapi.peridot.resf.org/peridotopenapi"
)

type LookasideUploadTask struct {
Expand All @@ -57,9 +59,11 @@ var buildRpmImport = &cobra.Command{
}

var buildRpmImportForceOverride bool
var skipStep string

func init() {
buildRpmImport.Flags().BoolVar(&buildRpmImportForceOverride, "force-override", true, "Force override even if version exists (default: true)")
buildRpmImport.Flags().StringVarP(&skipStep, "skip", "s", "", "which step to skip")
}

func isFile(path string) bool {
Expand All @@ -70,10 +74,24 @@ func isFile(path string) bool {
return true
}

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

var skipUpload bool = false
var skipImport bool = false

if skipStep != "" {
switch strings.ToLower(skipStep) {
case "upload":
skipUpload = true
case "import":
skipImport = true
default:
log.Fatalf("invalid skip step: %s", skipStep)
}
}

// Ensure all args are valid files
for _, arg := range args {
if !isFile(arg) {
Expand All @@ -85,16 +103,24 @@ func buildRpmImportMn(_ *cobra.Command, args []string) {
var blobs []string
projectCl := getClient(serviceProject).(peridotopenapi.ProjectServiceApi)
for _, arg := range args {
bts, err := ioutil.ReadFile(arg)
bts, err := os.ReadFile(arg)
errFatal(err)
base64EncodedBytes := base64.StdEncoding.EncodeToString(bts)
hash := sha256.Sum256(bts)
shasum := hex.EncodeToString(hash[:])

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

res, _, err := projectCl.LookasideFileUpload(getContext()).Body(peridotopenapi.V1LookasideFileUploadRequest{
File: &base64EncodedBytes,
}).Execute()
errFatal(err)
log.Printf("Uploaded %s to lookaside", arg)
blobs = append(blobs, res.GetDigest())
if skipImport {
return
}

taskCl := getClient(serviceTask).(peridotopenapi.TaskServiceApi)
Expand Down

0 comments on commit 9bdcda7

Please sign in to comment.