Skip to content
This repository has been archived by the owner on Dec 9, 2022. It is now read-only.

Commit

Permalink
Simplify hasher with just a random generated string
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro Cunha committed Oct 13, 2017
1 parent b4e255d commit 422e487
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 112 deletions.
15 changes: 5 additions & 10 deletions cli/data/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/aws/aws-sdk-go/service/s3/s3manager"
"github.com/deliveroo/paddle/common"
"github.com/deliveroo/paddle/rand"
"github.com/spf13/afero"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand Down Expand Up @@ -76,7 +76,7 @@ func commitPath(path string, destination S3Path) {
SharedConfigState: session.SharedConfigEnable,
}))

rootKey := generateRootKey(path, destination)
rootKey := generateRootKey(destination)
keys := filesToKeys(path)
uploader := s3manager.NewUploader(sess)

Expand All @@ -102,18 +102,13 @@ func filesToKeys(path string) (keys []string) {
return keys
}

func generateRootKey(source string, destination S3Path) string {
func generateRootKey(destination S3Path) string {
t := time.Now().UTC()
datePath := fmt.Sprintf("%d/%02d/%02d/%02d%02d",
datePath := fmt.Sprintf("%d/%02d/%02d/%02d/%02d",
t.Year(), t.Month(), t.Day(),
t.Hour(), t.Minute())

hash, err := common.DirHash(source)
if err != nil {
exitErrorf("Unable to hash input folder")
}

return fmt.Sprintf("%s/%s_%s", destination.path, datePath, hash)
return fmt.Sprintf("%s/%s_%s", destination.path, datePath, rand.String(10))
}

func uploadFileToS3(uploader *s3manager.Uploader, bucket string, key string, filePath string) {
Expand Down
81 changes: 0 additions & 81 deletions common/hasher.go

This file was deleted.

21 changes: 0 additions & 21 deletions common/path.go

This file was deleted.

24 changes: 24 additions & 0 deletions rand/strings.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package rand

import (
"math/rand"
"time"
)

const charset = "abcdefghijklmnopqrstuvwxyz" +
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"

var seededRand *rand.Rand = rand.New(
rand.NewSource(time.Now().UnixNano()))

func StringWithCharset(length int, charset string) string {
b := make([]byte, length)
for i := range b {
b[i] = charset[seededRand.Intn(len(charset))]
}
return string(b)
}

func String(length int) string {
return StringWithCharset(length, charset)
}

0 comments on commit 422e487

Please sign in to comment.