Add oidc provider name to systeminfo API (#19575)

fixes #13198

Signed-off-by: stonezdj <daojunz@vmware.com>
This commit is contained in:
stonezdj(Daojun Zhang) 2023-11-15 11:00:39 +08:00 committed by GitHub
parent 04397fb6a2
commit 3f6c0298fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 0 deletions

View File

@ -7867,6 +7867,11 @@ definitions:
x-nullable: true
x-omitempty: true
$ref: '#/definitions/AuthproxySetting'
oidc_provider_name:
type: string
x-nullable: true
x-omitempty: true
description: The OIDC provider name, empty if current auth is not OIDC_auth or OIDC provider is not configured.
AuthproxySetting:
type: object
properties:

View File

@ -50,6 +50,7 @@ type Data struct {
BannerMessage string
AuthProxySettings *models.HTTPAuthProxy
Protected *protectedData
OIDCProviderName string
}
type protectedData struct {
@ -103,6 +104,7 @@ func (c *controller) GetInfo(ctx context.Context, opt Options) (*Data, error) {
SelfRegistration: utils.SafeCastBool(cfg[common.SelfRegistration]),
HarborVersion: fmt.Sprintf("%s-%s", version.ReleaseVersion, version.GitCommit),
BannerMessage: utils.SafeCastString(mgr.Get(ctx, common.BannerMessage).GetString()),
OIDCProviderName: OIDCProviderName(cfg),
}
if res.AuthMode == common.HTTPAuth {
if s, err := config.HTTPAuthProxySetting(ctx); err == nil {
@ -137,6 +139,14 @@ func (c *controller) GetInfo(ctx context.Context, opt Options) (*Data, error) {
return res, nil
}
func OIDCProviderName(cfg map[string]interface{}) string {
authMode := utils.SafeCastString(cfg[common.AUTHMode])
if authMode != common.OIDCAuth {
return ""
}
return utils.SafeCastString(cfg[common.OIDCName])
}
func (c *controller) GetCapacity(ctx context.Context) (*imagestorage.Capacity, error) {
systeminfo.Init()
return imagestorage.GlobalDriver.Cap()

View File

@ -105,3 +105,25 @@ func (s *sysInfoCtlTestSuite) TestGetInfo() {
func TestControllerSuite(t *testing.T) {
suite.Run(t, &sysInfoCtlTestSuite{})
}
func TestOIDCProviderName(t *testing.T) {
type args struct {
cfg map[string]interface{}
}
tests := []struct {
name string
args args
want string
}{
{"normal testing", args{map[string]interface{}{common.AUTHMode: common.OIDCAuth, common.OIDCName: "test"}}, "test"},
{"not oidc", args{map[string]interface{}{common.AUTHMode: common.DBAuth, common.OIDCName: "test"}}, ""},
{"empty provider", args{map[string]interface{}{common.AUTHMode: common.OIDCAuth, common.OIDCName: ""}}, ""},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := OIDCProviderName(tt.args.cfg); got != tt.want {
t.Errorf("OIDCProviderName() = %v, want %v", got, tt.want)
}
})
}
}

View File

@ -87,6 +87,7 @@ func (s *sysInfoAPI) convertInfo(d *si.Data) *models.GeneralInfo {
SelfRegistration: &d.SelfRegistration,
HarborVersion: &d.HarborVersion,
BannerMessage: &d.BannerMessage,
OIDCProviderName: &d.OIDCProviderName,
}
if d.AuthProxySettings != nil {
res.AuthproxySettings = &models.AuthproxySetting{