Skip to content

Commit 2988de4

Browse files
adfostbexsoft
andauthored
adding edit service account api/ui (#1545)
Co-authored-by: Alex <33497058+bexsoft@users.noreply.github.com>
1 parent c6f2ddf commit 2988de4

14 files changed

+790
-19
lines changed

integration/service_account_test.go

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,6 @@ func TestAddServiceAccount(t *testing.T) {
5050
requestDataAddServiceAccount := map[string]interface{}{
5151
"accessKey": "testuser1",
5252
"secretKey": "password",
53-
"policy": "{" +
54-
"\n \"Version\": \"2012-10-17\"," +
55-
"\n \"Statement\": [" +
56-
"\n {" +
57-
"\n \"Effect\": \"Allow\"," +
58-
"\n \"Action\": [" +
59-
"\n \"s3:GetBucketLocation\"," +
60-
"\n \"s3:GetObject\"" +
61-
"\n ]," +
62-
"\n \"Resource\": [" +
63-
"\n \"arn:aws:s3:::*\"" +
64-
"\n ]" +
65-
"\n }" +
66-
"\n ]" +
67-
"\n}",
6853
}
6954

7055
fmt.Println("..............................TestServiceAccountPolicy(): Prepare the POST")
@@ -95,7 +80,51 @@ func TestAddServiceAccount(t *testing.T) {
9580
assert.Equal(201, response.StatusCode, "Status Code is incorrect")
9681
}
9782

98-
fmt.Println("...................................TestServiceAccountPolicy(): Remove user")
83+
requestDataPolicy := map[string]interface{}{"policy": "{" +
84+
"\n \"Version\": \"2012-10-17\"," +
85+
"\n \"Statement\": [" +
86+
"\n {" +
87+
"\n \"Effect\": \"Allow\"," +
88+
"\n \"Action\": [" +
89+
"\n \"s3:GetBucketLocation\"," +
90+
"\n \"s3:GetObject\"" +
91+
"\n ]," +
92+
"\n \"Resource\": [" +
93+
"\n \"arn:aws:s3:::*\"" +
94+
"\n ]" +
95+
"\n }" +
96+
"\n ]" +
97+
"\n}",
98+
}
99+
fmt.Println("..............................TestServiceAccountPolicy(): Prepare the PUT")
100+
requestDataJSON, _ = json.Marshal(requestDataPolicy)
101+
requestDataBody = bytes.NewReader(requestDataJSON)
102+
request, err = http.NewRequest(
103+
"PUT", "http://localhost:9090/api/v1/service-accounts/testuser1/policy", requestDataBody)
104+
if err != nil {
105+
log.Println(err)
106+
return
107+
}
108+
request.Header.Add("Cookie", fmt.Sprintf("token=%s", token))
109+
request.Header.Add("Content-Type", "application/json")
110+
111+
fmt.Println(".................................TestServiceAccountPolicy(): Make the PUT")
112+
response, err = client.Do(request)
113+
if err != nil {
114+
log.Println(err)
115+
return
116+
}
117+
fmt.Println("..................................TestServiceAccountPolicy(): Verification")
118+
fmt.Println(".................................TestServiceAccountPolicy(): PUT response")
119+
fmt.Println(response)
120+
fmt.Println("....................................TestServiceAccountPolicy(): PUT error")
121+
fmt.Println(err)
122+
if response != nil {
123+
fmt.Println("POST StatusCode:", response.StatusCode)
124+
assert.Equal(200, response.StatusCode, "Status Code is incorrect")
125+
}
126+
127+
fmt.Println("...................................TestServiceAccountPolicy(): Check policy")
99128

100129
// Test policy
101130
fmt.Println(".......................TestAddUserServiceAccount(): Create Data to add user")

models/add_service_account_policy_request.go

Lines changed: 88 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

portal-ui/src/screens/Console/Account/Account.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ const Account = ({ classes, displayErrorMessage }: IServiceAccountsProps) => {
179179

180180
const closePolicyModal = () => {
181181
setPolicyOpen(false);
182+
setLoading(true);
182183
};
183184

184185
const confirmDeleteServiceAccount = (selectedServiceAccount: string) => {

portal-ui/src/screens/Console/Account/ServiceAccountPolicy.tsx

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,18 @@ const ServiceAccountPolicy = ({
8585
}
8686
}, [loading, setLoading, setModalErrorSnackMessage, selectedAccessKey]);
8787

88+
const setPolicy = (event: React.FormEvent, newPolicy: string) => {
89+
event.preventDefault();
90+
api
91+
.invoke("PUT", `/api/v1/service-accounts/${selectedAccessKey}/policy`, {policy: newPolicy})
92+
.then((res) => {
93+
closeModalAndRefresh();
94+
})
95+
.catch((err: ErrorResponseHandler) => {
96+
setModalErrorSnackMessage(err);
97+
});
98+
};
99+
88100
return (
89101
<ModalWrapper
90102
title="Service Account Policy"
@@ -94,6 +106,13 @@ const ServiceAccountPolicy = ({
94106
}}
95107
titleIcon={<ChangeAccessPolicyIcon />}
96108
>
109+
<form
110+
noValidate
111+
autoComplete="off"
112+
onSubmit={(e: React.FormEvent<HTMLFormElement>) => {
113+
setPolicy(e, policyDefinition);
114+
}}
115+
>
97116
<Grid container>
98117
<Grid item xs={12} className={classes.codeMirrorContainer}>
99118
<CodeMirrorWrapper
@@ -103,7 +122,6 @@ const ServiceAccountPolicy = ({
103122
setPolicyDefinition(value);
104123
}}
105124
editorHeight={"350px"}
106-
readOnly={true}
107125
/>
108126
</Grid>
109127
<Grid item xs={12} className={classes.modalButtonBar}>
@@ -118,8 +136,19 @@ const ServiceAccountPolicy = ({
118136
>
119137
Cancel
120138
</Button>
139+
<Button
140+
type="submit"
141+
variant="contained"
142+
color="primary"
143+
disabled={
144+
loading
145+
}
146+
>
147+
Set
148+
</Button>
121149
</Grid>
122150
</Grid>
151+
</form>
123152
</ModalWrapper>
124153
);
125154
};

restapi/client-admin.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ type MinioAdmin interface {
9999
listServiceAccounts(ctx context.Context, user string) (madmin.ListServiceAccountsResp, error)
100100
deleteServiceAccount(ctx context.Context, serviceAccount string) error
101101
infoServiceAccount(ctx context.Context, serviceAccount string) (madmin.InfoServiceAccountResp, error)
102+
updateServiceAccount(ctx context.Context, serviceAccount string, opts madmin.UpdateServiceAccountReq) error
102103
// Remote Buckets
103104
listRemoteBuckets(ctx context.Context, bucket, arnType string) (targets []madmin.BucketTarget, err error)
104105
getRemoteBucket(ctx context.Context, bucket, arnType string) (targets *madmin.BucketTarget, err error)
@@ -312,6 +313,11 @@ func (ac AdminClient) infoServiceAccount(ctx context.Context, serviceAccount str
312313
return ac.Client.InfoServiceAccount(ctx, serviceAccount)
313314
}
314315

316+
// implements madmin.UpdateServiceAccount()
317+
func (ac AdminClient) updateServiceAccount(ctx context.Context, serviceAccount string, opts madmin.UpdateServiceAccountReq) error {
318+
return ac.Client.UpdateServiceAccount(ctx, serviceAccount, opts)
319+
}
320+
315321
// AccountInfo implements madmin.AccountInfo()
316322
func (ac AdminClient) AccountInfo(ctx context.Context) (madmin.AccountInfo, error) {
317323
return ac.Client.AccountInfo(ctx, madmin.AccountOpts{})

restapi/embedded_spec.go

Lines changed: 90 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)