-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support using a different s3 bucket through plugin setting (#46)
* add api endpoint to run legal hold job on demand * fix lint * PR feedback * call job in goroutine to avoid blocking ServeHTTP hook * reorder defer blocks for cleaning up legal hold job * call context cancel function in defer * move processAllLegalHolds body back into run() method * support using a different s3 bucket through plugin setting * move code around * update readme * initial s3 bucket form implementation * test connection works * show success/fail connection messages. check connection on plugin startup * update readme * disable inputs instead of hiding * reorder settings in the admin console * show aws secret key as asterisks * remove comment from code --------- Co-authored-by: wiggin77 <[email protected]>
- Loading branch information
1 parent
93a41b5
commit 5fcd868
Showing
16 changed files
with
575 additions
and
10 deletions.
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
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; |
51 changes: 51 additions & 0 deletions
51
webapp/src/components/admin_console_settings/secret_text_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,51 @@ | ||
import React, {useEffect, useRef, useState} from 'react'; | ||
|
||
import BaseSetting from './base_setting'; | ||
|
||
type Props = { | ||
id: string; | ||
name: string; | ||
helpText: string; | ||
onChange: (value: string) => void; | ||
value: string; | ||
disabled?: boolean; | ||
}; | ||
|
||
const SecretTextSetting = (props: Props) => { | ||
const [value, setValue] = useState(''); | ||
const mounted = useRef(false); | ||
|
||
useEffect(() => { | ||
if (mounted.current) { | ||
setValue(props.value); | ||
return; | ||
} | ||
|
||
if (props.value) { | ||
setValue('*'.repeat(32)); | ||
} | ||
|
||
mounted.current = true; | ||
}, [props.value]); | ||
|
||
const handleChange = (newValue: string) => { | ||
setValue(newValue); | ||
}; | ||
|
||
return ( | ||
<BaseSetting | ||
{...props} | ||
> | ||
<input | ||
id={props.id} | ||
className='form-control' | ||
type='text' | ||
value={value} | ||
onChange={(e) => handleChange(e.target.value)} | ||
disabled={props.disabled} | ||
/> | ||
</BaseSetting> | ||
); | ||
}; | ||
|
||
export default SecretTextSetting; |
38 changes: 38 additions & 0 deletions
38
webapp/src/components/admin_console_settings/status_message.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,38 @@ | ||
import React from 'react'; | ||
|
||
type Props = { | ||
state: 'warn' | 'success'; | ||
message: string; | ||
} | ||
|
||
const StatusMessage = (props: Props) => { | ||
const {state, message} = props; | ||
|
||
if (state === 'warn') { | ||
return ( | ||
<div> | ||
<div className='alert alert-warning'> | ||
<i | ||
className='fa fa-warning' | ||
title='Warning Icon' | ||
/> | ||
<span>{message}</span> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
return ( | ||
<div> | ||
<div className='alert alert-success'> | ||
<i | ||
className='fa fa-check' | ||
title='Success Icon' | ||
/> | ||
<span>{message}</span> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default StatusMessage; |
Oops, something went wrong.