Skip to content

Commit

Permalink
Merge pull request #282 from TencentBlueKing/development
Browse files Browse the repository at this point in the history
update to 2.3.3
  • Loading branch information
IMBlues authored Feb 21, 2022
2 parents d39373a + f1f545f commit 057f270
Show file tree
Hide file tree
Showing 36 changed files with 149 additions and 106 deletions.
23 changes: 6 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version ?= "development"
login_version ?= "development"
values ?=
image_repo ?= "ccr.ccs.tencentyun.com/bk.io"
image_repo ?= "mirrors.tencent.com/blueking"
chart_repo ?=
namespace ?= "bk-user"
test_release_name ?= "bk-user-test"
Expand Down Expand Up @@ -42,31 +42,20 @@ push:
docker push ${image_repo}/bk-user-saas:${version}
docker push ${image_repo}/bk-login:${login_version}

helm-sync:
mkdir -p deploy/helm/api/templates/
mkdir -p deploy/helm/saas/templates/
mkdir -p deploy/helm/login/templates/
ln -s ${PWD}/deploy/helm/chartty/* deploy/helm/api/templates/ || true
ln -s ${PWD}/deploy/helm/chartty/* deploy/helm/saas/templates/ || true
ln -s ${PWD}/deploy/helm/chartty/* deploy/helm/login/templates/ || true

ln -s ${PWD}/deploy/helm/chartty/c_*.tpl deploy/helm/bk-user-stack/templates/ || true

helm-refresh: helm-sync
cd deploy/helm && helm dependency update bk-user-stack --skip-refresh
helm-refresh:
cd deploy/helm && helm dependency update bk-user --skip-refresh

helm-debug: helm-refresh
cd deploy/helm && helm install ${test_release_name} bk-user-stack --debug --dry-run -f local_values.yaml
cd deploy/helm && helm install ${test_release_name} bk-user --debug --dry-run -f local_values.yaml

helm-install: helm-refresh
cd deploy/helm && helm upgrade --install ${test_release_name} bk-user-stack -n ${namespace} -f local_values.yaml
cd deploy/helm && helm upgrade --install ${test_release_name} bk-user -n ${namespace} -f local_values.yaml

helm-uninstall:
helm uninstall ${test_release_name} -n ${namespace} || true
kubectl delete deploy,sts,cronjob,pod,svc,ingress,secret,cm,sa,pvc -n ${namespace} -l app.kubernetes.io/instance=${test_release_name}

helm-package: helm-refresh
cd deploy/helm && helm package bk-user-stack -d dist/
cd deploy/helm && helm package bk-user -d dist/

helm-publish: deploy/helm/dist/*.tgz
for f in $^; do \
Expand Down
4 changes: 2 additions & 2 deletions deploy/helm/bk-user/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ apiVersion: v2
name: bk-user
description: A Helm chart for bk-user
type: application
version: 1.1.7
appVersion: v2.3.2
version: 1.1.9
appVersion: "v2.3.3"

dependencies:

Expand Down
2 changes: 1 addition & 1 deletion deploy/helm/bk-user/charts/api/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ name: api
description: Api module for bk-user
type: application
version: 1.0.0
appVersion: "2.3.2"
appVersion: "v2.3.3"
2 changes: 1 addition & 1 deletion deploy/helm/bk-user/charts/api/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ image:
registry: mirrors.tencent.com
repository: blueking/bk-user-api
pullPolicy: IfNotPresent
tag: "v2.3.2"
tag: "v2.3.3"

nameOverride: ""
fullnameOverride: ""
Expand Down
2 changes: 1 addition & 1 deletion deploy/helm/bk-user/charts/login/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ name: login
description: login module for blueking
type: application
version: 1.0.0
appVersion: "2.3.2"
appVersion: "v2.3.3"
4 changes: 2 additions & 2 deletions deploy/helm/bk-user/charts/login/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ image:
registry: mirrors.tencent.com
repository: blueking/bk-login
pullPolicy: IfNotPresent
tag: "v2.3.2"
tag: "v2.3.3"

nameOverride: ""
fullnameOverride: ""
Expand Down Expand Up @@ -236,4 +236,4 @@ volumes: []
volumeMounts: []
## 自定义登录插件示例
# - name: bk-login-plugin-example
# mountPath: /app/ee_login/
# mountPath: /app/bklogin/ee_login/
2 changes: 1 addition & 1 deletion deploy/helm/bk-user/charts/saas/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ name: saas
description: SaaS module for bk-user
type: application
version: 1.0.0
appVersion: "2.3.2"
appVersion: "v2.3.3"
2 changes: 1 addition & 1 deletion deploy/helm/bk-user/charts/saas/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ image:
registry: mirrors.tencent.com
repository: blueking/bk-user-saas
pullPolicy: IfNotPresent
tag: "v2.3.2"
tag: "v2.3.3"

command: []
args: []
Expand Down
20 changes: 20 additions & 0 deletions docs/changelogs/CHANGELOG-2.3.3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!-- generated by script, do not modify it manually -->
# Changelog [2.3.3] - 2022-02-21

## SaaS

### OPTIMIZATION

- 更新页面 Header &amp; Footer

### FIX

- SaaS 上重置密码时会清空该用户的 weixin、QQ 等字段 #275

## Login

### OPTIMIZATION

- 修复 Login bk_token 引号问题
- 更新页面 Header &amp; Footer

9 changes: 0 additions & 9 deletions docs/develop_api_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,3 @@ python manage.py makemessages --all
python manage.py compilemessages -l en
python manage.py compilemessages -l zh-hans
```

## 关于缓存

用户管理默认是没有开启缓存能力的,可以通过环境变量控制缓存使用与否

``` bash
# 关闭缓存
export BK_USER_NO_CACHE=1
```
22 changes: 20 additions & 2 deletions docs/develop_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
├── api # 后台 API 代码目录
├── bkuser_global # 公共代码目录
├── pages # SaaS 前端代码
├── login # 蓝鲸登录代码(包含前端 + 后台)
├── sdk # 由 API 生成的 SDK 代码
└── saas # SaaS 后端代码
```

本地开发时,你需要分别为三个模块——后台 API、SaaS 前端、SaaS 后端——创建开发环境。
本地开发时,你需要分别为四个模块——后台 API、SaaS 前端、SaaS 后端、蓝鲸登录——创建开发环境。

在开始开发前,你需要为整个项目安装并初始化 `pre-commit`

Expand Down Expand Up @@ -46,7 +47,7 @@ poetry install

运行
```bash
bin/start_dev.sh
bash bin/start_dev.sh
```

## SaaS 前端开发
Expand All @@ -64,4 +65,21 @@ npm install
### 运行
```bash
npm run dev
```

## 蓝鲸登录开发
与 SaaS 类似,你需要首先链接公共代码(前面任意一步做过即可跳过)
```bash
make link
```

### 安装依赖
```bash
cd src/login
poetry install
```

运行
```bash
bash bin/start_dev.sh
```
1 change: 1 addition & 0 deletions docs/release.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!-- generated by script, do not modify it manually -->
# CHANGELOGs

- [CHANGELOG-2.3.3.md](changelogs/CHANGELOG-2.3.3.md)
- [CHANGELOG-2.3.2.md](changelogs/CHANGELOG-2.3.2.md)
- [CHANGELOG-2.3.1.md](changelogs/CHANGELOG-2.3.1.md)
- [CHANGELOG-2.3.0.md](changelogs/CHANGELOG-2.3.0.md)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "蓝鲸用户管理"
version = "2.3.2"
version = "2.3.3"
description = "project description file for ci"
authors = ["IMBlues <bluesedenyu@gmail.com>"]

Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

---
[![license](https://img.shields.io/badge/license-mit-green.svg?style=flat)](https://github.com/TencentBlueKing/bk-user/blob/master/LICENSE)
[![Release Version](https://img.shields.io/badge/bk--user-2.3.1-green)](https://github.com/TencentBlueKing/bk-user/releases)
[![Release Version](https://img.shields.io/badge/bk--user-2.3.3-green)](https://github.com/TencentBlueKing/bk-user/releases)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-green.svg)](https://github.com/TencentBlueKing/bk-user/pulls)

简体中文 | [English](readme_en.md)
Expand All @@ -25,7 +25,7 @@

## 快速开始

- [Helm 快速部署指引](/deploy/helm/bk-user-stack/README.md)
- [Helm 快速部署指引](/deploy/helm/bk-user/README.md)
- [本地开发部署指引](/docs/develop_guide.md)

## 路线图
Expand Down
4 changes: 2 additions & 2 deletions readme_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

---
[![license](https://img.shields.io/badge/license-mit-green.svg?style=flat)](https://github.com/TencentBlueKing/bk-user/blob/master/LICENSE)
[![Release Version](https://img.shields.io/badge/bk--user-2.3.1-green)](https://github.com/TencentBlueKing/bk-user/releases)
[![Release Version](https://img.shields.io/badge/bk--user-2.3.3-green)](https://github.com/TencentBlueKing/bk-user/releases)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-green.svg)](https://github.com/TencentBlueKing/bk-user/pulls)

[简体中文](readme.md) | English
Expand All @@ -26,7 +26,7 @@ For details, please refer to [features](https://bk.tencent.com/docs/document/6.0

## Getting Started

- [Deploy by Helm](/deploy/helm/bk-user-stack/README.md)
- [Deploy by Helm](/deploy/helm/bk-user/README.md)
- [Local Developing](/docs/develop_guide.md)

## Roadmap
Expand Down
9 changes: 8 additions & 1 deletion src/api/bkuser_core/config/common/django_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"""
import os

from . import PROJECT_ROOT
from . import PROJECT_ROOT, env

# only for django itself(internal hashes), not a specific identity
SECRET_KEY = "Zfljnbga5QYVqNpOXLwhfGQLplZHHj3FuQWdAcaqTiDrDUfsTS"
Expand Down Expand Up @@ -155,3 +155,10 @@
"SECURITY_DEFINITIONS": {},
"DEFAULT_AUTO_SCHEMA_CLASS": "bkuser_core.apis.swagger.AutoModelTagSchema",
}

# ==============================================================================
# Celery
# ==============================================================================
CELERY_BROKER_URL = env("CELERY_BROKER_URL")
CELERY_RESULT_BACKEND = env("CELERY_RESULT_BACKEND")
CELERY_TASK_DEFAULT_QUEUE = env("CELERY_TASK_DEFAULT_QUEUE", default="bk_user")
5 changes: 0 additions & 5 deletions src/api/bkuser_core/config/common/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@

REDIS_URL = f"redis://:{REDIS_PASSWORD}@{REDIS_HOST}:{REDIS_PORT}/{REDIS_DB}"

# ==============================================================================
# RabbitMQ
# ==============================================================================
CELERY_BROKER_URL = env("CELERY_BROKER_URL")
CELERY_RESULT_BACKEND = env("CELERY_RESULT_BACKEND")

# ==============================================================================
# 缓存配置
Expand Down
2 changes: 1 addition & 1 deletion src/api/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "bk-user-api"
version = "2.3.2"
version = "2.3.3"
description = "bk-user Api"
authors = ["IMBlues <bluesedenyu@gmail.com>"]

Expand Down
7 changes: 7 additions & 0 deletions src/login/bin/start_dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#! /bin/bash

# 激活虚拟环境
poetry shell

python manage.py migrate || true
python manage.py runserver 0.0.0.0:8003
4 changes: 0 additions & 4 deletions src/login/bklogin/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
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.
"""


from __future__ import unicode_literals

from bklogin.api.constants import ApiErrorCodeEnum, ApiErrorCodeEnumV2, ApiErrorCodeEnumV3
from bklogin.api.utils import (
APIV1FailJsonResponse,
Expand Down
7 changes: 6 additions & 1 deletion src/login/bklogin/bkauth/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,12 @@ def login_success_response(request, user_or_form, redirect_to, app_id):
bk_token, expire_time = get_bk_token(username)
response = HttpResponseRedirect(redirect_to)
response.set_cookie(
BK_COOKIE_NAME, bk_token, expires=expire_time, domain=settings.BK_COOKIE_DOMAIN, httponly=True, secure=secure
BK_COOKIE_NAME,
urllib.parse.quote_plus(bk_token),
expires=expire_time,
domain=settings.BK_COOKIE_DOMAIN,
httponly=True,
secure=secure,
)

# set cookie for app or platform
Expand Down
25 changes: 11 additions & 14 deletions src/login/bklogin/bkauth/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import datetime
import time
import unicodedata
import urllib.parse
from urllib.parse import urlparse

from bklogin.bkaccount.models import BkToken, LoginLog
Expand Down Expand Up @@ -45,10 +46,8 @@ def get_bk_token(username):
plain_token = "%s|%s|%s" % (expire_time, username, salt())
bk_token = EncryptHandler().encrypt(plain_token)
try:
# BkToken.objects.create(token=bk_token)
BkToken.objects.create(token=bk_token, inactive_expire_time=inactive_expire_time)
except Exception:
# logger.exception(u"登录票据保存失败")
logger.exception("Login ticket failed to be saved during ticket generation")
# 循环结束前将bk_token置空后重新生成
bk_token = "" if retry_count < 4 else bk_token
Expand All @@ -61,18 +60,17 @@ def is_bk_token_valid(bk_token): # NOQA
验证用户登录态
"""
if not bk_token:
error_msg = _("缺少参数bk_token")
error_msg = _("参数 bk_token 缺失")
return False, error_msg

bk_token = urllib.parse.unquote(bk_token)
try:
plain_bk_token = EncryptHandler().decrypt(bk_token)
except Exception:
logger.exception("参数[%s] 解析失败" % bk_token)
plain_bk_token = ""
# logger.exception(u"参数[%s]解析失败" % bk_token)
logger.exception("Parameter[%s] parse failed" % bk_token)

# 参数bk_token非法
error_msg = _("参数bk_token非法")
error_msg = _("参数 bk_token 非法")
if not plain_bk_token:
return False, error_msg

Expand All @@ -81,16 +79,15 @@ def is_bk_token_valid(bk_token): # NOQA
if not token_info or len(token_info) < 3:
return False, error_msg
except Exception:
logger.exception("split token fail: %s" % bk_token)
logger.exception("分割 bk_token[%s] 失败" % bk_token)
return False, error_msg

try:
# is_logout = BkToken.objects.get(token=bk_token).is_logout
bktoken_obj = BkToken.objects.get(token=bk_token)
is_logout = bktoken_obj.is_logout
inactive_expire_time = bktoken_obj.inactive_expire_time
bk_token_obj = BkToken.objects.get(token=bk_token)
is_logout = bk_token_obj.is_logout
inactive_expire_time = bk_token_obj.inactive_expire_time
except Exception:
error_msg = _("不存在bk_token[%s]的记录") % bk_token
error_msg = _("不存在 bk_token[%s] 的记录") % bk_token
return False, error_msg

expire_time = int(token_info[0])
Expand All @@ -108,7 +105,7 @@ def is_bk_token_valid(bk_token): # NOQA
error_msg = _("登录态有效期不合法")
return False, error_msg

# token 无操作有效期已过
# token 无操作有效期已过
if now_time > inactive_expire_time + settings.BK_TOKEN_OFFSET_ERROR_TIME:
error_msg = _("长时间无操作,登录态已过期")
return False, error_msg
Expand Down
Loading

0 comments on commit 057f270

Please sign in to comment.