show service account status and expiry in ui (#2992)

This commit is contained in:
Prakash Senthil Vel
2023-08-16 23:25:07 +05:30
committed by GitHub
parent a2ba20e12f
commit e7fb205c31
14 changed files with 317 additions and 84 deletions

View File

@@ -8161,7 +8161,24 @@ func init() {
"serviceAccounts": {
"type": "array",
"items": {
"type": "string"
"type": "object",
"properties": {
"accessKey": {
"type": "string"
},
"accountStatus": {
"type": "string"
},
"description": {
"type": "string"
},
"expiration": {
"type": "string"
},
"name": {
"type": "string"
}
}
}
},
"sessionResponse": {
@@ -14515,6 +14532,26 @@ func init() {
}
}
},
"ServiceAccountsItems0": {
"type": "object",
"properties": {
"accessKey": {
"type": "string"
},
"accountStatus": {
"type": "string"
},
"description": {
"type": "string"
},
"expiration": {
"type": "string"
},
"name": {
"type": "string"
}
}
},
"SubnetRegTokenResponse": {
"type": "object",
"properties": {
@@ -17357,7 +17394,7 @@ func init() {
"serviceAccounts": {
"type": "array",
"items": {
"type": "string"
"$ref": "#/definitions/ServiceAccountsItems0"
}
},
"sessionResponse": {

View File

@@ -22,15 +22,14 @@ import (
"encoding/json"
"errors"
"strings"
"github.com/minio/console/pkg/utils"
userApi "github.com/minio/console/restapi/operations/user"
"time"
"github.com/go-openapi/runtime/middleware"
"github.com/minio/console/models"
"github.com/minio/console/pkg/utils"
"github.com/minio/console/restapi/operations"
saApi "github.com/minio/console/restapi/operations/service_account"
userApi "github.com/minio/console/restapi/operations/user"
"github.com/minio/madmin-go/v3"
iampolicy "github.com/minio/pkg/iam/policy"
)
@@ -323,11 +322,27 @@ func getUserServiceAccounts(ctx context.Context, userClient MinioAdmin, user str
if err != nil {
return nil, err
}
serviceAccounts := models.ServiceAccounts{}
saList := models.ServiceAccounts{}
for _, acc := range listServAccs.Accounts {
serviceAccounts = append(serviceAccounts, acc.AccessKey)
aInfo, err := userClient.infoServiceAccount(ctx, acc.AccessKey)
if err != nil {
continue
}
expiry := ""
if aInfo.Expiration != nil {
expiry = aInfo.Expiration.Format(time.RFC3339)
}
saList = append(saList, &models.ServiceAccountsItems0{
AccountStatus: aInfo.AccountStatus,
Description: aInfo.Description,
Expiration: expiry,
Name: aInfo.Name,
AccessKey: acc.AccessKey,
})
}
return serviceAccounts, nil
return saList, nil
}
// getUserServiceAccountsResponse authenticates the user and calls

View File

@@ -98,13 +98,23 @@ func TestListServiceAccounts(t *testing.T) {
minioListServiceAccountsMock = func(ctx context.Context, user string) (madmin.ListServiceAccountsResp, error) {
return mockResponse, nil
}
serviceAccounts, err := getUserServiceAccounts(ctx, client, "")
mockInfoResp := madmin.InfoServiceAccountResp{
ParentUser: "",
AccountStatus: "",
ImpliedPolicy: false,
Policy: "",
Name: "",
Description: "",
Expiration: nil,
}
minioInfoServiceAccountMock = func(ctx context.Context, serviceAccount string) (madmin.InfoServiceAccountResp, error) {
return mockInfoResp, nil
}
_, err := getUserServiceAccounts(ctx, client, "")
if err != nil {
t.Errorf("Failed on %s:, error occurred: %s", function, err.Error())
}
for i, sa := range serviceAccounts {
assert.Equal(mockResponse.Accounts[i].AccessKey, sa)
}
// Test-2: getUserServiceAccounts returns an error, handle it properly
minioListServiceAccountsMock = func(ctx context.Context, user string) (madmin.ListServiceAccountsResp, error) {