def get_workspace(workspace_id): """ワークスペース詳細 Args: workspace_id (int): ワークスペースID Returns: response: HTTP Respose """ globals.logger.debug('CALL get_workspace:{}'.format(workspace_id)) try: with dbconnector() as db, dbcursor(db) as cursor: # workspace情報データ取得 fetch_rows = da_workspace.select_workspace_id(cursor, workspace_id) if len(fetch_rows) > 0: # Response用のjsonに変換 response_rows = convert_workspace_response(fetch_rows) return jsonify({ "result": "200", "rows": response_rows, "time": str(datetime.now(globals.TZ)) }), 200 else: # 0件のときは404応答 return jsonify({"result": "404"}), 404 except Exception as e: return common.serverError(e)
def update_manifestParameter(workspace_id): """ワークスペース変更 Args: workspace_id (int): ワークスペースID Returns: response: HTTP Respose """ globals.logger.debug( "CALL update_manifestParameter:{}".format(workspace_id)) try: request_json = request.json.copy() update_at = request_json["update_at"] update_at = parser.parse(update_at) # Requestからspecification項目を生成する specification = request_json with dbconnector() as db, dbcursor(db) as cursor: # workspace情報取得 workspaceInfo = da_workspace.select_workspace_id( cursor, workspace_id) # workspace情報のmanifestParameter部を差し替え db_specification = json.loads(workspaceInfo[0]["specification"]) # 登録する配列用のindex i = 0 for db_env in db_specification["ci_config"]["environments"]: for in_env in specification["ci_config"]["environments"]: if db_env["environment_id"] == in_env["environment_id"]: db_specification["ci_config"]["environments"][i][ "manifests"] = in_env["manifests"] break i += 1 # manifestパラメータの項目説明も更新に含める db_specification["parameter-info"] = specification[ "parameter-info"] # workspace情報 update実行 upd_cnt = da_workspace.update_workspace(cursor, db_specification, workspace_id, update_at) if upd_cnt == 0: # データがないときは404応答 db.rollback() return jsonify({"result": "404"}), 404 # Response用のjsonに変換 response_rows = workspaceInfo return jsonify({"result": "200", "rows": response_rows}) except Exception as e: return common.serverError(e)
def put_workspace(workspace_id): """ワークスペース更新 Args: workspace_id (int): ワークスペースID Returns: response: HTTP Respose """ globals.logger.debug("CALL put_workspace:{}".format(workspace_id)) app_name = "ワークスペース情報更新:" exec_stat = "初期化" exec_detail = "" try: request_json = request.json.copy() update_at = request_json["update_at"] update_at = parser.parse(update_at) globals.logger.debug(f"update_at:{update_at}") # Requestからspecification項目を生成する specification = convert_workspace_specification(request_json) exec_stat = "DB接続" with dbconnector() as db, dbcursor(db) as cursor: # workspace情報 update実行 exec_stat = "更新実行" upd_cnt = da_workspace.update_workspace(cursor, specification, workspace_id, update_at) if upd_cnt == 0: # データがないときは404応答 db.rollback() return jsonify({ "result": "404", "errorStatement": app_name + exec_stat, "errorDetail": "更新するデータがありません" }), 404 # workspace履歴追加 exec_stat = "登録実行(履歴)" da_workspace.insert_history(cursor, workspace_id) # workspace情報の再取得 exec_stat = "登録データ確認" fetch_rows = da_workspace.select_workspace_id(cursor, workspace_id) # Response用のjsonに変換 response_rows = fetch_rows return jsonify({"result": "200", "rows": response_rows}) except Exception as e: return common.serverError(e, app_name + exec_stat, exec_detail)
def create_workspace(): """ワークスペース生成 Returns: response: HTTP Respose """ globals.logger.debug('CALL create_workspace') app_name = "ワークスペース情報登録:" exec_stat = "初期化" exec_detail = "" globals.logger.debug(request.json) try: # Requestからorganization_id項目を抽出する organization_id = request.json['common']['organization_id'] # Requestからspecification項目を生成する specification = convert_workspace_specification(request.json) exec_stat = "DB接続" with dbconnector() as db, dbcursor(db) as cursor: # workspace情報 insert実行(戻り値:追加したワークスペースID) exec_stat = "登録実行" workspace_id = da_workspace.insert_workspace( cursor, organization_id, specification) globals.logger.debug('insert workspaced_id:{}'.format( str(workspace_id))) # workspace履歴追加 exec_stat = "登録実行(履歴)" da_workspace.insert_history(cursor, workspace_id) # workspace情報 データ再取得 exec_stat = "登録データ確認" fetch_rows = da_workspace.select_workspace_id(cursor, workspace_id) # Response用のjsonに変換 response_rows = fetch_rows globals.logger.info('CREATED workspace:{} , organization:{}'.format( str(workspace_id), str(organization_id))) return jsonify({"result": "200", "rows": response_rows}) except Exception as e: return common.serverError(e, app_name + exec_stat, exec_detail)
def patch_workspace(workspace_id): """ワークスペース更新パッチ patch update workspace Args: workspace_id (int): ワークスペースID Returns: response: HTTP Respose """ globals.logger.debug("CALL patch_workspace:{}".format(workspace_id)) app_name = "ワークスペース更新パッチ:" exec_stat = "更新" exec_detail = "" # 更新対象のカラム(specification以外) # { # "parameter-info": {}, # "workspace_id": 1, # "create_at": "Thu, 25 Nov 2021 04:22:31 GMT", # "update_at": "Thu, 25 Nov 2021 04:22:31 GMT", # "role_update_at": "Thu, 25 Nov 2021 04:22:31 GMT" # } try: # 更新対象の項目をセット request_json = request.json.copy() exec_stat = "DB接続" with dbconnector() as db, dbcursor(db) as cursor: # workspace情報 update実行 exec_stat = "更新実行" upd_cnt = da_workspace.patch_workspace(cursor, workspace_id, request_json) globals.logger.debug( 'workspace update complete update_count:{}'.format(upd_cnt)) if upd_cnt == 0: # データがないときは404応答 db.rollback() return jsonify({ "result": "404", "errorStatement": app_name + exec_stat, "errorDetail": "更新するデータがありません" }), 404 # workspace履歴追加 exec_stat = "登録実行(履歴)" da_workspace.insert_history(cursor, workspace_id) globals.logger.debug('workspace history add complete') # workspace情報の再取得 exec_stat = "登録データ確認" fetch_rows = da_workspace.select_workspace_id(cursor, workspace_id) globals.logger.debug('workspace get complete') # Response用のjsonに変換 response_rows = fetch_rows return jsonify({"result": "200", "rows": response_rows}), 200 except Exception as e: return common.serverError(e, app_name + exec_stat, exec_detail)