Skip to content

Commit

Permalink
Add oidc provider name to systeminfo API (goharbor#19575)
Browse files Browse the repository at this point in the history
fixes goharbor#13198

Signed-off-by: stonezdj <daojunz@vmware.com>
Signed-off-by: Altynbaev Dinislam <altynbayevdr@sberautotech.ru>
  • Loading branch information
stonezdj authored and Altynbaev Dinislam committed Jan 29, 2024
1 parent 717a7c3 commit 158000b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
5 changes: 5 additions & 0 deletions api/v2.0/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions src/controller/systeminfo/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type Data struct {
BannerMessage string
AuthProxySettings *models.HTTPAuthProxy
Protected *protectedData
OIDCProviderName string
}

type protectedData struct {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
Expand Down
22 changes: 22 additions & 0 deletions src/controller/systeminfo/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
}
}
1 change: 1 addition & 0 deletions src/server/v2.0/handler/systeminfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 158000b

Please sign in to comment.