security: Update go-uuid and mholt/archiver to recommended version (#2216)

* security: Update go-uuid to recommended version
* security: Update mholt/archiver dep to recommended version

Signed-off-by: Sanket Sudake <sanketsudake@gmail.com>
This commit is contained in:
Sanket Sudake
2021-10-06 13:24:54 +05:30
committed by GitHub
parent 0d319c07ae
commit e4d5565f8e
19 changed files with 113 additions and 36 deletions
+3 -1
View File
@@ -359,7 +359,9 @@ func TestMain(m *testing.M) {
panicIf(err)
// testNS isolation for running multiple CI builds concurrently.
testNS = uuid.NewV4().String()
id, err := uuid.NewV4()
panicIf(err)
testNS = id.String()
_, err = kubeClient.CoreV1().Namespaces().Create(context.TODO(), &v1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: testNS,
+10 -2
View File
@@ -354,8 +354,16 @@ func (fetcher *Fetcher) Fetch(ctx context.Context, pkg *fv1.Package, req Functio
if archiver.Zip.Match(tmpPath) && !req.KeepArchive {
// unarchive tmp file to a tmp unarchive path
tmpUnarchivePath := filepath.Join(fetcher.sharedVolumePath, uuid.NewV4().String())
err := fetcher.unarchive(tmpPath, tmpUnarchivePath)
id, err := uuid.NewV4()
if err != nil {
logger.Error("error generating uuid",
zap.Error(err),
zap.String("archive_location", tmpPath))
return http.StatusInternalServerError, err
}
tmpUnarchivePath := filepath.Join(fetcher.sharedVolumePath, id.String())
err = fetcher.unarchive(tmpPath, tmpUnarchivePath)
if err != nil {
logger.Error("error unarchive",
zap.Error(err),
+10 -2
View File
@@ -214,7 +214,11 @@ func (opts *CreateSubCommand) complete(input cli.Input) error {
}
buildcmd := input.String(flagkey.PkgBuildCmd)
pkgName := fmt.Sprintf("%v-%v", fnName, uuid.NewV4().String())
id, err := uuid.NewV4()
if err != nil {
return errors.Wrap(err, "error generating uuid")
}
pkgName := fmt.Sprintf("%v-%v", fnName, id.String())
// create new package in the same namespace as the function.
pkgMetadata, err = _package.CreatePackage(input, opts.Client(), pkgName, fnNamespace, envName, envNamespace,
@@ -363,7 +367,11 @@ func (opts *CreateSubCommand) run(input cli.Input) error {
}
}
triggerName := uuid.NewV4().String()
id, err := uuid.NewV4()
if err != nil {
return errors.Wrap(err, "error generating UUID")
}
triggerName := id.String()
ht := &fv1.HTTPTrigger{
ObjectMeta: metav1.ObjectMeta{
Name: triggerName,
+5 -1
View File
@@ -70,7 +70,11 @@ func (opts *CreateSubCommand) complete(input cli.Input) error {
// just name triggers by uuid.
if len(triggerName) == 0 {
console.Warn(fmt.Sprintf("--%v will be soon marked as required flag, see 'help' for details", flagkey.HtName))
triggerName = uuid.NewV4().String()
id, err := uuid.NewV4()
if err != nil {
return err
}
triggerName = id.String()
}
fnNamespace := input.String(flagkey.NamespaceFunction)
+5 -1
View File
@@ -53,7 +53,11 @@ func (opts *CreateSubCommand) complete(input cli.Input) error {
watchName := input.String(flagkey.KwName)
if len(watchName) == 0 {
console.Warn(fmt.Sprintf("--%v will be soon marked as required flag, see 'help' for details", flagkey.MqtName))
watchName = uuid.NewV4().String()
id, err := uuid.NewV4()
if err != nil {
return errors.Wrap(err, "error generating uuid")
}
watchName = id.String()
}
fnName := input.String(flagkey.KwFnName)
fnNamespace := input.String(flagkey.NamespaceFunction)
+5 -1
View File
@@ -54,7 +54,11 @@ func (opts *CreateSubCommand) complete(input cli.Input) error {
mqtName := input.String(flagkey.MqtName)
if len(mqtName) == 0 {
console.Warn(fmt.Sprintf("--%v will be soon marked as required flag, see 'help' for details", flagkey.MqtName))
mqtName = uuid.NewV4().String()
id, err := uuid.NewV4()
if err != nil {
return err
}
mqtName = id.String()
}
fnName := input.String(flagkey.MqtFnName)
fnNamespace := input.String(flagkey.NamespaceFunction)
+5 -1
View File
@@ -160,7 +160,11 @@ func CreatePackage(input cli.Input, client client.Interface, pkgName string, pkg
}
if len(pkgName) == 0 {
pkgName = strings.ToLower(uuid.NewV4().String())
id, err := uuid.NewV4()
if err != nil {
return nil, errors.Wrap(err, "error generating UUID")
}
pkgName = strings.ToLower(id.String())
}
pkg := &fv1.Package{
+5 -1
View File
@@ -124,7 +124,11 @@ func CreateArchive(client client.Interface, input cli.Input, includeFiles []stri
return nil, err
}
file := filepath.Join(tmpDir, uuid.NewV4().String())
id, err := uuid.NewV4()
if err != nil {
return nil, err
}
file := filepath.Join(tmpDir, id.String())
err = utils.DownloadUrl(context.Background(), http.DefaultClient, fileURL, file)
if err != nil {
return nil, errors.Wrap(err, "error downloading file from the given URL")
+10 -2
View File
@@ -107,7 +107,11 @@ func DownloadToTempFile(fileUrl string) (string, error) {
return "", errors.Wrapf(err, "error creating temp directory %v", tmpDir)
}
tmpFilename := uuid.NewV4().String()
id, err := uuid.NewV4()
if err != nil {
return "", errors.Wrapf(err, "error generating UUID")
}
tmpFilename := id.String()
destination := filepath.Join(tmpDir, tmpFilename)
err = WriteArchiveToFile(destination, reader)
@@ -135,7 +139,11 @@ func WriteArchiveToFile(fileName string, reader io.Reader) error {
if err != nil {
return err
}
tmpFileName := uuid.NewV4().String()
id, err := uuid.NewV4()
if err != nil {
return err
}
tmpFileName := id.String()
path := filepath.Join(tmpDir, tmpFileName+".tmp")
w, err := os.Create(path)
+5 -1
View File
@@ -67,7 +67,11 @@ func (opts *InitSubCommand) complete(input cli.Input) error {
deployID := input.String(flagkey.SpecDeployID)
if len(deployID) == 0 {
deployID = uuid.NewV4().String()
id, err := uuid.NewV4()
if err != nil {
return errors.Wrap(err, "error generating UUID")
}
deployID = id.String()
}
// Create spec dir
+5 -1
View File
@@ -56,7 +56,11 @@ func (opts *CreateSubCommand) do(input cli.Input) error {
func (opts *CreateSubCommand) complete(input cli.Input) error {
name := input.String(flagkey.TtName)
if len(name) == 0 {
name = uuid.NewV4().String()
id, err := uuid.NewV4()
if err != nil {
return err
}
name = id.String()
}
fnName := input.String(flagkey.TtFnName)
+6 -2
View File
@@ -32,10 +32,14 @@ func (ls localStorage) getStorageType() StorageType {
return ls.storageType
}
func (ls localStorage) getUploadFileName() string {
func (ls localStorage) getUploadFileName() (string, error) {
// This is not the item ID (that's returned by Put)
// should we just use handler.Filename? what are the constraints here?
return uuid.NewV4().String()
id, err := uuid.NewV4()
if err != nil {
return "", err
}
return id.String(), err
}
func (ls localStorage) getContainerName() string {
+6 -3
View File
@@ -49,9 +49,12 @@ func (ss s3Storage) getContainerName() string {
return ss.bucketName
}
func (ss s3Storage) getUploadFileName() string {
uploadName := uuid.NewV4().String()
return path.Join(ss.subDir, uploadName)
func (ss s3Storage) getUploadFileName() (string, error) {
id, err := uuid.NewV4()
if err != nil {
return "", err
}
return path.Join(ss.subDir, id.String()), nil
}
func (ss s3Storage) dial() (stow.Location, error) {
+1 -1
View File
@@ -40,7 +40,7 @@ type (
dial() (stow.Location, error)
// getSubDir() string
getContainerName() string
getUploadFileName() string
getUploadFileName() (string, error)
}
// StorageService is a struct to hold all things for storage service
+4 -1
View File
@@ -111,7 +111,10 @@ func MakeStowClient(logger *zap.Logger, storage Storage) (*StowClient, error) {
// putFile writes the file on the storage
func (client *StowClient) putFile(file multipart.File, fileSize int64) (string, error) {
uploadName := client.config.storage.getUploadFileName()
uploadName, err := client.config.storage.getUploadFileName()
if err != nil {
return "", err
}
// save the file to the storage backend
item, err := client.container.Put(uploadName, file, fileSize, nil)
+5 -1
View File
@@ -47,7 +47,11 @@ type (
)
func init() {
Tracker = &tracker{gaPropertyID: os.Getenv(GA_TRACKING_ID), cid: uuid.NewV4().String()}
id, err := uuid.NewV4()
if err != nil {
panic(err)
}
Tracker = &tracker{gaPropertyID: os.Getenv(GA_TRACKING_ID), cid: id.String()}
}
func (t *tracker) SendEvent(e Event) error {
+5 -1
View File
@@ -88,7 +88,11 @@ func IsReadyPod(pod *apiv1.Pod) bool {
// GetTempDir creates and return a temporary directory
func GetTempDir() (string, error) {
tmpDir := uuid.NewV4().String()
id, err := uuid.NewV4()
if err != nil {
return "", err
}
tmpDir := id.String()
dir, err := ioutil.TempDir("", tmpDir)
return dir, err
}