-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: allow generating legal hold bundles in filestore directly #70
Open
fmartingr
wants to merge
21
commits into
main
Choose a base branch
from
feat/download-to-filestore
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
a8f5a0d
download to filestore
fmartingr 93ee03b
cleanupjob
fmartingr ac5c4fc
fixed tests
fmartingr 8115146
new api handler for bundles
fmartingr 7cb362c
better locks
fmartingr ce60c53
upload button
fmartingr 693727d
fix tests
fmartingr 361b469
use proper icon
fmartingr 3ee6203
removed setting
fmartingr 35492d1
removed setting
fmartingr 3753bc8
Merge remote-tracking branch 'origin/main' into feat/download-to-file…
fmartingr ef2be8b
spinner icon
fmartingr a64cc48
inef assignments
fmartingr c84ac85
hide upload button
fmartingr d5f21ab
Update server/api.go
fmartingr 7db3717
Update server/api.go
fmartingr e10f5d0
Update webapp/src/components/legal_hold_table/legal_hold_row/legal_ho…
fmartingr a8bb944
Update webapp/src/components/legal_hold_table/legal_hold_row/legal_ho…
fmartingr 7a0cf47
remove logs
fmartingr 304d2ef
tell the user if something went wrong
fmartingr a4ea883
make check-styles
fmartingr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package main | ||
|
||
import ( | ||
"path/filepath" | ||
"strconv" | ||
"time" | ||
|
||
"github.com/mattermost/mattermost-plugin-legal-hold/server/model" | ||
) | ||
|
||
// JobCleanupOldBundlesFromFilestore is a job that cleans old legal hold bundles from the filestore by | ||
// checking the timestamp in the filename and ensuring that bundles older than 24h are deleted. | ||
func (p *Plugin) jobCleanupOldBundlesFromFilestore() { | ||
p.API.LogDebug("Starting legal hold cleanup job") | ||
|
||
files, jobErr := p.FileBackend.ListDirectory(model.FilestoreBundlePath) | ||
if jobErr != nil { | ||
p.Client.Log.Error("failed to list directory", "err", jobErr) | ||
return | ||
} | ||
|
||
for _, file := range files { | ||
parts := model.FilestoreBundleRegex.FindStringSubmatch(filepath.Base(file)) | ||
if len(parts) != 3 { | ||
p.Client.Log.Error("Skipping file", "file", file, "reason", "does not match regex", "parts", parts) | ||
continue | ||
} | ||
|
||
// golang parse unix time | ||
parsedTimestamp, errStrConv := strconv.ParseInt(parts[2], 10, 64) | ||
if errStrConv != nil { | ||
p.Client.Log.Error("Skipping file", "file", file, "reason", "failed to parse timestamp", "err", errStrConv) | ||
continue | ||
} | ||
fileCreationTime := time.Unix(parsedTimestamp, 0) | ||
if time.Since(fileCreationTime) > time.Hour*24 { | ||
p.Client.Log.Debug("Deleting file", "file", file) | ||
if err := p.FileBackend.RemoveFile(file); err != nil { | ||
p.Client.Log.Error("Failed to delete file", "file", file, "err", err) | ||
} | ||
} | ||
|
||
p.Client.Log.Debug("Checking file", "file", file, "parts", parts) | ||
} | ||
|
||
p.API.LogDebug("Finished legal hold cleanup job") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package filebackend | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
|
||
"github.com/mattermost/mattermost-server/v6/shared/filestore" | ||
) | ||
|
||
// fileBackendWritter is a simple io.Writer that writes to a file using a filestore.FileBackend | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason this is spelled |
||
type fileBackendWritter struct { | ||
filePath string | ||
fileBackend filestore.FileBackend | ||
// created is used to know if the file has been created or not, to use either WriteFile or AppendFile | ||
created bool | ||
} | ||
|
||
func (s *fileBackendWritter) Write(p []byte) (n int, err error) { | ||
var written int64 | ||
if !s.created { | ||
s.created = true | ||
written, err = s.fileBackend.WriteFile(bytes.NewReader(p), s.filePath) | ||
} else { | ||
written, err = s.fileBackend.AppendFile(bytes.NewReader(p), s.filePath) | ||
} | ||
return int(written), err | ||
} | ||
|
||
func NewFileBackendWritter(fileBackend filestore.FileBackend, filePath string) io.Writer { | ||
return &fileBackendWritter{ | ||
filePath: filePath, | ||
fileBackend: fileBackend, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment makes it seem like we're not using
Deflate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I copied this verbatim from the original code, it's also confusing to me tbh.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a comment that outlasted a code change that it shouldn't have. I'd remove it.