-
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
Support using a different s3 bucket through plugin setting #46
Merged
Merged
Changes from 16 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
08e5a8f
add api endpoint to run legal hold job on demand
mickmister 4bfa0fe
fix lint
mickmister 07793ac
PR feedback
mickmister 0fac0cb
call job in goroutine to avoid blocking ServeHTTP hook
mickmister bc19ac0
reorder defer blocks for cleaning up legal hold job
mickmister 54aa700
call context cancel function in defer
mickmister e6e186d
move processAllLegalHolds body back into run() method
mickmister f3e4a81
support using a different s3 bucket through plugin setting
mickmister a926e08
move code around
mickmister 1b464d7
update readme
mickmister c2708a3
Merge remote-tracking branch 'origin/main' into add-api-endpoint-to-r…
wiggin77 568f22b
Merge remote-tracking branch 'origin/main' into separate-s3-bucket
wiggin77 507a0b3
Merge branch 'add-api-endpoint-to-run-job' into separate-s3-bucket
mickmister eb63d08
initial s3 bucket form implementation
mickmister 71bd47d
test connection works
mickmister 930e5bf
show success/fail connection messages. check connection on plugin sta…
mickmister 997fb1b
update readme
mickmister 135c267
disable inputs instead of hiding
mickmister 0bb5856
Merge branch 'main' into separate-s3-bucket
wiggin77 c54440c
reorder settings in the admin console
mickmister 849c3ac
show aws secret key as asterisks
mickmister d51d58a
remove comment from code
mickmister a41faed
Merge branch 'separate-s3-bucket' of https://github.com/mattermost/ma…
mickmister 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
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 |
---|---|---|
@@ -1,3 +1,62 @@ | ||
package main | ||
|
||
// TODO: Implement me! | ||
import ( | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
pluginapi "github.com/mattermost/mattermost-plugin-api" | ||
"github.com/mattermost/mattermost-plugin-legal-hold/server/config" | ||
"github.com/mattermost/mattermost-server/v6/model" | ||
"github.com/mattermost/mattermost-server/v6/plugin/plugintest" | ||
"github.com/stretchr/testify/mock" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestTestAmazonS3Connection(t *testing.T) { | ||
p := &Plugin{} | ||
api := &plugintest.API{} | ||
p.SetDriver(&plugintest.Driver{}) | ||
p.SetAPI(api) | ||
p.Client = pluginapi.NewClient(p.API, p.Driver) | ||
|
||
api.On("HasPermissionTo", "test_user_id", model.PermissionManageSystem).Return(true) | ||
api.On("LogInfo", mock.Anything).Maybe() | ||
|
||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
if r.URL.Path == "/bucket/" { | ||
w.WriteHeader(http.StatusOK) | ||
} else { | ||
w.WriteHeader(http.StatusNotFound) | ||
} | ||
})) | ||
|
||
defer server.Close() | ||
|
||
p.setConfiguration(&config.Configuration{ | ||
TimeOfDay: "10:00pm -0500h", | ||
AmazonS3BucketSettings: config.AmazonS3BucketSettings{ | ||
Enable: true, | ||
Settings: model.FileSettings{ | ||
DriverName: model.NewString("amazons3"), | ||
AmazonS3Bucket: model.NewString("bucket"), | ||
AmazonS3AccessKeyId: model.NewString("access_key_id"), | ||
AmazonS3SecretAccessKey: model.NewString("secret_access_key"), | ||
AmazonS3RequestTimeoutMilliseconds: model.NewInt64(5000), | ||
AmazonS3Endpoint: model.NewString(server.Listener.Addr().String()), | ||
AmazonS3Region: model.NewString("us-east-1"), | ||
AmazonS3SSL: model.NewBool(false), | ||
AmazonS3SSE: model.NewBool(false), | ||
}, | ||
}, | ||
}) | ||
|
||
req, err := http.NewRequest(http.MethodPost, "/api/v1/test_amazon_s3_connection", nil) | ||
require.NoError(t, err) | ||
|
||
req.Header.Add("Mattermost-User-Id", "test_user_id") | ||
|
||
recorder := httptest.NewRecorder() | ||
p.ServeHTTP(nil, recorder, req) | ||
require.Equal(t, http.StatusOK, recorder.Code) | ||
} |
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
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
32 changes: 32 additions & 0 deletions
32
webapp/src/components/admin_console_settings/base_setting.tsx
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,32 @@ | ||
import React from 'react'; | ||
|
||
type Props = React.PropsWithChildren<{ | ||
id: string; | ||
name: string; | ||
helpText: string; | ||
}>; | ||
|
||
const BaseSetting = (props: Props) => { | ||
return ( | ||
<div | ||
id={`legal-hold-admin-console-setting-${props.id}`} | ||
className='form-group' | ||
> | ||
<label | ||
className='control-label col-sm-4' | ||
> | ||
{props.name && `${props.name}:`} | ||
</label> | ||
<div className='col-sm-8'> | ||
{props.children} | ||
<div | ||
className='help-text' | ||
> | ||
<span>{props.helpText}</span> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default BaseSetting; |
41 changes: 41 additions & 0 deletions
41
webapp/src/components/admin_console_settings/boolean_setting.tsx
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,41 @@ | ||
import React from 'react'; | ||
|
||
import BaseSetting from './base_setting'; | ||
|
||
type Props = { | ||
id: string; | ||
name: string; | ||
helpText: string; | ||
onChange: (value: boolean) => void; | ||
value: boolean; | ||
disabled?: boolean; | ||
}; | ||
|
||
const BooleanSetting = (props: Props) => { | ||
return ( | ||
<BaseSetting | ||
{...props} | ||
> | ||
<label className='radio-inline'> | ||
<input | ||
type='radio' | ||
onChange={() => props.onChange(true)} | ||
checked={props.value} | ||
disabled={props.disabled} | ||
/> | ||
<span>{'true'}</span> | ||
</label> | ||
<label className='radio-inline'> | ||
<input | ||
type='radio' | ||
onChange={() => props.onChange(false)} | ||
checked={!props.value} | ||
disabled={props.disabled} | ||
/> | ||
<span>{'false'}</span> | ||
</label> | ||
</BaseSetting> | ||
); | ||
}; | ||
|
||
export default BooleanSetting; |
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.
I put this comment here since right now the UI will be given the stored access secret on page load. Though there is no chance to encrypt/decrypt the config value in the case of saving config values in the system console. Not sure how to proceed with hiding the secret even though it's in plaintext in the server config, and is exposed to the client directly.
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.
How is it done in the main mmserver S3 config?
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.
@wiggin77 The server's config is sanitized before being returned the client, which in this case includes censoring the main product's AWS secret key. But this sanitization step is not available for plugin settings, so they are always delivered as plaintext.
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.
Created a ticket to address this #54