@next-core/brick-container 3.13.6 → 3.13.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,151 @@
1
+ # -*- coding: utf-8 -*-
2
+ import json as simplejson
3
+ import sys
4
+ import os
5
+ import ens_api
6
+ import requests
7
+ import simplejson
8
+
9
+ reload(sys)
10
+ sys.setdefaultencoding("utf-8")
11
+
12
+ class NameServiceError(Exception):
13
+ pass
14
+
15
+
16
+ def join_host_port(host, port):
17
+ template = "%s:%s"
18
+ host_requires_bracketing = ':' in host or '%' in host
19
+ if host_requires_bracketing:
20
+ template = "[%s]:%s"
21
+ return template % (host, port)
22
+
23
+
24
+ session_id, ip, port = ens_api.get_service_by_name("", "logic.micro_app_service")
25
+ if session_id <= 0:
26
+ raise Exception("get name service logic.micro_app_service failed, no session_id")
27
+ MICRO_APP_ADDR = join_host_port(ip, port)
28
+
29
+ session_id, ip, port = ens_api.get_service_by_name("", "logic.micro_app_standalone_service")
30
+ if session_id <= 0:
31
+ raise NameServiceError("get nameservice logic.micro_app_standalone error, session_id={}".format(session_id))
32
+ MICRO_APP_SA_ADDR = join_host_port(ip, port)
33
+
34
+
35
+ def get_version(install_path):
36
+ # 开发环境没有version.ini文件,直接返回0.0.0
37
+ if not os.path.exists(os.path.join(install_path, "version.ini")):
38
+ return "0.0.0"
39
+ with open(os.path.join(install_path, "version.ini")) as f:
40
+ lines = f.readlines()
41
+ return lines[-1].strip()
42
+
43
+
44
+ def collect_app_info(app_path, report_app_id, version):
45
+ if not os.path.exists(app_path):
46
+ print u"could not find app path {}".format(app_path)
47
+ return
48
+ bootstrap_file_name = ""
49
+ for f in os.listdir(app_path):
50
+ if f.startswith("bootstrap-mini.") and f.endswith(".json"):
51
+ bootstrap_file_name = f
52
+ if bootstrap_file_name is "":
53
+ print u"bootstrap-mini.*.json not found in dir {}".format(app_path)
54
+ return
55
+ bootstrap_file = os.path.join(app_path, bootstrap_file_name)
56
+ print u"report app: {}, bootstrap_file: {}".format(report_app_id, bootstrap_file)
57
+ with open(bootstrap_file) as f:
58
+ bootstrap_content = f.read()
59
+ bootstrap_content_json = simplejson.loads(bootstrap_content)
60
+ # 跳过没有app字段的storyboard
61
+ if not bootstrap_content_json.get("storyboards"):
62
+ return None
63
+ storyboards = bootstrap_content_json.get("storyboards")
64
+ for story_board in storyboards:
65
+ if story_board["app"]["id"] == report_app_id:
66
+ app = {
67
+ "appId": story_board["app"]["id"],
68
+ "name": story_board["app"]["name"],
69
+ "internal": "true" if story_board["app"].get("internal") else "false",
70
+ "version": version,
71
+ "homepage": story_board["app"]["homepage"],
72
+ "status": "enabled", # 新安装状态默认是enabled的
73
+ "setActiveVersion": True,
74
+ "meta": simplejson.dumps(story_board["meta"], ensure_ascii=False),
75
+ "defaultConfig": story_board["app"].get("defaultConfig"),
76
+ "defaultContainer": story_board["app"].get("defaultContainer"),
77
+ "icons": story_board["app"].get("icons", {}),
78
+ "menuIcon": story_board["app"].get("menuIcon", {}),
79
+ "locales": story_board["app"].get("locales", {}),
80
+ "description": story_board["app"].get("description"),
81
+ "author": story_board["app"].get("author"),
82
+ "isFromUnionApp": True,
83
+ }
84
+ return app
85
+
86
+
87
+ def report(org, app):
88
+ try:
89
+ create_or_update_micro_app_sa(org, app)
90
+ except NameServiceError, e:
91
+ raise e
92
+ except requests.HTTPError, e:
93
+ raise e
94
+
95
+
96
+ def create_or_update_micro_app_sa(org, app):
97
+ headers = {"org": str(org), "user": "defaultUser"}
98
+ url = "http://{}/api/v1/micro_app_standalone/report".format(MICRO_APP_SA_ADDR)
99
+ rsp = requests.post(url, json=app, headers=headers)
100
+ rsp.raise_for_status()
101
+ print "report app end"
102
+
103
+
104
+ def import_micro_app_permissions(org, permission_path):
105
+ if not os.path.exists(permission_path):
106
+ print "could not find permission path {}, will not import permissions".format(permission_path)
107
+ return
108
+ headers = {"org": str(org), "user": "defaultUser"}
109
+ url = "http://{}/api/micro_app/v1/permission/import".format(MICRO_APP_ADDR)
110
+
111
+ print "permission path is {}, will start import permissions".format(permission_path)
112
+ with open(permission_path) as f:
113
+ p_f_content = f.read()
114
+ permission_list = simplejson.loads(p_f_content)
115
+ body = {"permissionList": permission_list}
116
+ rsp = requests.post(url, json=body, headers=headers)
117
+ rsp.raise_for_status()
118
+
119
+ def read_union_apps_file(install_app_path):
120
+ union_app_file = os.path.join(install_app_path, "union-apps", "union-apps.json")
121
+ if not os.path.exists(union_app_file):
122
+ return []
123
+ with open(union_app_file, "r") as f:
124
+ return simplejson.load(f)
125
+
126
+
127
+ def report_union_apps(org, install_app_path):
128
+ union_apps = read_union_apps_file(install_path)
129
+ for app in union_apps:
130
+ app_id = app["app_id"]
131
+ version = app["version"]
132
+ if app["use_brick_next_v3"]:
133
+ subdir_snippet = "v3"
134
+ else:
135
+ subdir_snippet = "v2"
136
+ union_app_path = os.path.join(install_app_path, "micro-apps", subdir_snippet, app_id, version)
137
+ print u"report app: {}, current app path: {}".format(app_id, union_app_path)
138
+ app = collect_app_info(union_app_path, app_id, version)
139
+ if app:
140
+ report(org, app)
141
+ permission_file_path = os.path.join(union_app_path, "permissions", "permissions.json")
142
+ import_micro_app_permissions(org, permission_file_path)
143
+
144
+
145
+ if __name__ == "__main__":
146
+ if len(sys.argv) != 3:
147
+ print "Usage: ./report_union_micro_app.py $org $install_path"
148
+ sys.exit(1)
149
+ org = sys.argv[1]
150
+ install_path = sys.argv[2]
151
+ report_union_apps(org, install_path)
@@ -30,7 +30,7 @@ def join_host_port(host, port):
30
30
  session_id, ip, port = ens_api.get_service_by_name("", "logic.micro_app_service")
31
31
  if session_id <= 0:
32
32
  raise Exception("get name service logic.micro_app_service failed, no session_id")
33
- MICRO_APP_ADDR = join_host_port("127.0.0.1", port)
33
+ MICRO_APP_ADDR = join_host_port(ip, port)
34
34
 
35
35
 
36
36
  def get_snippets_from_stories(stories_content):
@@ -373,7 +373,7 @@ if __name__ == "__main__":
373
373
  if install_path.endswith(os.sep):
374
374
  install_path = install_path[:-1]
375
375
 
376
- if install_path.endswith(("brick_next_v3", "brick_next")):
376
+ if install_path.endswith("brick_next"):
377
377
  report_brick_next(org, install_path)
378
378
  elif install_path.endswith("-NB"):
379
379
  report_nb(org, install_path)
@@ -22,12 +22,12 @@ def join_host_port(host, port):
22
22
  session_id, ip, port = ens_api.get_service_by_name("", "logic.micro_app_service")
23
23
  if session_id <= 0:
24
24
  raise Exception("get name service logic.micro_app_service failed, no session_id")
25
- MICRO_APP_ADDR = join_host_port("127.0.0.1", port)
25
+ MICRO_APP_ADDR = join_host_port(ip, port)
26
26
 
27
27
  session_id, ip, port = ens_api.get_service_by_name("", "logic.micro_app_standalone_service")
28
28
  if session_id <= 0:
29
29
  raise NameServiceError("get nameservice logic.micro_app_standalone error, session_id={}".format(session_id))
30
- MICRO_APP_SA_ADDR = join_host_port("127.0.0.1", port)
30
+ MICRO_APP_SA_ADDR = join_host_port(ip, port)
31
31
 
32
32
  def get_version(install_path):
33
33
  # 开发环境没有version.ini文件,直接返回0.0.0