Skip to content

Commit

Permalink
bug fix: fix signout feature
Browse files Browse the repository at this point in the history
  • Loading branch information
cho4036 committed Jun 5, 2023
1 parent 90cc054 commit c5d1ab6
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 57 deletions.
8 changes: 4 additions & 4 deletions api/swagger/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3380,10 +3380,6 @@ const docTemplate = `{
"description": "URL of built image for app",
"type": "string"
},
"note": {
"description": "additional note",
"type": "string"
},
"output": {
"description": "output for task result",
"type": "string"
Expand Down Expand Up @@ -3415,6 +3411,10 @@ const docTemplate = `{
"description": "resource spec of app pod",
"type": "string"
},
"rollbackVersion": {
"description": "rollback target version",
"type": "string"
},
"status": {
"description": "status is app status",
"type": "string"
Expand Down
8 changes: 4 additions & 4 deletions api/swagger/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -3373,10 +3373,6 @@
"description": "URL of built image for app",
"type": "string"
},
"note": {
"description": "additional note",
"type": "string"
},
"output": {
"description": "output for task result",
"type": "string"
Expand Down Expand Up @@ -3408,6 +3404,10 @@
"description": "resource spec of app pod",
"type": "string"
},
"rollbackVersion": {
"description": "rollback target version",
"type": "string"
},
"status": {
"description": "status is app status",
"type": "string"
Expand Down
6 changes: 3 additions & 3 deletions api/swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,6 @@ definitions:
imageUrl:
description: URL of built image for app
type: string
note:
description: additional note
type: string
output:
description: output for task result
type: string
Expand All @@ -210,6 +207,9 @@ definitions:
resourceSpec:
description: resource spec of app pod
type: string
rollbackVersion:
description: rollback target version
type: string
status:
description: status is app status
type: string
Expand Down
98 changes: 52 additions & 46 deletions internal/usecase/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/http"
"net/url"
"strings"
"time"

"github.com/openinfradev/tks-api/pkg/log"
"github.com/spf13/viper"
Expand Down Expand Up @@ -49,52 +50,6 @@ type AuthUsecase struct {
appgroupRepository repository.IAppGroupRepository
}

func (u *AuthUsecase) SingleSignOut(organizationId string) (map[string][]string, []*http.Cookie, error) {
urls := make(map[string][]string)

clusters, err := u.clusterRepository.FetchByOrganizationId(organizationId)
log.Info("clusters", clusters)
if err != nil {
return nil, nil, err
}
if len(clusters) == 0 {
return nil, nil, nil
}
for _, cluster := range clusters {
appgroups, err := u.appgroupRepository.Fetch(cluster.ID)
log.Info("appgroups", appgroups)
if err != nil {
return nil, nil, err
}
if len(appgroups) == 0 {
continue
}
for _, appgroup := range appgroups {
for _, appType := range []domain.ApplicationType{domain.ApplicationType_GRAFANA, domain.ApplicationType_KIALI} {
apps, err := u.appgroupRepository.GetApplications(appgroup.ID, appType)
if err != nil {
return nil, nil, err
}
if urls[strings.ToLower(appType.String())] == nil {
urls[strings.ToLower(appType.String())] = []string{}
}
for _, app := range apps {
urls[strings.ToLower(appType.String())] = append(urls[strings.ToLower(appType.String())], app.Endpoint+"/logout")
}
}
}
}

cookies := []*http.Cookie{
{
Name: KEYCLOAK_IDENTITY_COOKIE,
MaxAge: -1,
},
}

return urls, cookies, nil
}

func NewAuthUsecase(r repository.Repository, kc keycloak.IKeycloak) IAuthUsecase {
return &AuthUsecase{
kc: kc,
Expand Down Expand Up @@ -300,6 +255,57 @@ func (u *AuthUsecase) SingleSignIn(organizationId, accountId, password string) (
return cookies, nil
}

func (u *AuthUsecase) SingleSignOut(organizationId string) (map[string][]string, []*http.Cookie, error) {
urls := make(map[string][]string)

clusters, err := u.clusterRepository.FetchByOrganizationId(organizationId)
log.Info("clusters", clusters)
if err != nil {
return nil, nil, err
}
if len(clusters) == 0 {
return nil, nil, nil
}
for _, cluster := range clusters {
appgroups, err := u.appgroupRepository.Fetch(cluster.ID)
log.Info("appgroups", appgroups)
if err != nil {
return nil, nil, err
}
if len(appgroups) == 0 {
continue
}
for _, appgroup := range appgroups {
for _, appType := range []domain.ApplicationType{domain.ApplicationType_GRAFANA, domain.ApplicationType_KIALI} {
apps, err := u.appgroupRepository.GetApplications(appgroup.ID, appType)
if err != nil {
return nil, nil, err
}
if urls[strings.ToLower(appType.String())] == nil {
urls[strings.ToLower(appType.String())] = []string{}
}
for _, app := range apps {
urls[strings.ToLower(appType.String())] = append(urls[strings.ToLower(appType.String())], app.Endpoint+"/logout")
}
}
}
}

cookies := []*http.Cookie{
{
Name: KEYCLOAK_IDENTITY_COOKIE,
MaxAge: -1,
Expires: time.Now().AddDate(0, 0, -1),
Path: "/auth/realms/" + organizationId,
HttpOnly: true,
Secure: true,
SameSite: http.SameSiteNoneMode,
},
}

return urls, cookies, nil
}

func (u *AuthUsecase) isExpiredEmailCode(code repository.CacheEmailCode) bool {
return !helper.IsDurationExpired(code.UpdatedAt, internal.EmailCodeExpireTime)
}
Expand Down

0 comments on commit c5d1ab6

Please sign in to comment.