mirror of
https://github.com/rocky-linux/peridot.git
synced 2024-11-24 14:11:25 +00:00
Merge pull request #194 from rocky-linux/feat/import-skip-upload
feat: allow rpm import to skip upload OR import step
This commit is contained in:
commit
549b3a8294
@ -64,8 +64,8 @@ pkg_rpm(
|
|||||||
srcs = [":peridot-files"],
|
srcs = [":peridot-files"],
|
||||||
license = "MIT",
|
license = "MIT",
|
||||||
summary = "Peridot Command Line Interface",
|
summary = "Peridot Command Line Interface",
|
||||||
version = "0.2.0",
|
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,
|
||||||
|
@ -31,13 +31,16 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/sha256"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"github.com/spf13/cobra"
|
"encoding/hex"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"openapi.peridot.resf.org/peridotopenapi"
|
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"openapi.peridot.resf.org/peridotopenapi"
|
||||||
)
|
)
|
||||||
|
|
||||||
type LookasideUploadTask struct {
|
type LookasideUploadTask struct {
|
||||||
@ -57,9 +60,11 @@ var buildRpmImport = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
var buildRpmImportForceOverride bool
|
var buildRpmImportForceOverride bool
|
||||||
|
var skipStep string
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
buildRpmImport.Flags().BoolVar(&buildRpmImportForceOverride, "force-override", true, "Force override even if version exists (default: true)")
|
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 {
|
func isFile(path string) bool {
|
||||||
@ -74,6 +79,20 @@ func buildRpmImportMn(_ *cobra.Command, args []string) {
|
|||||||
// Ensure project id exists
|
// Ensure project id exists
|
||||||
projectId := mustGetProjectID()
|
projectId := mustGetProjectID()
|
||||||
|
|
||||||
|
var skipUpload = false
|
||||||
|
var skipImport = 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
|
// Ensure all args are valid files
|
||||||
for _, arg := range args {
|
for _, arg := range args {
|
||||||
if !isFile(arg) {
|
if !isFile(arg) {
|
||||||
@ -85,16 +104,27 @@ func buildRpmImportMn(_ *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 := ioutil.ReadFile(arg)
|
|
||||||
errFatal(err)
|
|
||||||
base64EncodedBytes := base64.StdEncoding.EncodeToString(bts)
|
|
||||||
|
|
||||||
res, _, err := projectCl.LookasideFileUpload(getContext()).Body(peridotopenapi.V1LookasideFileUploadRequest{
|
bts, err := os.ReadFile(arg)
|
||||||
File: &base64EncodedBytes,
|
|
||||||
}).Execute()
|
|
||||||
errFatal(err)
|
errFatal(err)
|
||||||
log.Printf("Uploaded %s to lookaside", arg)
|
|
||||||
blobs = append(blobs, res.GetDigest())
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
if skipImport {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
taskCl := getClient(serviceTask).(peridotopenapi.TaskServiceApi)
|
taskCl := getClient(serviceTask).(peridotopenapi.TaskServiceApi)
|
||||||
|
Loading…
Reference in New Issue
Block a user