Skip to content

Commit

Permalink
pref: add oss storage
Browse files Browse the repository at this point in the history
Signed-off-by: liangjunhao <3220663807@qq.com>
  • Loading branch information
paterleng committed Jul 31, 2024
1 parent 8c0b5d8 commit 5b4c1a5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 13 deletions.
3 changes: 2 additions & 1 deletion console/services/k8s_attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ def list_by_component_ids(self, component_ids):
return result

@transaction.atomic
def create_k8s_attribute(self, tenant, component, region_name, attribute):
def create_k8s_attribute(self, tenant, component, region_name, attribute, nike_name):
if attribute["save_type"] == "json":
attribute_value = attribute.get("attribute_value", [])
attribute_value_json = json.dumps({value["key"]: value["value"] for value in attribute_value})
attribute["attribute_value"] = attribute_value_json
k8s_attribute_repo.create(tenant_id=tenant.tenant_id, component_id=component.service_id, **attribute)
attribute["operator"] = nike_name
region_api.create_component_k8s_attribute(tenant.tenant_name, region_name, component.service_alias, attribute)

@transaction.atomic
Expand Down
4 changes: 2 additions & 2 deletions console/views/k8s_attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ def get(self, request, *args, **kwargs):

def post(self, request, *args, **kwargs):
attribute = request.data.get("attribute", {})
attribute['operator'] = self.user.nick_name
k8s_attribute_service.create_k8s_attribute(self.tenant, self.service, self.region_name, attribute)
# attribute['operator'] = self.user.nick_name
k8s_attribute_service.create_k8s_attribute(self.tenant, self.service, self.region_name, attribute, self.user.nick_name)
return Response(general_message(200, "success", "创建成功"))
41 changes: 31 additions & 10 deletions console/views/logos.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,53 @@
class ConfigOSSView(JWTTokenView):

def get(self, request, *args, **kwargs):
oss_config = ConsoleSysConfig.objects.filter(key='OSS_CONFIG').first()
if oss_config:
data = json.loads(oss_config.value)
return Response(data=data, status=200)
return Response(data={}, status=200)
oss_config = ConsoleSysConfig.objects.get(key='OSS_CONFIG')
if not oss_config:
result = general_message(200, "query success", "success")
return Response(data=result, status=200)
oss_config = oss_config.to_dict()
value = oss_config.get("value")

if oss_config.get("value"):
value = json.loads(oss_config.get("value"))
data = dict()
data["key"] = oss_config['key']
data["type"] = oss_config['type']
data["value"] = value
data["enable"] = oss_config["enable"]
data["desc"] = oss_config["desc"]
result = general_message(200, "query success", "success", bean=data)
return Response(data=result, status=200)

def put(self, request, *args, **kwargs):
data = dict()
data["OSS_ACCESS_KEY"] = request.data.get("OSS_ACCESS_KEY")
data["OSS_ACCESS_KEY_SECRET"] = request.data.get("OSS_ACCESS_KEY_SECRET")
data["OSS_ENDPOINT"] = request.data.get("OSS_ENDPOINT")
data["OSS_BUCKET"] = request.data.get("OSS_BUCKET")
data = json.dumps(data)
oss_config = ConsoleSysConfig.objects.filter(key='OSS_CONFIG').first()

# 如果已存在,则更新;如果不存在,则创建
if oss_config:
oss_config.value = json.dumps(request.data)
if request.data.get("enable"):
oss_config.value = data
oss_config.desc = 'OSS 配置'
oss_config.enable = request.data.get("enable")
oss_config.create_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
oss_config.save()
data = {'message': '配置更新成功'}
data = {'code': 200,'message': '配置更新成功'}
else:
print(request.data.get("enable"))
new_config = ConsoleSysConfig.objects.create(
key='OSS_CONFIG',
type='json',
value=json.dumps(request.data),
value=data,
enable=request.data.get("enable"),
desc='OSS 配置',
create_time=datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
enterprise_id=""
)
data = {'message': '配置创建成功', 'config_id': new_config.ID}
data = {'code': 200, 'message': '配置创建成功', 'config_id': new_config.ID}

return Response(data=data, status=200)

Expand Down

0 comments on commit 5b4c1a5

Please sign in to comment.