Skip to content

Commit

Permalink
Merge pull request #1274 from longguikeji/release-2.5.13
Browse files Browse the repository at this point in the history
Release 2.5.13
  • Loading branch information
notevery committed Sep 14, 2022
2 parents ca0abc6 + 6dc1bc7 commit 24ca5e4
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 10 deletions.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ FROM ${BASEIMAGE}
ARG DEBIAN=http://mirrors.aliyun.com/debian
ARG DEBIANSRT=http://mirrors.aliyun.com/debian-security
ARG PIP=https://mirrors.aliyun.com/pypi/simple
ARG ARKID_VERSION=dev

WORKDIR /var/arkid

ENV PYTHONUSERBASE=/var/arkid/arkid_extensions PATH=$PATH:/var/arkid/arkid_extensions/bin
ENV PYTHONUSERBASE=/var/arkid/arkid_extensions PATH=$PATH:/var/arkid/arkid_extensions/bin ARKID_VERSION=${ARKID_VERSION}

ADD . .
RUN sed -i 's/MinProtocol = TLSv1.2/MinProtocol = TLSv1.0/g' /etc/ssl/openssl.cnf; \
Expand Down
2 changes: 1 addition & 1 deletion api/v1/pages/platform_admin/tenant_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
)
},
local_actions={
"switch": actions.URLAction(
"switch": actions.DirectAction(
name=_("切换"),
path='/api/v1/mine/switch_tenant/{id}/',
method=actions.FrontActionMethod.GET
Expand Down
13 changes: 12 additions & 1 deletion api/v1/schema/platform_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,15 @@ class FrontendUrlSchema(Schema):


class FrontendUrlOut(ResponseSchema):
data: Optional[FrontendUrlSchema]
data: Optional[FrontendUrlSchema]


class VersionSchema(Schema):
version: Optional[str] = Field(title=_("Version", "版本"))
update_available: Optional[bool] = Field(title=_("Update Available", "是否有更新"))
new_version: Optional[str] = Field(title=_("New Version", "新版本"))
update_url: Optional[str] = Field(title=_("Update URL", "更新链接"))


class VersionOut(ResponseSchema):
data: Optional[VersionSchema]
50 changes: 48 additions & 2 deletions api/v1/views/platform_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import os
import requests
from django.conf import settings
from arkid.config import get_app_config
from arkid.core.api import api, operation
from arkid.core.constants import *
Expand All @@ -9,13 +11,20 @@
from arkid.core.event import Event, dispatch_event, SET_FRONTEND_URL


@api.get("/platform_config/",response=PlatformConfigOut, tags=["平台配置"],auth=None)
@operation()
@api.get("/platform_config/",response=PlatformConfigOut, tags=["平台配置"])
@operation(roles=[PLATFORM_ADMIN])
def get_platform_config(request):
""" 获取平台配置
"""
return {"data": Platform.get_config() }

@api.get("/platform_config_with_no_permission/",response=PlatformConfigOut, tags=["平台配置"],auth=None)
@operation()
def get_platform_config_with_no_permission(request):
""" 获取平台配置
"""
return {"data": Platform.get_config() }

@api.post("/platform_config/",response=ResponseSchema,tags=["平台配置"])
@operation(roles=[PLATFORM_ADMIN])
def update_platform_config(request,data:PlatformConfigIn):
Expand Down Expand Up @@ -72,6 +81,10 @@ def set_frontend_url(request, data:FrontendUrlSchemaIn):
)
config.frontend_url = url
config.save()

from arkid import settings
if config.frontend_url:
settings.CSRF_TRUSTED_ORIGINS.append(config.frontend_url)

dispatch_event(
Event(
Expand All @@ -88,3 +101,36 @@ def set_frontend_url(request, data:FrontendUrlSchemaIn):
"dev": False if os.environ.get('K8SORDC') else True
}
)


@api.get("/version/",response=VersionOut, tags=["平台配置"], auth=None)
def get_version(request):
""" 获取ArkId版本
"""
version = os.environ.get('ARKID_VERSION', '')
update_url = settings.UPDATE_URL

if settings.IS_CENTRAL_ARKID:
new_version = ''
update_available = False
else:
try:
arkid_saas_version_url = settings.ARKID_SAAS_URL + '/api/v1/version/'
resp = requests.get(arkid_saas_version_url, timeout=5).json()
new_version = resp.get('data', {}).get('version', '')
if version and new_version and version < new_version:
update_available = True
else:
update_available = False
except:
new_version = ''
update_available = False

return SuccessDict(
data={
"version": version,
"update_available": update_available,
"new_version": new_version,
"update_url": update_url
}
)
10 changes: 5 additions & 5 deletions arkid/common/arkstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,11 +473,11 @@ def create_tenant_oidc_app(tenant, url, name, description='', logo=''):

@transaction.atomic()
def create_tenant_app(tenant, saas_app):
from arkid.core.event import Event, register_event, dispatch_event
from arkid.core.event import(
CREATE_APP_CONFIG, UPDATE_APP_CONFIG, DELETE_APP,
CREATE_APP_DONE, SET_APP_OPENAPI_VERSION,
)
# from arkid.core.event import Event, register_event, dispatch_event
# from arkid.core.event import(
# CREATE_APP_CONFIG, UPDATE_APP_CONFIG, DELETE_APP,
# CREATE_APP_DONE, SET_APP_OPENAPI_VERSION,
# )
defaults = {
"name": saas_app['name'],
"logo": saas_app['logo'],
Expand Down
8 changes: 8 additions & 0 deletions arkid/core/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,11 @@ def ready(self):
# 监听
from arkid.core import listener

try:
from arkid import settings
from arkid.core.models import Platform
config = Platform.get_config()
if config.frontend_url:
settings.CSRF_TRUSTED_ORIGINS.append(config.frontend_url)
except Exception as e:
print(e)
6 changes: 6 additions & 0 deletions arkid/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,12 @@
ARKID_SAAS_URL = 'https://central.arkid.cc' # 中心ARKID链接
ARKSTOER_URL = 'https://arkstore.longguikeji.com' # 插件商店链接

# update_url
UPDATE_URL = "https://longguikeji.github.io/arkid/%20%20%20%E5%BF%AB%E9%80%9F%E5%BC%80%E5%A7%8B/"

# 引入settings_local.py 本地配置文件
if os.path.exists(os.path.join(BASE_DIR, 'settings_local.py')):
exec(open(os.path.join(BASE_DIR, 'settings_local.py')).read())


CSRF_TRUSTED_ORIGINS = []
46 changes: 46 additions & 0 deletions extension_root/com_longgui_app_protocol_oidc/Case.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# 代码示例

## FastAPI

``` py
from fastapi import FastAPI
from starlette.responses import RedirectResponse
import requests
import json

app = FastAPI()


client_id = 'KHvanrQlNIBMZj9owre9ZZ6oc8AjWNdPHYUO2rwH'
client_secret = 'ywZCKjSzxiWfgiaoEYAmloQ0greaLxLtTv6TnOyRtsgjvR7xAiTwpY0H5A46ZSSYz3x5laxHXQSlpjamnih3aQlYqS7Eq6oiSXsjiGNXnnf750i8WbbWAVAZdEaiivas'
auth_url = 'http://localhost:9528/api/v1/tenant/bf3511e2-07b3-459f-829e-17a349602531/app/10e82a7d-b7fd-45e0-976b-885859066508/oauth/authorize/'
redirect_uri = 'http://127.0.0.1:8001/redirect'
get_token_url = 'http://localhost:9528/api/v1/tenant/bf3511e2-07b3-459f-829e-17a349602531/oauth/token/'
get_userinfo_url = 'http://localhost:9528/api/v1/tenant/bf3511e2-07b3-459f-829e-17a349602531/oauth/userinfo/'

@app.get("/auth")
def oidc_auth():
response = RedirectResponse(
url=auth_url+'?client_id='+client_id+'&redirect_uri='+redirect_uri+'&response_type=code&scope=userinfo')
return response


@app.get("/redirect")
def oidc_redirect(code:str):
auth = requests.auth.HTTPBasicAuth(client_id, client_secret)
response = requests.post(
url=get_token_url,
auth=auth,
data={'code':code, 'grant_type':'authorization_code'}
)

response = json.loads(response.content)
access_token = response["access_token"]

return requests.get(
url=get_userinfo_url,
headers={
'Authorization': 'Bearer ' + access_token
}
).content
```
1 change: 1 addition & 0 deletions oauth2_provider/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ def post(self, request, *args, **kwargs):
else:
return super().post(request, *args, **kwargs)


def get(self, request, *args, **kwargs):
try:
scopes, credentials = self.validate_authorization_request(request)
Expand Down

0 comments on commit 24ca5e4

Please sign in to comment.