-
Notifications
You must be signed in to change notification settings - Fork 378
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set up ory kratos, add identity admin api (#1460)
* Set up ory kratos, add identity admin api * Code refactor, comment in kratos config
- Loading branch information
Showing
44 changed files
with
1,411 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
CREATE TABLE `kratos_uc_userid_mapping` ( | ||
`id` varchar(50) NOT NULL COMMENT 'uc userid', | ||
`user_id` varchar(191) NOT NULL COMMENT 'kratos user uuid', | ||
`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'created time', | ||
`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'updated time', | ||
PRIMARY KEY (`id`), | ||
KEY `idx_user_id` (`user_id`) | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='id mapping'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright (c) 2021 Terminus, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package dao | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
|
||
"github.com/jinzhu/gorm" | ||
|
||
"github.com/erda-project/erda/modules/core-services/model" | ||
) | ||
|
||
var joinMap = "LEFT OUTER JOIN kratos_uc_userid_mapping on kratos_uc_userid_mapping.id = uc_user.id" | ||
|
||
const noPass = "no pass" | ||
|
||
func (client *DBClient) GetUcUserList() ([]model.User, error) { | ||
var users []model.User | ||
sql := client.Table("uc_user").Joins(joinMap) | ||
if err := sql.Where("password != ? AND password IS NOT NULL AND kratos_uc_userid_mapping.id IS NULL", noPass).Find(&users).Error; err != nil { | ||
return nil, err | ||
} | ||
return users, nil | ||
} | ||
|
||
func (client *DBClient) InsertMapping(userID, uuid, hash string) error { | ||
return client.Transaction(func(tx *gorm.DB) error { | ||
sql := fmt.Sprintf("UPDATE identity_credentials SET config = JSON_SET(config, '$.hashed_password', ?) WHERE identity_id = ?") | ||
if err := tx.Exec(sql, hash, uuid).Error; err != nil { | ||
return err | ||
} | ||
return client.Table("kratos_uc_userid_mapping").Create(&model.UserIDMapping{ID: userID, UserID: uuid}).Error | ||
}) | ||
} | ||
|
||
func (client *DBClient) GetUcUserID(uuid string) (string, error) { | ||
var users []model.User | ||
if err := client.Table("kratos_uc_userid_mapping").Select("id").Where("user_id = ?", uuid).Find(&users).Error; err != nil { | ||
return "", err | ||
} | ||
if len(users) == 0 { | ||
return "", nil | ||
} | ||
return strconv.FormatInt(users[0].ID, 10), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright (c) 2021 Terminus, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package model | ||
|
||
type User struct { | ||
BaseModel | ||
Avatar string | ||
Username string | ||
Nickname string | ||
Mobile string | ||
Email string | ||
Password string | ||
} | ||
|
||
type Config struct { | ||
HashedPassword string `json:"hashed_password"` | ||
} | ||
|
||
type UserIDMapping struct { | ||
ID string | ||
UserID string | ||
} |
Oops, something went wrong.