mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-22 10:15:35 +01:00
Add oidc provider name to systeminfo API (#19575)
fixes #13198 Signed-off-by: stonezdj <daojunz@vmware.com>
This commit is contained in:
parent
04397fb6a2
commit
3f6c0298fe
@ -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:
|
||||
|
@ -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()
|
||||
|
@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -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{
|
||||
|
Loading…
Reference in New Issue
Block a user