Skip to content

File based file name storage backend implementation - #101

Closed
slashben wants to merge 14 commits into
mainfrom
file-based-poc
Closed

slashben wants to merge 14 commits into
mainfrom
file-based-poc

Conversation

@slashben

Copy link
Copy Markdown
Contributor

Overview

slashben added 2 commits July 23, 2023 19:06
Signed-off-by: Ben <ben@armosec.io>
Signed-off-by: Ben <ben@armosec.io>

@slashben slashben left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix it

Comment thread pkg/filehandler/v1/file_handler.go
Comment thread pkg/filehandler/v1/file_handler.go Outdated
Comment on lines +150 to +208
// Normalize the bucket name
container = NormalizeBucketName(container)

// Create a map of string to bool
fileList := make(map[string]bool)
// Check if bucket exists in the map
f.Lock.Lock()
fileObject, ok := f.fileMap[container]
if !ok {
f.Lock.Unlock()
return fileList, fmt.Errorf("bucket does not exist for container %s", container)
}
f.Lock.Unlock()

// Lock the file
fileObject.Lock.Lock()
// Close the file
fileObject.FileObject.Close()

// Do not use defer here! It makes life much harder

// Copy the file to a new file
storageFileName := fmt.Sprintf("%s/%s.txt", f.dirPath, container)
storageFileCopyName := fmt.Sprintf("%s/%s_copy.txt", f.dirPath, container)
// Copy the file
err := copyFile(storageFileName, storageFileCopyName)
if err != nil {
fileObject.FileObject, _ = os.OpenFile(storageFileName, os.O_CREATE|os.O_WRONLY, 0644)
fileObject.Lock.Unlock()
return fileList, err
}

// Open the file
fileObject.FileObject, err = os.OpenFile(storageFileName, os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
fileObject.Lock.Unlock()
return fileList, err
}
fileObject.Writer = bufio.NewWriter(fileObject.FileObject)

// Unlock the file and let other goroutines use it
fileObject.Lock.Unlock()

// Read the file line by line
file, err := os.Open(storageFileCopyName)
if err != nil {
return fileList, err
}
defer file.Close()
defer os.Remove(storageFileCopyName)
scanner := bufio.NewScanner(file)
for scanner.Scan() {
fileList[scanner.Text()] = true
}
if err := scanner.Err(); err != nil {
return fileList, err
}
return fileList, nil
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to protect this as per bucket against re-entrancy (there is a single "copy" file that can be overwritten)

Comment thread pkg/filehandler/v1/file_handler.go
Comment thread pkg/filehandler/v1/file_handler.go Outdated
Comment thread pkg/filehandler/v1/file_handler.go
Comment thread pkg/filehandler/v1/file_handler.go
Comment thread pkg/filehandler/v1/file_handler.go Outdated
Comment thread pkg/filehandler/v1/file_handler.go Outdated
David Wertenteil and others added 2 commits July 23, 2023 20:02
Signed-off-by: Ben <ben@armosec.io>
@github-actions

Copy link
Copy Markdown

Summary:

  • License scan: success
  • Credentials scan: success
  • Vulnerabilities scan: success
  • Unit test: success
  • Go linting: failure

@github-actions

Copy link
Copy Markdown

Summary:

  • License scan: success
  • Credentials scan: success
  • Vulnerabilities scan: success
  • Unit test: success
  • Go linting: failure

@github-actions

Copy link
Copy Markdown

Summary:

  • License scan: success
  • Credentials scan: success
  • Vulnerabilities scan: success
  • Unit test: success
  • Go linting: failure

@github-actions

Copy link
Copy Markdown

Summary:

  • License scan: success
  • Credentials scan: success
  • Vulnerabilities scan: success
  • Unit test: success
  • Go linting: failure

@github-actions

Copy link
Copy Markdown

Summary:

  • License scan: success
  • Credentials scan: success
  • Vulnerabilities scan: success
  • Unit test: success
  • Go linting: failure

@github-actions

Copy link
Copy Markdown

Summary:

  • License scan: success
  • Credentials scan: success
  • Vulnerabilities scan: success
  • Unit test: success
  • Go linting: failure

Signed-off-by: Ben <ben@armosec.io>
@github-actions

Copy link
Copy Markdown

Summary:

  • License scan: success
  • Credentials scan: success
  • Vulnerabilities scan: success
  • Unit test: success
  • Go linting: failure

Signed-off-by: Ben <ben@armosec.io>
@github-actions

Copy link
Copy Markdown

Summary:

  • License scan: success
  • Credentials scan: success
  • Vulnerabilities scan: success
  • Unit test: success
  • Go linting: failure

@dwertent

dwertent commented Aug 4, 2023

Copy link
Copy Markdown

We have decided to move forward with the in-memory storage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants