diff --git a/backend/app/controllers/app.py b/backend/app/controllers/app.py index 8c5cc625..cc8e133a 100644 --- a/backend/app/controllers/app.py +++ b/backend/app/controllers/app.py @@ -21,15 +21,18 @@ def add(): default_target_branch = request.json.get('app_default_target_branch') description = request.json.get('app_description') services = request.json.get('service') + cd_config = request.json.get('app_cd_config') + ci_config = request.json.get('app_ci_config') + git_config = request.json.get('app_git_config') creater = session['username'] try: if app_id: - app = Application.update_application(app_id, name=name, description=description, default_source_branch=default_source_branch, default_target_branch=default_target_branch) + app = Application.update_application(app_id, name=name, description=description, default_source_branch=default_source_branch, default_target_branch=default_target_branch, cd_config=cd_config, ci_config=ci_config, git_config=git_config) ApplicationService.delete_service_by_app_id(app_id) appID = app_id else: - app = Application.create(tenant_id, creater, name, description, default_source_branch, default_target_branch) + app = Application.create(tenant_id, creater, name, description, default_source_branch, default_target_branch, git_config, ci_config, cd_config) appID = app.app_id for service in services: diff --git a/backend/app/controllers/setting.py b/backend/app/controllers/setting.py index 3bfc3898..600126d4 100644 --- a/backend/app/controllers/setting.py +++ b/backend/app/controllers/setting.py @@ -3,6 +3,9 @@ from flask import Blueprint from app.pkgs.tools.i18b import getI18n from app.models.setting import getGitConfigList, getCIConfigList, getCDConfigList, getLLMConfigList +from app.models.tenant_git_config_pro import TenantGitConfig +from app.models.tenant_cd_config_pro import TenantCDConfig +from app.models.tenant_ci_config_pro import TenantCIConfig bp = Blueprint('setting', __name__, url_prefix='/setting') @@ -46,10 +49,85 @@ def get_cd_config_list(): @json_response def get_llm_config_list(): _ = getI18n("controllers") + raise Exception(_("Failed to get git config list.")) tenantID = session['tenant_id'] gitList, success = getLLMConfigList(tenantID, 0) if not success: raise Exception(_("Failed to get git config list.")) - return gitList \ No newline at end of file + return gitList + +@bp.route('/edit_git', methods=['POST']) +@json_response +def edit_git(): + _ = getI18n("controllers") + git_email = request.json.get('git_email') + git_provider = request.json.get('git_provider') + git_token = request.json.get('git_token') + git_url = request.json.get('git_url') + git_username = request.json.get('git_username') + git_config_id = request.json.get('git_config_id') + name = request.json.get('git_name') + creater = session['username'] + tenant_id = session['tenant_id'] + + try: + if git_config_id: + TenantGitConfig.update_config(git_config_id, name=name, git_email=git_email, git_provider=git_provider, git_token=git_token, git_url=git_url, git_username=git_username) + id = git_config_id + else: + data = TenantGitConfig.create_config(tenant_id, creater, name, git_url, git_token, git_provider, git_username, git_email) + id = data.git_config_id + + return {'success': id} + except Exception as e: + raise Exception(_("Failed to edit setting.")) + +@bp.route('/edit_ci', methods=['POST']) +@json_response +def edit_ci(): + _ = getI18n("controllers") + ci_api_url = request.json.get('ci_api_url') + ci_token = request.json.get('ci_token') + ci_provider = request.json.get('ci_provider') + ci_config_id = request.json.get('ci_config_id') + name = request.json.get('ci_name') + creater = session['username'] + tenant_id = session['tenant_id'] + + try: + if ci_config_id: + TenantCIConfig.update_config(ci_config_id, name=name, ci_api_url=ci_api_url, ci_token=ci_token, ci_provider=ci_provider) + id = ci_config_id + else: + data = TenantCIConfig.create_config(tenant_id, creater, name, ci_api_url, ci_token, ci_provider) + id = data.ci_config_id + + return {'success': id} + except Exception as e: + raise Exception(_("Failed to edit setting.")) + +@bp.route('/edit_cd', methods=['POST']) +@json_response +def edit_cd(): + _ = getI18n("controllers") + cd_config_id = request.json.get('cd_config_id') + access_key = request.json.get('ACCESS_KEY') + secret_key = request.json.get('SECRET_KEY') + cd_provider = request.json.get('cd_provider') + name = request.json.get('cd_name') + creater = session['username'] + tenant_id = session['tenant_id'] + + try: + if cd_config_id: + TenantCDConfig.update_config(cd_config_id, name=name, access_key=access_key, secret_key=secret_key, cd_provider=cd_provider) + id = cd_config_id + else: + data = TenantCDConfig.create_config(tenant_id, creater, name, access_key, secret_key, cd_provider) + id = data.cd_config_id + + return {'success': id} + except Exception as e: + raise Exception(_("Failed to edit setting.")) \ No newline at end of file diff --git a/backend/app/models/application.py b/backend/app/models/application.py index 7e98e88e..3dac8a4e 100644 --- a/backend/app/models/application.py +++ b/backend/app/models/application.py @@ -4,13 +4,16 @@ class Application(db.Model): app_id = db.Column(db.Integer, primary_key=True) tenant_id = db.Column(db.Integer, nullable=False) + git_config = db.Column(db.Integer, nullable=False) + ci_config = db.Column(db.Integer, nullable=False) + cd_config = db.Column(db.Integer, nullable=False) creater = db.Column(db.String(255), nullable=False) name = db.Column(db.String(255), nullable=False) description = db.Column(db.Text) default_source_branch = db.Column(db.String(255)) default_target_branch = db.Column(db.String(255)) - def create(tenant_id, creater, name, description, default_source_branch, default_target_branch): + def create(tenant_id, creater, name, description, default_source_branch, default_target_branch, git_config, ci_config, cd_config): if not tenant_id: tenant_id = 0 @@ -18,6 +21,9 @@ def create(tenant_id, creater, name, description, default_source_branch, default tenant_id=tenant_id, creater=creater, name=name, + git_config=git_config, + ci_config=ci_config, + cd_config=cd_config, description=description, default_source_branch=default_source_branch, default_target_branch=default_target_branch @@ -40,6 +46,9 @@ def get_all_application(owner, appID): 'tenant_id': app.tenant_id, 'creater': app.creater, 'name': app.name, + 'git_config': app.git_config, + 'ci_config': app.ci_config, + 'cd_config': app.cd_config, 'description': app.description, 'default_source_branch': app.default_source_branch, 'default_target_branch': app.default_target_branch, @@ -56,6 +65,9 @@ def get_application_by_id(appID): 'tenant_id': app.tenant_id, 'creater': app.creater, 'name': app.name, + 'git_config': app.git_config, + 'ci_config': app.ci_config, + 'cd_config': app.cd_config, 'description': app.description, 'default_source_branch': app.default_source_branch, 'default_target_branch': app.default_target_branch, diff --git a/backend/app/models/application_service.py b/backend/app/models/application_service.py index fad05598..cdaee73a 100644 --- a/backend/app/models/application_service.py +++ b/backend/app/models/application_service.py @@ -27,6 +27,8 @@ class ApplicationService(db.Model): STATUS_DELETE = "DELETED" STATUS_OK = "OK" + LANGUAGE_JAVA = "Java" + def create_service(app_id, name, git_path, git_workflow, role, language, framework, database, api_type, api_location, cd_container_name, cd_container_group, cd_region, cd_public_ip, cd_security_group, cd_subnet, struct_cache): service = ApplicationService( diff --git a/backend/app/models/setting_basic.py b/backend/app/models/setting_basic.py index 31a2335a..266ae3f9 100644 --- a/backend/app/models/setting_basic.py +++ b/backend/app/models/setting_basic.py @@ -5,6 +5,7 @@ class SettingBasic(SettingInterface): def getGitConfigList(self, tenantID, appID): gitList = [] gitList.append({ + "name" : "Default(from env.yaml)", "git_provider" : DEVOPS_TOOLS, "git_url" : GIT_URL, "git_token" : GIT_TOKEN, @@ -18,6 +19,7 @@ def getGitConfigList(self, tenantID, appID): def getCIConfigList(self, tenantID, appID): gitList = [] gitList.append({ + "name" : "Default(from env.yaml)", "ci_provider" : DEVOPS_TOOLS, "ci_config_id" : 0, "ci_api_url" : GIT_API, @@ -30,6 +32,7 @@ def getCIConfigList(self, tenantID, appID): def getCDConfigList(self, tenantID, appID): gitList = [] gitList.append({ + "name" : "Default(from env.yaml)", "cd_provider" : CD_TOOLS, "ACCESS_KEY" : CD_ACCESS_KEY, "SECRET_KEY" : CD_SECRET_KEY, diff --git a/backend/app/models/tenant_cd_config_pro.py b/backend/app/models/tenant_cd_config_pro.py new file mode 100644 index 00000000..6ffb0b5f --- /dev/null +++ b/backend/app/models/tenant_cd_config_pro.py @@ -0,0 +1,3 @@ +class TenantCDConfig(): + def test(): + pass \ No newline at end of file diff --git a/backend/app/models/tenant_ci_config_pro.py b/backend/app/models/tenant_ci_config_pro.py new file mode 100644 index 00000000..a39bbaa2 --- /dev/null +++ b/backend/app/models/tenant_ci_config_pro.py @@ -0,0 +1,3 @@ +class TenantCIConfig(): + def test(): + pass \ No newline at end of file diff --git a/backend/app/models/tenant_git_config_pro.py b/backend/app/models/tenant_git_config_pro.py new file mode 100644 index 00000000..2e1a1d3b --- /dev/null +++ b/backend/app/models/tenant_git_config_pro.py @@ -0,0 +1,3 @@ +class TenantGitConfig(): + def test(): + pass \ No newline at end of file diff --git a/backend/app/pkgs/devops/devops.py b/backend/app/pkgs/devops/devops.py index 5f38f34b..add97bb1 100644 --- a/backend/app/pkgs/devops/devops.py +++ b/backend/app/pkgs/devops/devops.py @@ -9,9 +9,9 @@ def triggerPipeline(requirementID, branchName, serviceInfo, ciConfig): if DEVOPS_TOOLS == 'local': obj = DevopsLocal() - elif DEVOPS_TOOLS == 'gitlab': + elif DEVOPS_TOOLS == 'gitlab' or DEVOPS_TOOLS == 'GitLab': obj = DevopsGitlab() - elif DEVOPS_TOOLS == 'github': + elif DEVOPS_TOOLS == 'github' or DEVOPS_TOOLS == 'GitHub': obj = DevopsGitHub() result, piplineID, piplineUrl, success = obj.triggerPipeline(branchName, serviceInfo, ciConfig) @@ -26,9 +26,9 @@ def getPipelineStatus(piplineId, repoPath, ciConfig): if DEVOPS_TOOLS == 'local': obj = DevopsLocal() - elif DEVOPS_TOOLS == 'gitlab': + elif DEVOPS_TOOLS == 'gitlab' or DEVOPS_TOOLS == 'GitLab': obj = DevopsGitlab() - elif DEVOPS_TOOLS == 'github': + elif DEVOPS_TOOLS == 'github' or DEVOPS_TOOLS == 'GitHub': obj = DevopsGitHub() return obj.getPipelineStatus(piplineId, repoPath, ciConfig) @@ -38,9 +38,9 @@ def getPipelineJobLogs(repopath, pipeline_id, job_id, ciConfig): if DEVOPS_TOOLS == 'local': obj = DevopsLocal() - elif DEVOPS_TOOLS == 'gitlab': + elif DEVOPS_TOOLS == 'gitlab' or DEVOPS_TOOLS == 'GitLab': obj = DevopsGitlab() - elif DEVOPS_TOOLS == 'github': + elif DEVOPS_TOOLS == 'github' or DEVOPS_TOOLS == 'GitHub': obj = DevopsGitHub() return obj.getPipelineJobLogs(obj, repopath, pipeline_id, job_id, ciConfig) \ No newline at end of file diff --git a/backend/app/pkgs/devops/devops_github.py b/backend/app/pkgs/devops/devops_github.py index 4e977b12..26ab0bdd 100644 --- a/backend/app/pkgs/devops/devops_github.py +++ b/backend/app/pkgs/devops/devops_github.py @@ -6,7 +6,8 @@ class DevopsGitHub(DevopsInterface): def triggerPipeline(self, branch_name, serviceInfo, ciConfig): - gitURL = ciConfig["git_url"] + print(ciConfig) + ciURL = ciConfig["ci_api_url"] ciToken = ciConfig["ci_token"] repopath = serviceInfo["git_path"] @@ -39,7 +40,7 @@ def triggerPipeline(self, branch_name, serviceInfo, ciConfig): run_id = run["id"] break - return "Get pipline status...", run_id, f"{gitURL}/{repopath}/actions/runs/{run_id}", True + return "Get pipline status...", run_id, f"{repopath}/actions/runs/{run_id}", True else: return f"Failed to trigger pipeline giturl:{ciURL} repopath:{repopath} branch:{branch_name} gitWorkflow:{gitWorkflow}, Error: {str(e)}", 0, "", False except Exception as e: diff --git a/backend/app/pkgs/tools/i18b.py b/backend/app/pkgs/tools/i18b.py index c1fbf2d4..2aa9c600 100644 --- a/backend/app/pkgs/tools/i18b.py +++ b/backend/app/pkgs/tools/i18b.py @@ -150,4 +150,20 @@ def getFrontendText(): "bill_date": _("Billing date"), "remarks": _("Remarks"), "operate": _("Operate"), + "git_provider": _("Git provider"), + "git_url": _("Git URL"), + "git_token": _("Git token"), + "git_username": _("Git username"), + "git_email": _("Git email"), + "ci_token": _("CI Token"), + "ci_api_url": _("CI API URL"), + "ci_provider": _("CI provider"), + "cd_provider": _("CD provider"), + "ACCESS_KEY": _("ACCESS_KEY"), + "SECRET_KEY": _("SECRET_KEY"), + "configuration": _("Configuration"), + "config_name": _("Config name"), + "app_cd_config": _("Associated CD Config"), + "app_ci_config": _("Associated CI Config"), + "app_git_config": _("Associated Git Config"), } \ No newline at end of file diff --git a/db/database.db b/db/database.db index c230c221..39991dee 100644 Binary files a/db/database.db and b/db/database.db differ diff --git a/frontend/app.html b/frontend/app.html index a6d52cb9..a9626a21 100644 --- a/frontend/app.html +++ b/frontend/app.html @@ -17,6 +17,7 @@ +
@@ -29,7 +30,6 @@ - +