From d315fee7796af4b2aa2dd8432db52937780527f2 Mon Sep 17 00:00:00 2001 From: Daniil Pankratov Date: Fri, 26 Feb 2021 10:54:25 +0300 Subject: [PATCH 1/4] Create admin auths API --- modules/convert/auth_source.go | 42 +++++++ modules/structs/auth_source.go | 38 ++++++ routers/api/v1/admin/auths.go | 115 ++++++++++++++++++ routers/api/v1/api.go | 4 + routers/api/v1/swagger/auth_source.go | 28 +++++ templates/swagger/v1_json.tmpl | 161 ++++++++++++++++++++++++++ 6 files changed, 388 insertions(+) create mode 100644 modules/convert/auth_source.go create mode 100644 modules/structs/auth_source.go create mode 100644 routers/api/v1/admin/auths.go create mode 100644 routers/api/v1/swagger/auth_source.go diff --git a/modules/convert/auth_source.go b/modules/convert/auth_source.go new file mode 100644 index 0000000000000..f4b091aea7ec4 --- /dev/null +++ b/modules/convert/auth_source.go @@ -0,0 +1,42 @@ +// Copyright 2021 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package convert + +import ( + "code.gitea.io/gitea/models" + api "code.gitea.io/gitea/modules/structs" +) + +// ToAuthSources convert a list of models.LoginSource to a list of api.AuthSource +func ToAuthSources(sources []*models.LoginSource) ([]*api.AuthSource, error) { + result := make([]*api.AuthSource, len(sources)) + for i, source := range sources { + authSource, err := ToAuthSource(source) + if err != nil { + return nil, err + } + result[i] = authSource + } + return result, nil +} + +// ToAuthSource convert a models.LoginSource to a api.AuthSource +func ToAuthSource(source *models.LoginSource) (*api.AuthSource, error) { + cfg, err := source.Cfg.ToDB() + if err != nil { + return nil, err + } + authSource := &api.AuthSource{ + ID: source.ID, + Name: source.Name, + Type: models.LoginNames[source.Type], + IsActive: source.IsActived, + IsSyncEnabled: source.IsSyncEnabled, + CreatedTime: source.CreatedUnix.AsTime(), + UpdatedTime: source.UpdatedUnix.AsTime(), + Cfg: cfg, + } + return authSource, nil +} diff --git a/modules/structs/auth_source.go b/modules/structs/auth_source.go new file mode 100644 index 0000000000000..741bee7062770 --- /dev/null +++ b/modules/structs/auth_source.go @@ -0,0 +1,38 @@ +// Copyright 2021 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package structs + +import ( + "encoding/json" + "time" +) + +// AuthSource represents an authentication source +type AuthSource struct { + ID int64 `json:"id"` + Name string `json:"name"` + // enum: LDAP (via BindDN),LDAP (simple auth),SMTP,PAM,OAuth2,SPNEGO with SSPI + Type string `json:"type"` + IsActive bool `json:"isActive"` + IsSyncEnabled bool `json:"isSyncEnabled"` + // swagger:strfmt date-time + CreatedTime time.Time `json:"createdTime"` + // swagger:strfmt date-time + UpdatedTime time.Time `json:"updatedTime"` + Cfg json.RawMessage `json:"config"` +} + +// CreateAuthSource represents an authentication source creation request +type CreateAuthSource struct { + // required: true + Name string `json:"name" binding:"Required"` + // required: true + // enum: LDAP (via BindDN),LDAP (simple auth),SMTP,PAM,OAuth2,SPNEGO with SSPI + Type string `json:"type" binding:"Required"` + IsActive bool `json:"isActive"` + IsSyncEnabled bool `json:"isSyncEnabled"` + // required: true + Cfg json.RawMessage `json:"config" binding:"Required"` +} diff --git a/routers/api/v1/admin/auths.go b/routers/api/v1/admin/auths.go new file mode 100644 index 0000000000000..743ee62299add --- /dev/null +++ b/routers/api/v1/admin/auths.go @@ -0,0 +1,115 @@ +// Copyright 2021 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package admin + +import ( + "net/http" + + "code.gitea.io/gitea/models" + "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/convert" + api "code.gitea.io/gitea/modules/structs" + "code.gitea.io/gitea/modules/timeutil" + "code.gitea.io/gitea/modules/web" + + xorm "xorm.io/xorm/convert" +) + +// ListAuthSources returns list of existing authentication sources +func ListAuthSources(ctx *context.APIContext) { + // swagger:operation GET /admin/auths admin adminAuthsSourcesList + // --- + // summary: List existing authentication sources + // produces: + // - application/json + // responses: + // "200": + // "$ref": "#/responses/AuthSourcesList" + // "403": + // "$ref": "#/responses/forbidden" + sources, err := models.LoginSources() + if err != nil { + ctx.InternalServerError(err) + return + } + result, err := convert.ToAuthSources(sources) + if err != nil { + ctx.InternalServerError(err) + return + } + ctx.JSON(http.StatusOK, result) +} + +// CreateAuthSource creates new authentication source +func CreateAuthSource(ctx *context.APIContext) { + // swagger:operation POST /admin/auths admin adminCreateAuthSource + // --- + // summary: Create new authentication source + // consumes: + // - application/json + // produces: + // - application/json + // parameters: + // - name: body + // in: body + // schema: + // "$ref": "#/definitions/CreateAuthSource" + // responses: + // "201": + // "$ref": "#/responses/AuthSource" + // "403": + // "$ref": "#/responses/forbidden" + authSource := web.GetForm(ctx).(*api.CreateAuthSource) + var config xorm.Conversion + var loginType models.LoginType + for key, val := range models.LoginNames { + if authSource.Type == val { + loginType = key + switch key { + case models.LoginLDAP: + config = &models.LDAPConfig{} + case models.LoginSMTP: + config = &models.SMTPConfig{} + case models.LoginPAM: + config = &models.PAMConfig{} + case models.LoginDLDAP: + config = &models.LDAPConfig{} + case models.LoginOAuth2: + config = &models.OAuth2Config{} + case models.LoginSSPI: + config = &models.SSPIConfig{} + } + break + } + } + if loginType == 0 { + ctx.Error(http.StatusBadRequest, "", "Authentication source type is invalid") + return + } + if err := config.FromDB(authSource.Cfg); err != nil { + ctx.InternalServerError(err) + return + } + + source := &models.LoginSource{ + Type: loginType, + Cfg: config, + Name: authSource.Name, + IsActived: authSource.IsActive, + IsSyncEnabled: authSource.IsSyncEnabled, + CreatedUnix: timeutil.TimeStampNow(), + UpdatedUnix: timeutil.TimeStampNow(), + } + if err := models.CreateLoginSource(source); err != nil { + ctx.InternalServerError(err) + return + } + result, err := convert.ToAuthSource(source) + if err != nil { + ctx.InternalServerError(err) + return + } + ctx.JSON(http.StatusCreated, result) +} diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index cb1803f7c652f..fc61b7084f09b 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -1499,6 +1499,10 @@ func Routes() *web.Route { }, tokenRequiresScopes(auth_model.AccessTokenScopeCategoryOrganization), orgAssignment(false, true), reqToken(), reqTeamMembership()) m.Group("/admin", func() { + m.Group("/auths", func() { + m.Get("", admin.ListAuthSources) + m.Post("", bind(api.CreateAuthSource{}), admin.CreateAuthSource) + }) m.Group("/cron", func() { m.Get("", admin.ListCronTasks) m.Post("/{task}", admin.PostCronTask) diff --git a/routers/api/v1/swagger/auth_source.go b/routers/api/v1/swagger/auth_source.go new file mode 100644 index 0000000000000..fbca605945186 --- /dev/null +++ b/routers/api/v1/swagger/auth_source.go @@ -0,0 +1,28 @@ +// Copyright 2021 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package swagger + +import api "code.gitea.io/gitea/modules/structs" + +// AuthSourcesList +// swagger:response AuthSourcesList +type swaggerAuthSourcesList struct { + // in:body + Body []api.AuthSource `json:"body"` +} + +// AuthSource +// swagger:response AuthSource +type swaggerAuthSource struct { + // in:body + Body api.AuthSource `json:"body"` +} + +// CreateAuthSource +// swagger:response CreateAuthSource +type swaggerCreateAuthSource struct { + // in:body + CreateAuthSource api.CreateAuthSource +} diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index dc04a97b833c7..3fc1b1bdc5331 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -75,6 +75,56 @@ } } }, + "/admin/auths": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "admin" + ], + "summary": "List existing authentication sources", + "operationId": "adminAuthsSourcesList", + "responses": { + "200": { + "$ref": "#/responses/AuthSourcesList" + }, + "403": { + "$ref": "#/responses/forbidden" + } + } + }, + "post": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "admin" + ], + "summary": "Create new authentication source", + "operationId": "adminCreateAuthSource", + "parameters": [ + { + "name": "body", + "in": "body", + "schema": { + "$ref": "#/definitions/CreateAuthSource" + } + } + ], + "responses": { + "201": { + "$ref": "#/responses/AuthSource" + }, + "403": { + "$ref": "#/responses/forbidden" + } + } + } + }, "/admin/cron": { "get": { "produces": [ @@ -16910,6 +16960,56 @@ }, "x-go-package": "code.gitea.io/gitea/modules/structs" }, + "AuthSource": { + "description": "AuthSource represents an authentication source", + "type": "object", + "properties": { + "config": { + "type": "object", + "x-go-name": "Cfg" + }, + "createdTime": { + "type": "string", + "format": "date-time", + "x-go-name": "CreatedTime" + }, + "id": { + "type": "integer", + "format": "int64", + "x-go-name": "ID" + }, + "isActive": { + "type": "boolean", + "x-go-name": "IsActive" + }, + "isSyncEnabled": { + "type": "boolean", + "x-go-name": "IsSyncEnabled" + }, + "name": { + "type": "string", + "x-go-name": "Name" + }, + "type": { + "type": "string", + "enum": [ + "LDAP (via BindDN)", + "LDAP (simple auth)", + "SMTP", + "PAM", + "OAuth2", + "SPNEGO with SSPI" + ], + "x-go-name": "Type" + }, + "updatedTime": { + "type": "string", + "format": "date-time", + "x-go-name": "UpdatedTime" + } + }, + "x-go-package": "code.gitea.io/gitea/modules/structs" + }, "Branch": { "description": "Branch represents a repository branch", "type": "object", @@ -17606,6 +17706,46 @@ }, "x-go-package": "code.gitea.io/gitea/modules/structs" }, + "CreateAuthSource": { + "description": "CreateAuthSource represents an authentication source creation request", + "type": "object", + "required": [ + "name", + "type", + "config" + ], + "properties": { + "config": { + "type": "object", + "x-go-name": "Cfg" + }, + "isActive": { + "type": "boolean", + "x-go-name": "IsActive" + }, + "isSyncEnabled": { + "type": "boolean", + "x-go-name": "IsSyncEnabled" + }, + "name": { + "type": "string", + "x-go-name": "Name" + }, + "type": { + "type": "string", + "enum": [ + "LDAP (via BindDN)", + "LDAP (simple auth)", + "SMTP", + "PAM", + "OAuth2", + "SPNEGO with SSPI" + ], + "x-go-name": "Type" + } + }, + "x-go-package": "code.gitea.io/gitea/modules/structs" + }, "CreateBranchProtectionOption": { "description": "CreateBranchProtectionOption options for creating a branch protection", "type": "object", @@ -23229,6 +23369,27 @@ } } }, + "AuthSource": { + "description": "AuthSource", + "schema": { + "$ref": "#/definitions/AuthSource" + } + }, + "AuthSourcesList": { + "description": "AuthSourcesList", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/AuthSource" + } + } + }, + "CreateAuthSource": { + "description": "CreateAuthSource", + "schema": { + "$ref": "#/definitions/CreateAuthSource" + } + }, "Branch": { "description": "Branch", "schema": { From e6843fdff6b1a4dff8b095d1fa6725da4f70a4aa Mon Sep 17 00:00:00 2001 From: Jeffrey Clark Date: Mon, 6 Feb 2023 09:22:50 +0000 Subject: [PATCH 2/4] update admin auth api --- modules/convert/auth_source.go | 12 +++++----- routers/api/v1/admin/auths.go | 43 +++++++++++++++++++--------------- 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/modules/convert/auth_source.go b/modules/convert/auth_source.go index f4b091aea7ec4..e2219afafc911 100644 --- a/modules/convert/auth_source.go +++ b/modules/convert/auth_source.go @@ -5,12 +5,12 @@ package convert import ( - "code.gitea.io/gitea/models" + "code.gitea.io/gitea/models/auth" api "code.gitea.io/gitea/modules/structs" ) // ToAuthSources convert a list of models.LoginSource to a list of api.AuthSource -func ToAuthSources(sources []*models.LoginSource) ([]*api.AuthSource, error) { +func ToAuthSources(sources []*auth.Source) ([]*api.AuthSource, error) { result := make([]*api.AuthSource, len(sources)) for i, source := range sources { authSource, err := ToAuthSource(source) @@ -22,8 +22,8 @@ func ToAuthSources(sources []*models.LoginSource) ([]*api.AuthSource, error) { return result, nil } -// ToAuthSource convert a models.LoginSource to a api.AuthSource -func ToAuthSource(source *models.LoginSource) (*api.AuthSource, error) { +// ToAuthSource convert a auth.LoginSource to a api.AuthSource +func ToAuthSource(source *auth.Source) (*api.AuthSource, error) { cfg, err := source.Cfg.ToDB() if err != nil { return nil, err @@ -31,8 +31,8 @@ func ToAuthSource(source *models.LoginSource) (*api.AuthSource, error) { authSource := &api.AuthSource{ ID: source.ID, Name: source.Name, - Type: models.LoginNames[source.Type], - IsActive: source.IsActived, + Type: auth.Names[source.Type], + IsActive: source.IsActive, IsSyncEnabled: source.IsSyncEnabled, CreatedTime: source.CreatedUnix.AsTime(), UpdatedTime: source.UpdatedUnix.AsTime(), diff --git a/routers/api/v1/admin/auths.go b/routers/api/v1/admin/auths.go index 743ee62299add..28a2b2c9cbc67 100644 --- a/routers/api/v1/admin/auths.go +++ b/routers/api/v1/admin/auths.go @@ -7,12 +7,17 @@ package admin import ( "net/http" - "code.gitea.io/gitea/models" + "code.gitea.io/gitea/models/auth" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/convert" api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/web" + "code.gitea.io/gitea/services/auth/source/ldap" + "code.gitea.io/gitea/services/auth/source/oauth2" + "code.gitea.io/gitea/services/auth/source/pam" + "code.gitea.io/gitea/services/auth/source/smtp" + "code.gitea.io/gitea/services/auth/source/sspi" xorm "xorm.io/xorm/convert" ) @@ -29,7 +34,7 @@ func ListAuthSources(ctx *context.APIContext) { // "$ref": "#/responses/AuthSourcesList" // "403": // "$ref": "#/responses/forbidden" - sources, err := models.LoginSources() + sources, err := auth.Sources() if err != nil { ctx.InternalServerError(err) return @@ -63,23 +68,23 @@ func CreateAuthSource(ctx *context.APIContext) { // "$ref": "#/responses/forbidden" authSource := web.GetForm(ctx).(*api.CreateAuthSource) var config xorm.Conversion - var loginType models.LoginType - for key, val := range models.LoginNames { + var loginType auth.Type + for key, val := range auth.Names { if authSource.Type == val { loginType = key switch key { - case models.LoginLDAP: - config = &models.LDAPConfig{} - case models.LoginSMTP: - config = &models.SMTPConfig{} - case models.LoginPAM: - config = &models.PAMConfig{} - case models.LoginDLDAP: - config = &models.LDAPConfig{} - case models.LoginOAuth2: - config = &models.OAuth2Config{} - case models.LoginSSPI: - config = &models.SSPIConfig{} + case auth.LDAP: + config = &ldap.Source{} + case auth.SMTP: + config = &smtp.Source{} + case auth.PAM: + config = &pam.Source{} + case auth.DLDAP: + config = &ldap.Source{} + case auth.OAuth2: + config = &oauth2.Source{} + case auth.SSPI: + config = &sspi.Source{} } break } @@ -93,16 +98,16 @@ func CreateAuthSource(ctx *context.APIContext) { return } - source := &models.LoginSource{ + source := &auth.Source{ Type: loginType, Cfg: config, Name: authSource.Name, - IsActived: authSource.IsActive, + IsActive: authSource.IsActive, IsSyncEnabled: authSource.IsSyncEnabled, CreatedUnix: timeutil.TimeStampNow(), UpdatedUnix: timeutil.TimeStampNow(), } - if err := models.CreateLoginSource(source); err != nil { + if err := auth.CreateSource(source); err != nil { ctx.InternalServerError(err) return } From 61155ec397e02779ff52b3edaabb38abef63c61d Mon Sep 17 00:00:00 2001 From: Jeffrey Clark Date: Mon, 6 Feb 2023 10:05:42 +0000 Subject: [PATCH 3/4] add id get and delete to admin auth api --- routers/api/v1/admin/auths.go | 67 ++++++++++++++++++++++++++++++++++ routers/api/v1/api.go | 6 ++- templates/swagger/v1_json.tmpl | 64 +++++++++++++++++++++++++++++--- 3 files changed, 129 insertions(+), 8 deletions(-) diff --git a/routers/api/v1/admin/auths.go b/routers/api/v1/admin/auths.go index 28a2b2c9cbc67..014f23030a26d 100644 --- a/routers/api/v1/admin/auths.go +++ b/routers/api/v1/admin/auths.go @@ -13,6 +13,7 @@ import ( api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/web" + auth_service "code.gitea.io/gitea/services/auth" "code.gitea.io/gitea/services/auth/source/ldap" "code.gitea.io/gitea/services/auth/source/oauth2" "code.gitea.io/gitea/services/auth/source/pam" @@ -47,6 +48,37 @@ func ListAuthSources(ctx *context.APIContext) { ctx.JSON(http.StatusOK, result) } +// GetAuthSource get an authentication source by id +func GetAuthSource(ctx *context.APIContext) { + // swagger:operation GET /admin/auths/{id} admin adminGetAuthSource + // --- + // summary: Get an authentication source + // produces: + // - application/json + // parameters: + // - name: id + // in: path + // description: id of the authentication source to get + // type: integer + // format: int64 + // required: true + // responses: + // "200": + // "$ref": "#/responses/AuthSource" + + source, err := auth.GetSourceByID(ctx.ParamsInt64(":id")) + if err != nil { + ctx.ServerError("auth.GetSourceByID", err) + return + } + result, err := convert.ToAuthSource(source) + if err != nil { + ctx.Error(http.StatusInternalServerError, "convert.ToAuthSource", err) + return + } + ctx.JSON(http.StatusOK, result) +} + // CreateAuthSource creates new authentication source func CreateAuthSource(ctx *context.APIContext) { // swagger:operation POST /admin/auths admin adminCreateAuthSource @@ -118,3 +150,38 @@ func CreateAuthSource(ctx *context.APIContext) { } ctx.JSON(http.StatusCreated, result) } + +// DeleteAuthSource delete an authentication source +func DeleteAuthSource(ctx *context.APIContext) { + // swagger:operation DELETE /admin/auths/{id} admin adminDeleteAuthSource + // --- + // summary: Delete an authentication source + // produces: + // - application/json + // parameters: + // - name: id + // in: path + // description: id of the authentication source to delete + // type: integer + // format: int64 + // required: true + // responses: + // "204": + // "$ref": "#/responses/empty" + + source, err := auth.GetSourceByID(ctx.ParamsInt64(":id")) + if err != nil { + ctx.ServerError("auth.GetSourceByID", err) + return + } + + if err = auth_service.DeleteSource(source); err != nil { + if auth.IsErrSourceInUse(err) { + ctx.Error(http.StatusInternalServerError, "auth_service.DeleteSource", err) + } else { + ctx.Error(http.StatusInternalServerError, "auth_service.DeleteSource", err) + } + return + } + ctx.Status(http.StatusNoContent) +} diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index fc61b7084f09b..228012c9327aa 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -1500,8 +1500,10 @@ func Routes() *web.Route { m.Group("/admin", func() { m.Group("/auths", func() { - m.Get("", admin.ListAuthSources) - m.Post("", bind(api.CreateAuthSource{}), admin.CreateAuthSource) + m.Combo("").Get(admin.ListAuthSources). + Post(bind(api.CreateAuthSource{}), admin.CreateAuthSource) + m.Combo("/{id}").Get(admin.GetAuthSource). + Delete(admin.DeleteAuthSource) }) m.Group("/cron", func() { m.Get("", admin.ListCronTasks) diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 3fc1b1bdc5331..e0ef7a3fce4e9 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -125,6 +125,58 @@ } } }, + "/admin/auths/{id}": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "admin" + ], + "summary": "Get an authentication source", + "operationId": "adminGetAuthSource", + "parameters": [ + { + "type": "integer", + "format": "int64", + "description": "id of the authentication source to get", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "$ref": "#/responses/AuthSource" + } + } + }, + "delete": { + "produces": [ + "application/json" + ], + "tags": [ + "admin" + ], + "summary": "Delete an authentication source", + "operationId": "adminDeleteAuthSource", + "parameters": [ + { + "type": "integer", + "format": "int64", + "description": "id of the authentication source to delete", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "204": { + "$ref": "#/responses/empty" + } + } + } + }, "/admin/cron": { "get": { "produces": [ @@ -23384,12 +23436,6 @@ } } }, - "CreateAuthSource": { - "description": "CreateAuthSource", - "schema": { - "$ref": "#/definitions/CreateAuthSource" - } - }, "Branch": { "description": "Branch", "schema": { @@ -23547,6 +23593,12 @@ "$ref": "#/definitions/ContentsResponse" } }, + "CreateAuthSource": { + "description": "CreateAuthSource", + "schema": { + "$ref": "#/definitions/CreateAuthSource" + } + }, "CronList": { "description": "CronList", "schema": { From 92972a46d5dda68fc569f8f56606ce830ff68e75 Mon Sep 17 00:00:00 2001 From: Jeffrey Clark Date: Mon, 6 Feb 2023 20:24:02 +0000 Subject: [PATCH 4/4] chore lint and doc --- modules/convert/auth_source.go | 4 ++-- routers/api/v1/admin/auths.go | 6 +----- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/modules/convert/auth_source.go b/modules/convert/auth_source.go index e2219afafc911..90ffc3c28ab55 100644 --- a/modules/convert/auth_source.go +++ b/modules/convert/auth_source.go @@ -9,7 +9,7 @@ import ( api "code.gitea.io/gitea/modules/structs" ) -// ToAuthSources convert a list of models.LoginSource to a list of api.AuthSource +// ToAuthSources convert a list of auth.Source to a list of api.AuthSource func ToAuthSources(sources []*auth.Source) ([]*api.AuthSource, error) { result := make([]*api.AuthSource, len(sources)) for i, source := range sources { @@ -22,7 +22,7 @@ func ToAuthSources(sources []*auth.Source) ([]*api.AuthSource, error) { return result, nil } -// ToAuthSource convert a auth.LoginSource to a api.AuthSource +// ToAuthSource convert a auth.Source to a api.AuthSource func ToAuthSource(source *auth.Source) (*api.AuthSource, error) { cfg, err := source.Cfg.ToDB() if err != nil { diff --git a/routers/api/v1/admin/auths.go b/routers/api/v1/admin/auths.go index 014f23030a26d..5d46111bfab7e 100644 --- a/routers/api/v1/admin/auths.go +++ b/routers/api/v1/admin/auths.go @@ -176,11 +176,7 @@ func DeleteAuthSource(ctx *context.APIContext) { } if err = auth_service.DeleteSource(source); err != nil { - if auth.IsErrSourceInUse(err) { - ctx.Error(http.StatusInternalServerError, "auth_service.DeleteSource", err) - } else { - ctx.Error(http.StatusInternalServerError, "auth_service.DeleteSource", err) - } + ctx.Error(http.StatusInternalServerError, "auth_service.DeleteSource", err) return } ctx.Status(http.StatusNoContent)