Skip to content

Commit

Permalink
enhance: 添加应用特性 MODIFY_ENVIRONMENT_VARIABLE 控制是否支持修改环境变量, 目前仅前端实现该特性开关 (
Browse files Browse the repository at this point in the history
  • Loading branch information
shabbywu authored Feb 9, 2023
1 parent c8355b1 commit 5f59e1b
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 82 deletions.
4 changes: 2 additions & 2 deletions apiserver/paasng/assets/javascripts/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ const i18n = {
messages: {
// 中文语言包
'zh-cn': {
'系统出现异常': '系统出现异常'
'系统出现异常': '系统出现异常'
},
// 英文语言包
en: {
'系统出现异常': 'System exception'
'系统出现异常': 'System exception'
}
},
t: function (message) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,18 @@ def run(self, command: GitCommand, success_code: int = 0) -> str:
env=environment_variables,
cwd=command.cwd,
) as proc:
timeout = False
try:
stdout, _ = proc.communicate(timeout=self._default_timeout)
except subprocess.TimeoutExpired:
proc.kill()
timeout = True

# 不能在 except 中抛异常, 否则 TimeoutExpired 会自动被 traceback 跟踪导致暴露明文的 command 指令
if timeout:
raise GitCommandExecutionError(
f"Command failed: cmd <{command}> execution timeout({self._default_timeout}s)"
)

if proc.returncode != success_code:
raise GitCommandExecutionError(
f"Command failed with ({proc.returncode}):\n>>> {command}\n{stdout.decode()}"
Expand Down
13 changes: 1 addition & 12 deletions apiserver/paasng/paasng/platform/applications/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

from blue_krill.data_types.enum import EnumField, FeatureFlag, FeatureFlagField, StructuredEnum

from paasng.utils.basic import ChoicesEnum


class ApplicationType(str, StructuredEnum):
DEFAULT = EnumField('default') # 默认类型:无任何定制逻辑
Expand Down Expand Up @@ -88,16 +86,6 @@ class AppEnvironment(str, StructuredEnum):
PRODUCTION = EnumField("prod", label="生产环境")


class AppResourceType(ChoicesEnum):
# deprecated
"""app的资源类型"""

ONLINE_RESOURCE = 1
APP_RECORD = 2

_choices_labels = ((ONLINE_RESOURCE, u"线上资源"), (APP_RECORD, u'应用记录'))


class AppFeatureFlag(FeatureFlag):
"""App feature 常量表"""

Expand All @@ -111,6 +99,7 @@ class AppFeatureFlag(FeatureFlag):
PA_INGRESS_ANALYTICS = FeatureFlagField(label="访问日志统计功能")
PA_USER_DIMENSION_SHOW_DEPT = FeatureFlagField(label="按用户维度拆分展示部门字段")
APPLICATION_DESCRIPTION = FeatureFlagField(label="部署时使用应用描述文件", default=True)
MODIFY_ENVIRONMENT_VARIABLE = FeatureFlagField(label="修改环境变量", default=True)


class LightApplicationViewSetErrorCode(str, StructuredEnum):
Expand Down
6 changes: 5 additions & 1 deletion apiserver/paasng/paasng/platform/log/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ def get_es_term(query_term: str, mappings: dict) -> str:
# 去掉最后一个 "properties"
# ["json", "levelname"] -> ["json", "properties", "levelname"]
parts = list(chain.from_iterable(zip(parts, ["properties"] * len(parts))))[:-1]
target = reduce(operator.getitem, parts, mappings)
try:
target = reduce(operator.getitem, parts, mappings)
except KeyError:
logger.warning("can't parse %s from mappings, return what it is", query_term)
return query_term

if target["type"] == "text":
return f"{query_term}.keyword"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class TestGetDefaultFeatureFlags:
'PA_INGRESS_ANALYTICS': False,
'PA_USER_DIMENSION_SHOW_DEPT': False,
'APPLICATION_DESCRIPTION': True,
'MODIFY_ENVIRONMENT_VARIABLE': True,
},
),
(
Expand All @@ -56,6 +57,7 @@ class TestGetDefaultFeatureFlags:
'PA_INGRESS_ANALYTICS': False,
'PA_USER_DIMENSION_SHOW_DEPT': False,
'APPLICATION_DESCRIPTION': True,
'MODIFY_ENVIRONMENT_VARIABLE': True,
},
),
(
Expand All @@ -71,6 +73,7 @@ class TestGetDefaultFeatureFlags:
'PA_INGRESS_ANALYTICS': True,
'PA_USER_DIMENSION_SHOW_DEPT': False,
'APPLICATION_DESCRIPTION': True,
'MODIFY_ENVIRONMENT_VARIABLE': True,
},
),
(
Expand All @@ -86,6 +89,7 @@ class TestGetDefaultFeatureFlags:
'PA_INGRESS_ANALYTICS': False,
'PA_USER_DIMENSION_SHOW_DEPT': False,
'APPLICATION_DESCRIPTION': True,
'MODIFY_ENVIRONMENT_VARIABLE': True,
},
),
(
Expand All @@ -110,6 +114,7 @@ class TestGetDefaultFeatureFlags:
'PA_INGRESS_ANALYTICS': False,
'PA_USER_DIMENSION_SHOW_DEPT': True,
'APPLICATION_DESCRIPTION': True,
'MODIFY_ENVIRONMENT_VARIABLE': True,
},
),
],
Expand Down
8 changes: 6 additions & 2 deletions webfe/package_vue/src/language/lang/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export default {
'权限管理功能目前只支持主模块': 'The permission management function only supports the default module',
'新增模块': 'Add module',
'应用目前不允许创建其它模块': 'The app is currently not allowed to create other modules',
'当前应用不允许新增模块': 'He current app does not allow new modules',
'当前应用不允许新增模块': 'The current app does not allow new modules',
'帮助': 'Help',
'访问入口': 'Network & Domains',
'代码检查': 'Code Analysis',
Expand Down Expand Up @@ -2077,5 +2077,9 @@ export default {
'仅管理员可添加成员': 'Only administrators can add members',
'插件创建成功!': 'Plugin created successfully!',
'提交者': 'submitter',
'请选择代码分支': 'Please select a code branch'
'请选择代码分支': 'Please select a code branch',
'应用已迁移到插件开发中心,本页面仅做展示用,如需操作请到': 'The app has been migrated to the Plugin Center, this page is for demonstration purposes only, if you need to operate it please go to',
'插件开发- 配置管理页面': 'the Plugin-Center - Configurations',
'。': '.',
'当前应用不支持配置环境变量。': 'The current application does not support the configuration of environment variables.'
};
6 changes: 5 additions & 1 deletion webfe/package_vue/src/language/lang/zh.js
Original file line number Diff line number Diff line change
Expand Up @@ -2079,5 +2079,9 @@ export default {
'仅管理员可添加成员': '仅管理员可添加成员',
'插件创建成功!': '插件创建成功!',
'提交者': '提交者',
'请选择代码分支': '请选择代码分支'
'请选择代码分支': '请选择代码分支',
'应用已迁移到插件开发中心,本页面仅做展示用,如需操作请到': '应用已迁移到插件开发中心,本页面仅做展示用,如需操作请到',
'插件开发- 配置管理页面': '插件开发- 配置管理页面',
'。': '。',
'当前应用不支持配置环境变量。': '当前应用不支持配置环境变量。'
};
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@
{{ nodeIp.internal_ip_address }}
</div>
</template>
<template v-else-if="!curAppModule.clusters.stag.feature_flags.enable_egress_ip">
<template v-else-if="!curAppModule.clusters.stag.feature_flags.ENABLE_EGRESS_IP">
<div class="no-ip">
<p> {{ $t('该环境暂不支持获取出流量 IP 信息') }} </p>
</div>
Expand Down Expand Up @@ -504,7 +504,7 @@
{{ nodeIp.internal_ip_address }}
</div>
</template>
<template v-else-if="!curAppModule.clusters.prod.feature_flags.enable_egress_ip">
<template v-else-if="!curAppModule.clusters.prod.feature_flags.ENABLE_EGRESS_IP">
<div class="no-ip">
<p> {{ $t('该环境暂不支持获取出流量 IP 信息') }} </p>
</div>
Expand Down Expand Up @@ -947,10 +947,10 @@
return !this.displaySwitchDisabled;
},
curStagDisabled () {
return this.gatewayInfosStagLoading || this.isGatewayInfosBeClearing || !this.curAppModule.clusters.stag.feature_flags.enable_egress_ip;
return this.gatewayInfosStagLoading || this.isGatewayInfosBeClearing || !this.curAppModule.clusters.stag.feature_flags.ENABLE_EGRESS_IP;
},
curProdDisabled () {
return this.gatewayInfosProdLoading || this.isGatewayInfosBeClearing || !this.curAppModule.clusters.prod.feature_flags.enable_egress_ip;
return this.gatewayInfosProdLoading || this.isGatewayInfosBeClearing || !this.curAppModule.clusters.prod.feature_flags.ENABLE_EGRESS_IP;
},
entranceConfig () {
return this.$store.state.region.entrance_config;
Expand Down
Loading

0 comments on commit 5f59e1b

Please sign in to comment.