Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add oidc provider name to systeminfo API #19575

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@
SelfRegistration: &d.SelfRegistration,
HarborVersion: &d.HarborVersion,
BannerMessage: &d.BannerMessage,
OIDCProviderName: &d.OIDCProviderName,

Check warning on line 90 in src/server/v2.0/handler/systeminfo.go

View check run for this annotation

Codecov / codecov/patch

src/server/v2.0/handler/systeminfo.go#L90

Added line #L90 was not covered by tests
}
if d.AuthProxySettings != nil {
res.AuthproxySettings = &models.AuthproxySetting{
Expand Down