├── .github ├── ISSUE_TEMPLATE │ ├── bug-report.md │ ├── enhancement.md │ └── installation-feedback.yaml ├── PULL_REQUEST_TEMPLATE.md └── workflows │ ├── image.yml │ ├── stale.yml │ └── unit-test.yml ├── .gitignore ├── .golangci.yml ├── .nocalhost ├── config.yaml ├── debug.sh └── run.sh ├── .pre-commit-config.yaml ├── CODE-OF-CONDUCT.md ├── CONTRIBUTING.md ├── DEVELOPMENT.md ├── Horizon.svg ├── LICENSE ├── Makefile ├── README.md ├── README_ZH-CN.md ├── build-json-schema.json ├── build-ui-schema.json ├── build ├── build.sh ├── core │ └── Dockerfile └── swagger │ ├── Dockerfile │ └── build.sh ├── config.yaml ├── core ├── cmd │ ├── cloudevent.go │ └── cmd.go ├── common │ ├── application.go │ ├── cluster.go │ ├── common.go │ ├── const.go │ ├── gitops.go │ ├── group.go │ ├── idp │ │ └── const.go │ ├── jwt.go │ ├── pipelinerun.go │ ├── rbac.go │ ├── routes.go │ ├── template.go │ ├── user.go │ └── utils.go ├── config │ └── config.go ├── controller │ ├── access │ │ ├── controller.go │ │ ├── controller_test.go │ │ └── models.go │ ├── accesstoken │ │ ├── controller.go │ │ ├── controller_test.go │ │ └── models.go │ ├── application │ │ ├── controller.go │ │ ├── controller_test.go │ │ ├── models.go │ │ └── v2models.go │ ├── applicationregion │ │ ├── controller.go │ │ ├── controller_test.go │ │ └── models.go │ ├── badge │ │ ├── controller.go │ │ ├── controller_test.go │ │ └── model.go │ ├── build │ │ ├── controller.go │ │ └── models.go │ ├── cloudevent │ │ ├── controller.go │ │ ├── controller_test.go │ │ ├── models.go │ │ └── models_test.go │ ├── cluster │ │ ├── controller.go │ │ ├── controller_basic.go │ │ ├── controller_basic_test.go │ │ ├── controller_basic_v2.go │ │ ├── controller_basic_v2_test.go │ │ ├── controller_build_deploy.go │ │ ├── controller_build_deploy_test.go │ │ ├── controller_internal.go │ │ ├── controller_internal_v2.go │ │ ├── controller_operation.go │ │ ├── controller_status.go │ │ ├── controller_status_test.go │ │ ├── controller_test.go │ │ ├── models_basic.go │ │ ├── models_basic_v2.go │ │ ├── models_basic_v2_test.go │ │ ├── models_build_deploy.go │ │ ├── models_internal.go │ │ ├── models_internal_v2.go │ │ ├── models_operation.go │ │ └── models_status.go │ ├── code │ │ ├── controller.go │ │ └── models.go │ ├── environment │ │ ├── controller.go │ │ ├── controller_test.go │ │ └── models.go │ ├── environmentregion │ │ ├── controller.go │ │ ├── controller_test.go │ │ └── models.go │ ├── envtemplate │ │ ├── controller.go │ │ ├── controller_test.go │ │ └── models.go │ ├── event │ │ └── controller.go │ ├── group │ │ ├── controller.go │ │ ├── controller_test.go │ │ ├── convert.go │ │ └── models.go │ ├── horizonapp │ │ └── controller.go │ ├── idp │ │ ├── controller.go │ │ └── models.go │ ├── member │ │ ├── controller.go │ │ ├── controller_test.go │ │ └── models.go │ ├── oauth │ │ └── controller.go │ ├── oauthapp │ │ └── controller.go │ ├── oauthcheck │ │ └── controller.go │ ├── pipelinerun │ │ ├── controller.go │ │ ├── controller_test.go │ │ └── models.go │ ├── region │ │ ├── controller.go │ │ └── models.go │ ├── registry │ │ ├── controller.go │ │ └── models.go │ ├── role │ │ └── controller.go │ ├── scope │ │ ├── controller.go │ │ └── models.go │ ├── tag │ │ ├── controller.go │ │ ├── controller_test.go │ │ └── models.go │ ├── template │ │ ├── controller.go │ │ ├── controller_test.go │ │ └── models.go │ ├── templateschematag │ │ ├── controller.go │ │ ├── controller_test.go │ │ └── models.go │ ├── terminal │ │ ├── controller.go │ │ ├── models.go │ │ └── terminal.go │ ├── user │ │ ├── controller.go │ │ ├── controller_test.go │ │ └── models.go │ └── webhook │ │ ├── controller.go │ │ ├── controller_test.go │ │ └── models.go ├── errors │ └── horizonerrors.go ├── http │ ├── api │ │ ├── v1 │ │ │ ├── access │ │ │ │ ├── apis.go │ │ │ │ └── routers.go │ │ │ ├── accesstoken │ │ │ │ ├── apis.go │ │ │ │ └── routers.go │ │ │ ├── application │ │ │ │ ├── apis.go │ │ │ │ └── routers.go │ │ │ ├── applicationregion │ │ │ │ ├── apis.go │ │ │ │ └── routers.go │ │ │ ├── cluster │ │ │ │ ├── apis_basic.go │ │ │ │ ├── apis_operation.go │ │ │ │ └── routers.go │ │ │ ├── code │ │ │ │ ├── apis.go │ │ │ │ └── routers.go │ │ │ ├── environment │ │ │ │ ├── apis.go │ │ │ │ └── routers.go │ │ │ ├── environmentregion │ │ │ │ ├── apis.go │ │ │ │ └── routers.go │ │ │ ├── envtemplate │ │ │ │ ├── apis.go │ │ │ │ └── routers.go │ │ │ ├── event │ │ │ │ ├── apis.go │ │ │ │ └── routers.go │ │ │ ├── group │ │ │ │ ├── apis.go │ │ │ │ └── routers.go │ │ │ ├── idp │ │ │ │ ├── apis.go │ │ │ │ └── routers.go │ │ │ ├── member │ │ │ │ ├── apis.go │ │ │ │ └── routers.go │ │ │ ├── oauthapp │ │ │ │ ├── apis.go │ │ │ │ └── routes.go │ │ │ ├── oauthserver │ │ │ │ ├── apis.go │ │ │ │ ├── auth.html │ │ │ │ └── routes.go │ │ │ ├── pipelinerun │ │ │ │ ├── apis.go │ │ │ │ └── routers.go │ │ │ ├── region │ │ │ │ ├── apis.go │ │ │ │ └── routers.go │ │ │ ├── registry │ │ │ │ ├── apis.go │ │ │ │ └── routers.go │ │ │ ├── role │ │ │ │ ├── apis.go │ │ │ │ └── routers.go │ │ │ ├── scope │ │ │ │ ├── apis.go │ │ │ │ └── routers.go │ │ │ ├── tag │ │ │ │ ├── apis.go │ │ │ │ └── routers.go │ │ │ ├── template │ │ │ │ ├── apis.go │ │ │ │ └── routers.go │ │ │ ├── templateschematag │ │ │ │ ├── apis.go │ │ │ │ └── routes.go │ │ │ ├── terminal │ │ │ │ ├── apis.go │ │ │ │ └── routers.go │ │ │ ├── user │ │ │ │ ├── apis.go │ │ │ │ └── routers.go │ │ │ └── webhook │ │ │ │ ├── apis.go │ │ │ │ └── routers.go │ │ └── v2 │ │ │ ├── access │ │ │ ├── apis.go │ │ │ └── routers.go │ │ │ ├── accesstoken │ │ │ ├── apis.go │ │ │ └── routers.go │ │ │ ├── application │ │ │ ├── apis.go │ │ │ └── routers.go │ │ │ ├── applicationregion │ │ │ ├── apis.go │ │ │ └── routers.go │ │ │ ├── badge │ │ │ ├── apis.go │ │ │ └── routers.go │ │ │ ├── build │ │ │ ├── apis.go │ │ │ └── routers.go │ │ │ ├── cluster │ │ │ ├── apis_basic.go │ │ │ ├── apis_operation.go │ │ │ └── routers.go │ │ │ ├── code │ │ │ ├── apis.go │ │ │ └── routers.go │ │ │ ├── environment │ │ │ ├── apis.go │ │ │ └── routers.go │ │ │ ├── environmentregion │ │ │ ├── apis.go │ │ │ └── routers.go │ │ │ ├── envtemplate │ │ │ ├── apis.go │ │ │ └── routers.go │ │ │ ├── event │ │ │ ├── apis.go │ │ │ └── routers.go │ │ │ ├── group │ │ │ ├── apis.go │ │ │ └── routers.go │ │ │ ├── idp │ │ │ ├── apis.go │ │ │ └── routers.go │ │ │ ├── member │ │ │ ├── apis.go │ │ │ └── routers.go │ │ │ ├── oauthapp │ │ │ ├── apis.go │ │ │ └── routes.go │ │ │ ├── pipelinerun │ │ │ ├── apis.go │ │ │ └── routers.go │ │ │ ├── region │ │ │ ├── apis.go │ │ │ └── routers.go │ │ │ ├── registry │ │ │ ├── apis.go │ │ │ └── routers.go │ │ │ ├── role │ │ │ ├── apis.go │ │ │ └── routers.go │ │ │ ├── scope │ │ │ ├── apis.go │ │ │ └── routers.go │ │ │ ├── tag │ │ │ ├── apis.go │ │ │ └── routers.go │ │ │ ├── template │ │ │ ├── apis.go │ │ │ └── routers.go │ │ │ ├── templateschematag │ │ │ ├── apis.go │ │ │ └── routes.go │ │ │ ├── terminal │ │ │ ├── apis.go │ │ │ └── routers.go │ │ │ ├── user │ │ │ ├── apis.go │ │ │ └── routers.go │ │ │ └── webhook │ │ │ ├── apis.go │ │ │ └── routers.go │ ├── cloudevent │ │ ├── apis.go │ │ └── routers.go │ ├── health │ │ └── routers.go │ └── metrics │ │ └── routers.go ├── main.go └── middleware │ ├── admission │ └── admission.go │ ├── auth │ └── auth.go │ ├── authenticate │ └── authenticate.go │ ├── ginlog │ └── ginlog.go │ ├── log │ └── log.go │ ├── metrics │ └── metrics.go │ ├── middleware.go │ ├── prehandle │ └── prehandle.go │ ├── requestid │ └── requestid.go │ ├── scope │ └── scope.go │ ├── skipper.go │ ├── tag │ ├── tag.go │ └── tag_test.go │ ├── token │ └── token.go │ └── user │ └── user.go ├── db ├── 20210908_initial_schema.sql ├── 20211124.sql ├── 20211125.sql ├── 20220113.sql ├── 20220124.sql ├── 20220330.sql ├── 20220516.sql ├── 20220519.sql ├── 20220712.sql ├── 20220722.sql ├── 20220816.sql ├── 20220823.sql ├── 20220824.sql ├── 20220908.sql ├── 20220920.sql ├── 20220921.sql ├── 20221031.sql ├── 20221110.sql ├── 20221111.sql ├── 20221117.sql ├── 20221121.sql ├── 20221201.sql ├── 20230302.sql ├── 20230512.sql ├── 20230515.sql ├── 20230710.sql ├── 20230817.sql ├── 20240105.sql ├── 20240130.sql └── migrations │ ├── 20210908_initial_schema.up.sql │ ├── 20211124_add_cluster_status.up.sql │ ├── 20211125_add_cluster_template_schema_tag.up.sql │ ├── 20220113_add_application_region.up.sql │ ├── 20220124_add_slo.sql │ ├── 20220330_rename_table.sql │ ├── 20220506_add_k8s_region.sql │ ├── 20220517_add_field_to_environment_region.sql │ ├── 20220519_reactor_clustertag_to_tag.sql │ ├── 20220520_cluster_add_env_.sql │ ├── 20220527_group_region_selector.sql │ ├── 20220712_git_ref.sql │ ├── 20220722_add_template_management.sql │ ├── 20220816_create_tb_identity_provider.sql │ ├── 20220824_template_add_columns_owner_only.sql │ ├── 20220908_add_prometheus_url.sql │ ├── 20220920_add_idp_user.sql │ ├── 20220921_add_auto_free.sql │ ├── 20220922_add_webhook_event.sql │ ├── 20221031_add_config_to_registry.sql │ ├── 20221101_add_template_ci.sql │ ├── 20221103_add_user_type.sql │ ├── 20221110_add_user_password.sql │ ├── 20221130_add_event_id.sql │ ├── 20230302_add_event_extra.sql │ ├── 20230512_add_metatag_table.sql │ ├── 20230515_add_image_to_app.sql │ ├── 20230710_add_ref_id_to_token.sql │ ├── 20230817_add_check.sql │ └── 20240130_add_system_to_pr_msg.sql ├── go.mod ├── go.sum ├── image ├── DEVELOPMENT │ ├── core-debug.png │ ├── core-running.png │ ├── nocalhost-active.png │ ├── nocalhost-add.png │ ├── nocalhost-extension.png │ ├── nocalhost-remote-debug.png │ ├── nocalhost-workload.png │ ├── web-debug.png │ └── web-running.png └── readme │ ├── horizon-basic.svg │ ├── horizon.svg │ └── wechat.jpg ├── integrationtest └── authpagerender_test.go ├── lib ├── gitlab │ ├── gitlab.go │ └── gitlab_test.go ├── orm │ ├── metrics.go │ └── orm.go ├── q │ └── query.go └── s3 │ ├── s3.go │ └── s3_test.go ├── mock ├── lib │ └── gitlab │ │ └── mock_gitlab.go └── pkg │ ├── application │ ├── gitrepo │ │ ├── gitrepo_application_mock.go │ │ └── gitrepo_applicationv2_mock.go │ └── manager │ │ └── manager.go │ ├── cd │ ├── cd_mock.go │ ├── k8sutil_mock.go │ └── lagacycd_mock.go │ ├── cluster │ ├── code │ │ └── mock_codegit.go │ ├── gitrepo │ │ └── gitrepo_cluster_mock.go │ ├── manager │ │ └── manager.go │ ├── registry │ │ ├── factory │ │ │ └── factory_mock.go │ │ └── registry_mock.go │ └── tekton │ │ ├── collector │ │ └── collector_mock.go │ │ ├── factory │ │ └── factory_mock.go │ │ └── tekton_mock.go │ ├── git │ └── git_mock.go │ ├── group │ └── manager │ │ └── manager_mock.go │ ├── hook │ └── handler │ │ └── mock_handler.go │ ├── member │ ├── manager │ │ └── mock_manager.go │ └── service │ │ └── service_mock.go │ ├── pipelinerun │ └── manager │ │ ├── mock_check_manager.go │ │ └── mock_manager.go │ ├── rbac │ └── role │ │ └── roles_mock.go │ ├── tag │ └── manager │ │ └── manager.go │ ├── template │ └── manager │ │ └── manager_mock.go │ ├── templaterelease │ ├── manager │ │ └── manager_mock.go │ ├── output │ │ └── output_mock.go │ └── schema │ │ └── mock_schema.go │ ├── templaterepo │ └── mock_repo.go │ ├── templateschematag │ └── manager │ │ └── mock_manager.go │ ├── user │ └── manager │ │ └── manager_mock.go │ └── userlink │ └── manager │ └── manager_mock.go ├── openapi ├── v1 │ ├── front │ │ ├── access.yaml │ │ ├── application.yaml │ │ ├── cluster.yaml │ │ ├── code.yaml │ │ ├── common.yaml │ │ ├── group.yaml │ │ ├── login.yaml │ │ ├── terminal.yaml │ │ └── user.yaml │ └── restful │ │ ├── accesstoken.yaml │ │ ├── application.yaml │ │ ├── cluster.yaml │ │ ├── common.yaml │ │ ├── environment.yaml │ │ ├── event.yaml │ │ ├── group.yaml │ │ ├── harbor.yaml │ │ ├── horizonapp.yaml │ │ ├── member.yaml │ │ ├── oauthapp.yaml │ │ ├── oauthserver.yaml │ │ ├── pipelinerun.yaml │ │ ├── region.yaml │ │ ├── tag.yaml │ │ ├── template.yaml │ │ ├── terminal.yaml │ │ └── webhook.yaml └── v2 │ ├── front │ ├── access.yaml │ ├── application.yaml │ ├── build.yaml │ ├── cluster.yaml │ ├── code.yaml │ ├── common.yaml │ └── group.yaml │ └── restful │ ├── accesstoken.yaml │ ├── application.yaml │ ├── applicationregion.yaml │ ├── badge.yaml │ ├── cluster.yaml │ ├── common.yaml │ ├── environment.yaml │ ├── environmentregion.yaml │ ├── envtemplate.yaml │ ├── event.yaml │ ├── group.yaml │ ├── horizonapp.yaml │ ├── idp.yaml │ ├── member.yaml │ ├── metatag.yaml │ ├── oauthapp.yaml │ ├── oauthserver.yaml │ ├── pipelinerun.yaml │ ├── region.yaml │ ├── registry.yaml │ ├── role.yaml │ ├── scope.yaml │ ├── tag.yaml │ ├── template.yaml │ ├── terminal.yaml │ ├── user.yaml │ └── webhook.yaml ├── pkg ├── accesstoken │ ├── dao │ │ └── dao.go │ ├── manager │ │ └── manager.go │ └── models │ │ └── models.go ├── admission │ ├── http.go │ ├── models │ │ └── models.go │ ├── webhook.go │ └── webhook_test.go ├── application │ ├── dao │ │ └── dao.go │ ├── gitrepo │ │ ├── gitrepo_application_test.go │ │ └── gitrepo_applicationv2.go │ ├── manager │ │ ├── manager.go │ │ └── manager_test.go │ ├── models │ │ └── application.go │ └── service │ │ ├── models.go │ │ ├── service.go │ │ └── service_test.go ├── applicationregion │ ├── dao │ │ └── dao.go │ ├── manager │ │ ├── manager.go │ │ └── manager_test.go │ └── models │ │ └── applicationregion.go ├── argocd │ ├── application.go │ ├── argocd.go │ ├── argocd_test.go │ ├── facotry.go │ ├── facotry_test.go │ └── mock │ │ └── mock.go ├── auth │ ├── prehandle.go │ ├── prehandle_test.go │ └── types.go ├── authentication │ └── user │ │ └── user.go ├── badge │ ├── dao │ │ └── dao.go │ ├── manager │ │ └── manager.go │ └── models │ │ └── models.go ├── cd │ ├── cd.go │ ├── k8sutil.go │ ├── legacycd.go │ ├── types.go │ └── util.go ├── cluster │ ├── code │ │ ├── codegit.go │ │ └── models.go │ ├── dao │ │ └── dao.go │ ├── gitrepo │ │ ├── gitrepo_cluster.go │ │ └── gitrepo_cluster_test.go │ ├── kubeclient │ │ └── factory.go │ ├── manager │ │ ├── manager.go │ │ └── manager_test.go │ ├── metrics │ │ ├── metrics.go │ │ ├── metrics_test.go │ │ └── tekton │ │ │ ├── metrics.go │ │ │ ├── metrics_test.go │ │ │ ├── resolver.go │ │ │ └── resolver_test.go │ ├── models │ │ └── cluster.go │ ├── registry │ │ ├── factory │ │ │ └── factory.go │ │ ├── harbor │ │ │ ├── registry_harbor_metrics.go │ │ │ ├── registry_harbor_metrics_test.go │ │ │ ├── v1 │ │ │ │ ├── mockserver │ │ │ │ │ └── server.go │ │ │ │ ├── registry_harbor.go │ │ │ │ └── registry_harbor_test.go │ │ │ └── v2 │ │ │ │ ├── mockserver │ │ │ │ └── server.go │ │ │ │ ├── registry_harbor.go │ │ │ │ └── registry_harbor_test.go │ │ └── registry.go │ ├── service │ │ ├── models.go │ │ ├── service.go │ │ └── service_test.go │ └── tekton │ │ ├── client.go │ │ ├── client_test.go │ │ ├── collector │ │ ├── collector.go │ │ ├── collector_dummy.go │ │ ├── collector_dummy_test.go │ │ ├── collector_s3.go │ │ ├── collector_s3_test.go │ │ └── collector_test.go │ │ ├── factory │ │ └── factory.go │ │ ├── log │ │ ├── log.go │ │ ├── params.go │ │ ├── pipeline_reader.go │ │ ├── reader.go │ │ └── task_reader.go │ │ ├── tekton.go │ │ ├── tekton_run.go │ │ ├── tekton_run_test.go │ │ ├── tekton_test.go │ │ ├── tekton_util.go │ │ └── tekton_util_test.go ├── collection │ ├── dao │ │ └── dao.go │ ├── manager │ │ └── manager.go │ └── models │ │ └── models.go ├── common │ ├── db_scripts.go │ └── models.go ├── config │ ├── admission │ │ └── config.go │ ├── argocd │ │ └── argocd.go │ ├── authenticate │ │ └── authenticate.go │ ├── autofree │ │ └── config.go │ ├── clean │ │ └── config.go │ ├── db │ │ └── config.go │ ├── eventhandler │ │ └── eventhandler.go │ ├── git │ │ └── git.go │ ├── gitlab │ │ └── gitlab.go │ ├── grafana │ │ └── grafana.go │ ├── job │ │ └── job.go │ ├── k8sevent │ │ └── k8sevent.go │ ├── oauth │ │ └── config.go │ ├── oidc │ │ └── config.go │ ├── pprof │ │ └── config.go │ ├── redis │ │ └── config.go │ ├── role │ │ └── config.go │ ├── server │ │ └── config.go │ ├── session │ │ └── config.go │ ├── tekton │ │ └── tekton.go │ ├── template │ │ └── template.go │ ├── templaterepo │ │ └── template_repo.go │ ├── token │ │ └── token.go │ └── webhook │ │ └── webhook.go ├── context │ ├── context.go │ └── scope.go ├── environment │ ├── dao │ │ └── dao.go │ ├── manager │ │ ├── manager.go │ │ └── manager_test.go │ ├── models │ │ └── environment.go │ └── service │ │ └── autofree.go ├── environmentregion │ ├── dao │ │ └── dao.go │ ├── manager │ │ ├── manager.go │ │ └── manager_test.go │ └── models │ │ └── environment_region.go ├── errors │ ├── README.md │ └── errors.go ├── event │ ├── dao │ │ └── dao.go │ ├── manager │ │ ├── manager.go │ │ └── manager_test.go │ ├── models │ │ └── event.go │ └── service │ │ └── service.go ├── eventhandler │ ├── eventhandler.go │ └── wlgenerator │ │ └── wlgenerator.go ├── git │ ├── git.go │ ├── github │ │ └── github.go │ ├── gitlab │ │ └── gitlab.go │ └── models.go ├── grafana │ └── grafana.go ├── group │ ├── .DS_Store │ ├── dao │ │ └── dao.go │ ├── manager │ │ ├── manager.go │ │ └── manager_test.go │ ├── models │ │ └── group.go │ └── service │ │ ├── convert.go │ │ ├── models.go │ │ ├── service.go │ │ └── service_test.go ├── hook │ ├── handler │ │ └── handler.go │ ├── hook │ │ ├── hooks.go │ │ └── models.go │ ├── hook_test.go │ └── hooks.go ├── horizonapp │ ├── dao │ │ └── dao.go │ └── models │ │ └── models.go ├── idp │ ├── dao │ │ └── dao.go │ ├── manager │ │ └── manager.go │ ├── models │ │ └── models.go │ └── utils │ │ └── utils.go ├── jobs │ ├── autofree │ │ ├── autofree.go │ │ └── autofree_test.go │ ├── clean │ │ ├── cleaner.go │ │ └── cleaner_test.go │ ├── eventhandler │ │ └── eventhandler.go │ ├── grafanasync │ │ └── grafanasync.go │ ├── k8sevent │ │ └── k8sevent.go │ ├── singleinstancejob.go │ └── webhook │ │ └── webhook.go ├── member │ ├── dao │ │ └── dao.go │ ├── manager │ │ ├── manager.go │ │ └── manager_test.go │ ├── models │ │ └── member.go │ └── service │ │ ├── models.go │ │ ├── service.go │ │ └── service_test.go ├── oauth │ ├── dao │ │ └── dao.go │ ├── manager │ │ ├── manager.go │ │ └── manager_test.go │ ├── models │ │ └── models.go │ └── scope │ │ └── scope.go ├── param │ ├── managerparam │ │ └── managerparam.go │ └── param.go ├── pr │ ├── dao │ │ ├── check.go │ │ ├── message.go │ │ └── pipelinerun.go │ ├── manager │ │ ├── check.go │ │ ├── check_test.go │ │ ├── message.go │ │ ├── message_test.go │ │ ├── pipelinerun.go │ │ ├── pipelinerun_test.go │ │ └── pr.go │ ├── models │ │ ├── check.go │ │ ├── message.go │ │ └── pipelinerun.go │ ├── pipeline │ │ ├── dao │ │ │ └── dao.go │ │ ├── manager │ │ │ ├── manager.go │ │ │ └── manager_test.go │ │ └── models │ │ │ ├── pipeline.go │ │ │ ├── stats.go │ │ │ ├── step.go │ │ │ └── task.go │ └── service │ │ └── service.go ├── rbac │ ├── auth.go │ ├── auth_test.go │ ├── role │ │ ├── roles.go │ │ └── roles_test.go │ └── types │ │ ├── eveluation_helpers.go │ │ ├── types.go │ │ └── types_test.go ├── region │ ├── dao │ │ └── dao.go │ ├── manager │ │ ├── manager.go │ │ └── manager_test.go │ └── models │ │ └── region.go ├── regioninformers │ └── regioninformers.go ├── registry │ ├── dao │ │ └── dao.go │ ├── manager │ │ ├── manager.go │ │ └── manager_test.go │ └── models │ │ └── registry.go ├── server │ ├── global │ │ └── model.go │ ├── request │ │ └── request.go │ ├── response │ │ └── response.go │ ├── route │ │ └── route.go │ └── rpcerror │ │ └── rpc_error.go ├── tag │ ├── dao │ │ └── dao.go │ ├── manager │ │ ├── manager.go │ │ └── manager_test.go │ └── models │ │ └── tag.go ├── template │ ├── dao │ │ └── dao.go │ ├── manager │ │ ├── manager.go │ │ └── manager_test.go │ └── models │ │ └── template.go ├── templaterelease │ ├── dao │ │ └── dao.go │ ├── manager │ │ ├── manager.go │ │ └── manager_test.go │ ├── models │ │ └── template_release.go │ ├── output │ │ ├── output.go │ │ └── output_test.go │ └── schema │ │ ├── gitlab │ │ ├── schema.go │ │ └── schema_test.go │ │ ├── repo │ │ └── schema.go │ │ └── schema.go ├── templaterepo │ ├── chartmuseumbase │ │ ├── repo.go │ │ └── repo_test.go │ ├── chartutil.go │ └── repo.go ├── templateschematag │ ├── dao │ │ └── dao.go │ ├── manager │ │ ├── manager.go │ │ └── manager_test.go │ └── models │ │ └── models.go ├── token │ ├── generator │ │ ├── generator.go │ │ └── generator_types.go │ ├── manager │ │ ├── manager.go │ │ └── manager_test.go │ ├── models │ │ └── token.go │ ├── service │ │ ├── claims.go │ │ ├── models.go │ │ ├── service.go │ │ └── service_test.go │ └── store │ │ ├── store.go │ │ └── types.go ├── user │ ├── dao │ │ └── dao.go │ ├── manager │ │ ├── manager.go │ │ └── manager_test.go │ ├── models │ │ └── user.go │ ├── service │ │ ├── service.go │ │ └── service_test.go │ └── util │ │ └── session.go ├── userlink │ ├── dao │ │ └── dao.go │ ├── manager │ │ └── manager.go │ └── models │ │ └── models.go ├── util │ ├── angular │ │ ├── angular.go │ │ └── angular_test.go │ ├── common │ │ └── common.go │ ├── errors │ │ ├── err.go │ │ └── err_test.go │ ├── jsonschema │ │ ├── jsonschema.go │ │ └── jsonschema_test.go │ ├── kube │ │ ├── fake │ │ │ └── fake.go │ │ ├── kube.go │ │ └── kube_test.go │ ├── log │ │ └── log.go │ ├── mergemap │ │ ├── mergemap.go │ │ └── mergemap_test.go │ ├── ormcallbacks │ │ └── callbacks.go │ ├── permission │ │ └── permission.go │ ├── sets │ │ ├── empty.go │ │ ├── set_test.go │ │ └── string.go │ ├── tag │ │ └── tag.go │ ├── template │ │ ├── template_test.go │ │ └── yaml_template_test.go │ ├── time │ │ └── time.go │ ├── validate │ │ └── validate.go │ └── wlog │ │ ├── log.go │ │ └── log_test.go ├── webhook │ ├── dao │ │ └── dao.go │ ├── manager │ │ ├── manager.go │ │ └── manager_test.go │ ├── models │ │ └── webhook.go │ └── service │ │ └── service.go └── workload │ ├── deployment │ └── deployment.go │ ├── dummy │ └── dummy.go │ ├── getter │ └── getter.go │ ├── kservice │ └── kservice.go │ ├── pod │ └── pod.go │ ├── rollout │ ├── rollout.go │ └── util.go │ ├── statefulset │ └── statefulset.go │ ├── type.go │ ├── util.go │ └── workload.go ├── roles.yaml ├── scopes.yaml └── scripts ├── LICENSE_TEMPLATE ├── coverage.awk ├── coverage.sh ├── install.sh └── make-rules ├── common.mk ├── copyright.mk ├── gen.mk ├── golang.mk ├── image.mk └── tools.mk /.github/ISSUE_TEMPLATE/bug-report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug Report 3 | about: Report a bug encountered while using Horizon 4 | labels: kind/bug 5 | 6 | --- 7 | 8 | 10 | 11 | 12 | **What happened**: 13 | 14 | **What you expected to happen**: 15 | 16 | **How to reproduce it (as minimally and precisely as possible)**: 17 | 18 | **Anything else we need to know?**: 19 | 20 | **Environment**: 21 | - Kubernetes version (use `kubectl version`): 22 | - OS (e.g: `cat /etc/os-release`): 23 | - Kernel (e.g. `uname -a`): 24 | - Others: 25 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/enhancement.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Enhancement Request 3 | about: Suggest an enhancement to the Horizon project 4 | labels: kind/feature 5 | 6 | --- 7 | 8 | 9 | **What would you like to be added**: 10 | 11 | **Why is this needed**: 12 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ### Description of your changes 2 | 3 | 10 | 11 | Fixes # 12 | 13 | I have: 14 | 15 | - [ ] Read and followed Horizon's [contribution process](https://github.com/horizoncd/horizon/CONTRIBUTING.md). 16 | - [ ] Run `make build && make lint` to ensure this PR is ready for review. 17 | 18 | ### How has this code been tested 19 | 20 | 25 | 26 | 27 | ### Special notes for your reviewer 28 | 29 | 35 | -------------------------------------------------------------------------------- /.github/workflows/stale.yml: -------------------------------------------------------------------------------- 1 | # This workflow warns and then closes issues and PRs that have had no activity for a specified amount of time. 2 | # 3 | # You can adjust the behavior by modifying this file. 4 | # For more information, see: 5 | # https://github.com/actions/stale 6 | name: Mark stale issues and pull requests 7 | 8 | on: 9 | schedule: 10 | - cron: '31 19 * * *' 11 | 12 | jobs: 13 | stale: 14 | 15 | runs-on: ubuntu-latest 16 | permissions: 17 | issues: write 18 | pull-requests: write 19 | 20 | steps: 21 | - uses: actions/stale@v5 22 | with: 23 | repo-token: ${{ github.token }} 24 | days-before-stale: 30 25 | days-before-close: 5 26 | stale-issue-message: 'This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.' 27 | stale-pr-message: 'This issue is stale because it has been open 30 days with no activity.' 28 | close-issue-message: 'This issue was closed because it has been stalled for 5 days with no activity.' 29 | close-pr-message: 'This PR was closed because it has been stalled for 5 days with no activity. You can reopen it if you want.' 30 | stale-issue-label: 'no-issue-activity' 31 | stale-pr-label: 'no-pr-activity' 32 | -------------------------------------------------------------------------------- /.github/workflows/unit-test.yml: -------------------------------------------------------------------------------- 1 | name: Lint & Unit Test 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | - main 8 | paths: 9 | - '**.go' 10 | pull_request: 11 | paths: 12 | - '**.go' 13 | 14 | permissions: 15 | contents: read 16 | 17 | jobs: 18 | lint: 19 | name: golangci-lint 20 | runs-on: ubuntu-20.04 21 | steps: 22 | - uses: actions/setup-go@v3 23 | with: 24 | go-version: 1.15 25 | - uses: actions/checkout@v3 26 | - name: golangci-lint 27 | uses: golangci/golangci-lint-action@v3 28 | with: 29 | version: v1.47.3 30 | 31 | unit-test: 32 | strategy: 33 | matrix: 34 | go: [1.15] 35 | name: unit-test 36 | needs: [lint] 37 | runs-on: ubuntu-20.04 38 | steps: 39 | - uses: actions/checkout@v3 40 | 41 | - uses: actions/setup-go@v3 42 | with: 43 | go-version: ${{ matrix.go }} 44 | 45 | - name: Set Prefix 46 | id: prefix 47 | run: | 48 | echo "PREFIX=$(go list -m)" >> $GITHUB_OUTPUT 49 | 50 | - uses: paambaati/codeclimate-action@v6.0.0 51 | env: 52 | CC_TEST_REPORTER_ID: e47aa5e6270db938ee1bdd6dc9486f4f581beb1bcaee5d28be1633d68c8550c6 53 | with: 54 | coverageLocations: | 55 | ${{github.workspace}}/coverage.out:gocov 56 | coverageCommand: go test -v -coverprofile=coverage.out ./... 57 | prefix: ${{ steps.prefix.outputs.PREFIX }} 58 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | .idea/ 3 | .vscode/ 4 | 5 | coverage.data 6 | 7 | .DS_Store 8 | core/__debug_bin 9 | 10 | bin/ 11 | 12 | # Debugging info 13 | *.debug 14 | *.exe 15 | *.test 16 | 17 | # makefile 18 | tmp/ 19 | tools/ 20 | 21 | config-dev.yaml 22 | -------------------------------------------------------------------------------- /.golangci.yml: -------------------------------------------------------------------------------- 1 | # options for analysis running 2 | run: 3 | # timeout for analysis, e.g. 30s, 5m, default is 1m 4 | timeout: 10m 5 | # which files to skip: they will be analyzed, but issues from them 6 | # won't be reported. Default value is empty list, but there is 7 | # no need to include all autogenerated files, we confidently recognize 8 | # autogenerated files. If it's not please let us know. 9 | # "/" will be replaced by current OS file path separator to properly work 10 | # on Windows. 11 | skip-files: [] 12 | 13 | # all available settings of specific linters 14 | linters-settings: 15 | lll: 16 | # max line length, lines longer will be reported. Default is 120. 17 | # '\t' is counted as 1 character by default, and can be changed with the tab-width option 18 | line-length: 120 19 | 20 | linters: 21 | enable: 22 | - lll 23 | - gofmt 24 | - revive 25 | - misspell 26 | - whitespace 27 | - goconst 28 | - bodyclose 29 | -------------------------------------------------------------------------------- /.nocalhost/config.yaml: -------------------------------------------------------------------------------- 1 | name: horizon-core 2 | serviceType: deployment 3 | containers: 4 | - name: core 5 | dev: 6 | gitUrl: "" 7 | image: horizoncd/go-dlv:v2.0.0 8 | sidecarImage: horizoncd/nocalhost-sidecar:syncthing 9 | # aliyun registry for domestic developer 10 | # image: registry.cn-hangzhou.aliyuncs.com/horizoncd/go-dlv:v2.0.0 11 | # sidecarImage: registry.cn-hangzhou.aliyuncs.com/horizoncd/nocalhost-sidecar:syncthing 12 | shell: "" 13 | workDir: "/home/appops" 14 | storageClass: "" 15 | persistentVolumeDirs: [] 16 | command: 17 | run: 18 | - .nocalhost/run.sh 19 | debug: 20 | - .nocalhost/debug.sh 21 | debug: 22 | remoteDebugPort: 9009 23 | hotReload: false 24 | sync: 25 | type: "send" 26 | mode: "pattern" 27 | filePattern: [] 28 | ignoreFilePattern: 29 | - "./build" 30 | - "./db" 31 | - "./mock" 32 | - "./openapi" 33 | env: [] 34 | portForward: [] 35 | -------------------------------------------------------------------------------- /.nocalhost/debug.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | dlv --headless --log --listen :9009 --api-version 2 --accept-multiclient debug core/main.go -- -config=/home/appops/config -roles=/home/appops/roles -environment=production -scopes=/home/appops/scopes -buildjsonschema=/home/appops/buildjsonschema -builduischema=/home/appops/builduischema 4 | -------------------------------------------------------------------------------- /.nocalhost/run.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | go run core/main.go --config=/home/appops/config --roles=/home/appops/roles --environment=production --scopes=/home/appops/scopes --buildjsonschema=/home/appops/buildjsonschema --builduischema=/home/appops/builduischema 4 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | # See https://pre-commit.com for more information 2 | # See https://pre-commit.com/hooks.html for more hooks 3 | repos: 4 | - repo: https://github.com/golangci/golangci-lint 5 | rev: v1.51.1 6 | hooks: 7 | - id: golangci-lint 8 | entry: golangci-lint run --fix 9 | -------------------------------------------------------------------------------- /CODE-OF-CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Horizon Code of Conduct 2 | 3 | Horizon follows the [CNCF Code of Conduct](https://github.com/cncf/foundation/blob/master/code-of-conduct.md). 4 | -------------------------------------------------------------------------------- /build-ui-schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "ui:order": [ 3 | "buildType", 4 | "language", 5 | "environment", 6 | "buildInfo", 7 | "dockerfile", 8 | "buildArgs" 9 | ], 10 | "buildInfo": { 11 | "buildxml": { 12 | "ui:widget": "textarea", 13 | "ui:options": { 14 | "rows": 18 15 | } 16 | }, 17 | "shellScript": { 18 | "ui:widget": "textarea", 19 | "ui:options": { 20 | "rows": 18 21 | } 22 | } 23 | }, 24 | "dockerfile": { 25 | "content": { 26 | "ui:widget": "textarea", 27 | "ui:options": { 28 | "rows": 18 29 | } 30 | } 31 | }, 32 | "buildType": { 33 | "ui:widget": "radio", 34 | "ui:options": { 35 | "inline": true 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /build/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Environment Variables: 4 | # - REPOSITORY_PREFIX 5 | 6 | export REPOSITORY_PREFIX="${REPOSITORY_PREFIX:-"harbor.mockserver.org/staffyun163music/cloudnative/library/"}" 7 | 8 | build(){ 9 | local DOCKERFILE_DIR="$1" && shift 10 | local DOCKERFILE_PATH="$DOCKERFILE_DIR/Dockerfile" 11 | local COMPONENT="${DOCKERFILE_DIR##*/}" && [[ "$COMPONENT" =~ .*horizon.* ]] || COMPONENT="horizon-$COMPONENT" 12 | local CONTEXT NO_PUSH 13 | while ARG="$1" && shift; do 14 | case "$ARG" in 15 | "--context") 16 | CONTEXT="$1" && shift || break 17 | ;; 18 | "--no-push") 19 | NO_PUSH="y" 20 | ;; 21 | *) 22 | shift 23 | ;; 24 | esac 25 | done 26 | [[ ! -z "$CONTEXT" ]] || CONTEXT="$PWD" 27 | local IMAGE="${REPOSITORY_PREFIX%/}/$COMPONENT:$APP_REVISION" 28 | docker build --network=host --rm -t "$IMAGE" -f "$DOCKERFILE_PATH" "$CONTEXT" || exit 1 29 | [[ "$NO_PUSH" == "y" ]] || { 30 | docker push "$IMAGE" || exit 1 31 | docker rmi "$IMAGE" -f 32 | } 33 | } 34 | 35 | main(){ 36 | local SCRIPT="${BASH_SOURCE[0]}" && [[ -L "$SCRIPT" ]] && SCRIPT="$(readlink -f "$SCRIPT")" 37 | local SCRIPT_DIR="$(cd "$(dirname $SCRIPT)"; pwd)" SUB_PATH 38 | for SUB in $(ls "$SCRIPT_DIR"); do 39 | SUB_PATH="$SCRIPT_DIR/$SUB" 40 | [[ -f "$SUB_PATH" ]] && continue 41 | build "$SUB_PATH" "$@" 42 | done 43 | } 44 | 45 | main "$@" 46 | -------------------------------------------------------------------------------- /build/core/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:1.15.3 AS builder 2 | COPY . /horizon 3 | 4 | WORKDIR /horizon 5 | 6 | RUN CGO_ENABLED=0 GOOS=linux go build -o bin/app -ldflags '-s -w' ./core/main.go 7 | 8 | FROM alpine:3.9 AS runtime 9 | 10 | RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && \ 11 | apk update && apk add bash curl git && \ 12 | apk add tzdata && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo "Asia/Shanghai" > /etc/timezone 13 | 14 | ARG GROUP=netease 15 | ARG USER=appops 16 | ARG GROUP_ID=10001 17 | ARG USER_ID=10001 18 | 19 | RUN addgroup --gid $GROUP_ID $GROUP && adduser -h /home/$USER -u $USER_ID -G $GROUP -D $USER 20 | 21 | RUN echo "hosts: files dns" > /etc/nsswitch.conf 22 | 23 | USER $USER 24 | 25 | COPY --from=builder --chown=$USER:$GROUP /horizon/bin/app /usr/local/bin/app 26 | 27 | ENTRYPOINT ["/usr/local/bin/app"] 28 | -------------------------------------------------------------------------------- /build/swagger/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM swaggerapi/swagger-ui:latest 2 | 3 | ARG GROUP=netease 4 | ARG USER=appops 5 | ARG GROUP_ID=10001 6 | ARG USER_ID=10001 7 | 8 | RUN addgroup --gid $GROUP_ID $GROUP && adduser -h /home/$USER -u $USER_ID -G $GROUP -D $USER && \ 9 | chown -R $USER:$GROUP /var/run/ /usr/ && \ 10 | sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && apk update && apk add bash && \ 11 | curl -#sSL -o /usr/bin/jq https://music-cloudnative.nos-jd.163yun.com/binary/jq-linux64 && \ 12 | curl -#sSL -o /usr/bin/yaml2json https://music-cloudnative.nos-jd.163yun.com/binary/yaml2json_linux_amd64 && \ 13 | chmod +x /usr/bin/jq && chmod +x /usr/bin/yaml2json 14 | 15 | COPY ./openapi /openapi 16 | COPY ./build/swagger/build.sh /openapi 17 | 18 | RUN cp /openapi/build.sh /openapi/v1/restful/build.sh && cd /openapi/v1/restful && bash build.sh && \ 19 | cp /openapi/build.sh /openapi/v1/front/build.sh && cd /openapi/v1/front && bash build.sh && \ 20 | cp /openapi/v1/restful/swagger.json /openapi/restful-v1.0.0.json && \ 21 | cp /openapi/v1/front/swagger.json /openapi/front-v1.0.0.json && \ 22 | cp /openapi/build.sh /openapi/v2/restful/build.sh && cd /openapi/v2/restful && bash build.sh && \ 23 | cp /openapi/build.sh /openapi/v2/front/build.sh && cd /openapi/v2/front && bash build.sh && \ 24 | cp /openapi/v2/restful/swagger.json /openapi/restful-v2.0.0.json && \ 25 | cp /openapi/v2/front/swagger.json /openapi/front-v2.0.0.json && \ 26 | cp /openapi/v2/restful/common.yaml /openapi/common.yaml 27 | 28 | RUN chown -R $USER:$GROUP /openapi 29 | 30 | USER $USER 31 | 32 | -------------------------------------------------------------------------------- /build/swagger/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | JSON='{}' 4 | for FILE in *.yaml; do 5 | [[ "$FILE" =~ common.* ]] && continue 6 | echo $FILE 7 | JSON="$(jq -s '.[0] * .[1]' <(echo "$JSON") <(yaml2json < "$FILE"))" 8 | done 9 | jq '.info.title="Horizon API" | .info.description="Horizon API" | del(.servers)'<<<"$JSON" > swagger.json -------------------------------------------------------------------------------- /core/cmd/cloudevent.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package cmd 16 | 17 | import ( 18 | "fmt" 19 | "log" 20 | 21 | "github.com/gin-gonic/gin" 22 | cloudeventctl "github.com/horizoncd/horizon/core/controller/cloudevent" 23 | "github.com/horizoncd/horizon/core/http/cloudevent" 24 | "github.com/horizoncd/horizon/pkg/cluster/tekton/factory" 25 | "github.com/horizoncd/horizon/pkg/config/server" 26 | "github.com/horizoncd/horizon/pkg/param" 27 | ) 28 | 29 | func runCloudEventServer(tektonFty factory.Factory, config server.Config, 30 | parameter *param.Param, middlewares ...gin.HandlerFunc) { 31 | r := gin.Default() 32 | r.Use(middlewares...) 33 | 34 | cloudEventCtl := cloudeventctl.NewController(tektonFty, parameter) 35 | 36 | cloudevent.RegisterRoutes(r, cloudevent.NewAPI(cloudEventCtl)) 37 | 38 | log.Fatal(r.Run(fmt.Sprintf(":%d", config.Port))) 39 | } 40 | -------------------------------------------------------------------------------- /core/common/application.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package common 16 | 17 | const ( 18 | ApplicationQueryName = "filter" 19 | ApplicationQueryByUser = "userID" 20 | ApplicationQueryByTemplate = "template" 21 | ApplicationQueryByRelease = "templateRelease" 22 | ApplicationQueryByGroup = "groupID" 23 | ApplicationQueryByGroupRecursive = "groupRecursive" 24 | ApplicationQueryID = "id" 25 | 26 | ApplicationQueryWithDeleted = "withDeleted" 27 | ) 28 | -------------------------------------------------------------------------------- /core/common/common.go: -------------------------------------------------------------------------------- 1 | package common 2 | 3 | type Resource struct { 4 | ResourceID uint `json:"resource_id" yaml:"resourceID"` 5 | Type string `gorm:"column:resource_type" json:"resource_type" yaml:"resourceType"` 6 | } 7 | -------------------------------------------------------------------------------- /core/common/gitops.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package common 16 | 17 | const ( 18 | // fileName 19 | GitopsFileChart = "Chart.yaml" 20 | GitopsFileApplication = "application.yaml" 21 | GitopsFileTags = "tags.yaml" 22 | GitopsFileSRE = "sre/sre.yaml" 23 | GitopsFileBase = "system/horizon.yaml" 24 | GitopsFileEnv = "system/env.yaml" 25 | GitopsFileRestart = "system/restart.yaml" 26 | GitopsFilePipeline = "pipeline/pipeline.yaml" 27 | GitopsFilePipelineOutput = "pipeline/pipeline-output.yaml" 28 | GitopsFileManifest = "manifest.yaml" 29 | 30 | // value namespace 31 | GitopsEnvValueNamespace = "env" 32 | GitopsBaseValueNamespace = "horizon" 33 | 34 | GitopsMergeRequestStateOpen = "opened" 35 | 36 | GitopsGroupClusters = "clusters" 37 | GitopsGroupRecyclingClusters = "recycling-clusters" 38 | 39 | GitopsKeyTags = "tags" 40 | ) 41 | -------------------------------------------------------------------------------- /core/common/group.go: -------------------------------------------------------------------------------- 1 | package common 2 | 3 | import ( 4 | "strconv" 5 | "strings" 6 | ) 7 | 8 | func UnmarshalTraversalIDS(traversalIDs string) ([]uint, error) { 9 | splitIds := strings.Split(traversalIDs, ",") 10 | var ids = make([]uint, len(splitIds)) 11 | for i, id := range splitIds { 12 | ii, err := strconv.Atoi(id) 13 | if err != nil { 14 | return nil, err 15 | } 16 | ids[i] = uint(ii) 17 | } 18 | return ids, nil 19 | } 20 | -------------------------------------------------------------------------------- /core/common/idp/const.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package idp 16 | 17 | // for query key 18 | const ( 19 | QueryName = "name" 20 | ) 21 | -------------------------------------------------------------------------------- /core/common/jwt.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package common 16 | 17 | import ( 18 | "context" 19 | 20 | herror "github.com/horizoncd/horizon/core/errors" 21 | hctx "github.com/horizoncd/horizon/pkg/context" 22 | ) 23 | 24 | func WithContextJWTTokenString(ctx context.Context, tokenStr string) context.Context { 25 | return context.WithValue(ctx, hctx.JWTTokenString, tokenStr) 26 | } 27 | 28 | func JWTTokenStringFromContext(ctx context.Context) (string, error) { 29 | str, ok := ctx.Value(hctx.JWTTokenString).(string) 30 | if !ok { 31 | return "", herror.ErrFailedToGetJWTToken 32 | } 33 | return str, nil 34 | } 35 | -------------------------------------------------------------------------------- /core/common/pipelinerun.go: -------------------------------------------------------------------------------- 1 | package common 2 | 3 | const ( 4 | PipelineQueryByStatus = "status" 5 | 6 | MessageQueryBySystem = "system" 7 | 8 | MessagePipelinerunStopped = "stopped pipelinerun" 9 | MessagePipelinerunExecuted = "executed pipelinerun" 10 | MessagePipelinerunCancelled = "cancelled pipelinerun" 11 | MessagePipelinerunReady = "marked pipelinerun as ready to execute" 12 | ) 13 | -------------------------------------------------------------------------------- /core/common/rbac.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package common 16 | 17 | var ContextAuthRecord = "authRecord" 18 | -------------------------------------------------------------------------------- /core/common/routes.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package common 16 | 17 | const ( 18 | URLFrontLogin = "/user/login" 19 | ) 20 | 21 | const ( 22 | URLOauthAuthorization = "/login/oauth/authorize" 23 | 24 | URLLoginCallback = "/apis/core/v1/login/callback" 25 | ) 26 | -------------------------------------------------------------------------------- /core/common/template.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package common 16 | 17 | const ( 18 | TemplateQueryWithoutCI = "withoutCI" 19 | TemplateQueryByUser = "userID" 20 | TemplateQueryByGroup = "groupID" 21 | TemplateQueryByGroupRecursive = "groupIDRecursive" 22 | TemplateQueryByGroups = "templateGroupIDs" 23 | TemplateQueryWithRelease = "withRelease" 24 | TemplateQueryName = "filter" 25 | TemplateQueryType = "type" 26 | ) 27 | -------------------------------------------------------------------------------- /core/common/utils.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package common 16 | 17 | import ( 18 | "context" 19 | "io/ioutil" 20 | "net/http" 21 | "os" 22 | "os/signal" 23 | "syscall" 24 | 25 | "github.com/horizoncd/horizon/pkg/hook/hook" 26 | "github.com/horizoncd/horizon/pkg/util/log" 27 | ) 28 | 29 | func ElegantExit(h hook.Hook) { 30 | signals := make(chan os.Signal, 1) 31 | signal.Notify(signals, syscall.SIGTERM) 32 | 33 | go func() { 34 | <-signals 35 | h.WaitStop() 36 | os.Exit(0) 37 | }() 38 | } 39 | 40 | func Response(ctx context.Context, resp *http.Response) string { 41 | data, err := ioutil.ReadAll(resp.Body) 42 | if err != nil { 43 | log.Error(ctx, err) 44 | return err.Error() 45 | } 46 | 47 | str := string(data) 48 | log.Info(ctx, str) 49 | return str 50 | } 51 | -------------------------------------------------------------------------------- /core/controller/access/models.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package access 16 | 17 | type API struct { 18 | URL string `json:"url"` 19 | Method string `json:"method"` 20 | } 21 | 22 | type ReviewResult struct { 23 | Allowed bool `json:"allowed"` 24 | Reason string `json:"reason"` 25 | } 26 | 27 | // ReviewRequest provide apis for access review 28 | type ReviewRequest struct { 29 | APIs []API `json:"apis"` 30 | } 31 | -------------------------------------------------------------------------------- /core/controller/badge/model.go: -------------------------------------------------------------------------------- 1 | package badge 2 | 3 | import ( 4 | "time" 5 | 6 | "github.com/horizoncd/horizon/pkg/badge/models" 7 | ) 8 | 9 | type Badge struct { 10 | Create `json:",inline"` 11 | ID uint `json:"id"` 12 | ResourceID uint `json:"resourceID"` 13 | ResourceType string `json:"resourceType"` 14 | CreatedAt time.Time `json:"createdAt"` 15 | UpdatedAt time.Time `json:"updatedAt"` 16 | } 17 | 18 | func (b *Badge) FromDAO(daoBadge *models.Badge) { 19 | b.ID = daoBadge.ID 20 | b.ResourceID = daoBadge.ResourceID 21 | b.ResourceType = daoBadge.ResourceType 22 | b.Name = daoBadge.Name 23 | b.SvgLink = daoBadge.SvgLink 24 | b.RedirectLink = daoBadge.RedirectLink 25 | b.CreatedAt = daoBadge.CreatedAt 26 | b.UpdatedAt = daoBadge.UpdatedAt 27 | } 28 | 29 | type Update struct { 30 | SvgLink *string `json:"svgLink"` 31 | RedirectLink *string `json:"redirectLink"` 32 | } 33 | 34 | type Create struct { 35 | SvgLink string `json:"svgLink"` 36 | RedirectLink string `json:"redirectLink,omitempty"` 37 | Name string `json:"name"` 38 | } 39 | -------------------------------------------------------------------------------- /core/controller/build/controller.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package build 16 | 17 | import ( 18 | "golang.org/x/net/context" 19 | ) 20 | 21 | // Controller get build schema 22 | type Controller interface { 23 | GetSchema(ctx context.Context) (*Schema, error) 24 | } 25 | 26 | type controller struct { 27 | schema *Schema 28 | } 29 | 30 | func NewController(schema *Schema) Controller { 31 | return &controller{schema: schema} 32 | } 33 | 34 | func (c controller) GetSchema(ctx context.Context) (*Schema, error) { 35 | return c.schema, nil 36 | } 37 | 38 | var _ Controller = (*controller)(nil) 39 | -------------------------------------------------------------------------------- /core/controller/build/models.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package build 16 | 17 | type Schema struct { 18 | JSONSchema map[string]interface{} `json:"jsonSchema"` 19 | UISchema map[string]interface{} `json:"uiSchema"` 20 | } 21 | -------------------------------------------------------------------------------- /core/controller/cloudevent/models.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package cloudevent 16 | 17 | import ( 18 | "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" 19 | "knative.dev/pkg/apis" 20 | ) 21 | 22 | type WrappedPipelineRun struct { 23 | PipelineRun *v1beta1.PipelineRun `json:"pipelineRun"` 24 | } 25 | 26 | func (wpr *WrappedPipelineRun) IsFinished() bool { 27 | if wpr.PipelineRun == nil { 28 | return false 29 | } 30 | prc := wpr.PipelineRun.Status.GetCondition(apis.ConditionSucceeded) 31 | if prc == nil { 32 | return false 33 | } 34 | switch v1beta1.PipelineRunReason(prc.GetReason()) { 35 | case v1beta1.PipelineRunReasonSuccessful, v1beta1.PipelineRunReasonCompleted, 36 | v1beta1.PipelineRunReasonFailed, v1beta1.PipelineRunReasonTimedOut, 37 | v1beta1.PipelineRunReasonCancelled, v1beta1.PipelineRunSpecStatusCancelled: 38 | return true 39 | } 40 | return false 41 | } 42 | -------------------------------------------------------------------------------- /core/controller/cluster/models_internal.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package cluster 16 | 17 | type InternalDeployRequest struct { 18 | PipelinerunID uint `json:"pipelinerunID"` 19 | } 20 | 21 | type InternalDeployResponse struct { 22 | PipelinerunID uint `json:"pipelinerunID"` 23 | Commit string `json:"commit"` 24 | } 25 | -------------------------------------------------------------------------------- /core/controller/cluster/models_internal_v2.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package cluster 16 | 17 | type InternalDeployRequestV2 struct { 18 | PipelinerunID uint `json:"pipelinerunID"` 19 | Output map[string]interface{} `json:"output"` 20 | } 21 | 22 | type InternalDeployResponseV2 struct { 23 | PipelinerunID uint `json:"pipelinerunID"` 24 | Commit string `json:"commit"` 25 | } 26 | -------------------------------------------------------------------------------- /core/controller/code/controller.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package code 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/horizoncd/horizon/pkg/cluster/code" 21 | "github.com/horizoncd/horizon/pkg/git" 22 | ) 23 | 24 | type Controller interface { 25 | ListBranch(ctx context.Context, gitURL string, params *git.SearchParams) ([]string, error) 26 | ListTag(ctx context.Context, gitURL string, params *git.SearchParams) ([]string, error) 27 | } 28 | 29 | func NewController(getter code.GitGetter) Controller { 30 | return &controller{gitGetter: getter} 31 | } 32 | 33 | type controller struct { 34 | gitGetter code.GitGetter 35 | } 36 | 37 | func (c *controller) ListBranch(ctx context.Context, gitURL string, params *git.SearchParams) ([]string, error) { 38 | return c.gitGetter.ListBranch(ctx, gitURL, params) 39 | } 40 | 41 | func (c *controller) ListTag(ctx context.Context, gitURL string, params *git.SearchParams) ([]string, error) { 42 | return c.gitGetter.ListTag(ctx, gitURL, params) 43 | } 44 | -------------------------------------------------------------------------------- /core/controller/code/models.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package code 16 | 17 | // Git struct about git 18 | type Git struct { 19 | URL string `json:"url"` 20 | Subfolder string `json:"subfolder"` 21 | Branch string `json:"branch"` 22 | Tag string `json:"tag"` 23 | Commit string `json:"commit"` 24 | } 25 | -------------------------------------------------------------------------------- /core/controller/envtemplate/models.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package envtemplate 16 | 17 | type EnvTemplate struct { 18 | Application map[string]interface{} `json:"application"` 19 | Pipeline map[string]interface{} `json:"pipeline"` 20 | } 21 | 22 | type UpdateEnvTemplateRequest struct { 23 | *EnvTemplate 24 | } 25 | 26 | type GetEnvTemplateResponse struct { 27 | *EnvTemplate 28 | } 29 | -------------------------------------------------------------------------------- /core/controller/event/controller.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package event 16 | 17 | import ( 18 | "context" 19 | 20 | eventmanager "github.com/horizoncd/horizon/pkg/event/manager" 21 | "github.com/horizoncd/horizon/pkg/param" 22 | "github.com/horizoncd/horizon/pkg/util/wlog" 23 | ) 24 | 25 | type Controller interface { 26 | ListSupportEvents(ctx context.Context) map[string]string 27 | } 28 | 29 | type controller struct { 30 | eventMgr eventmanager.Manager 31 | } 32 | 33 | func NewController(param *param.Param) Controller { 34 | return &controller{ 35 | eventMgr: param.EventMgr, 36 | } 37 | } 38 | 39 | func (c *controller) ListSupportEvents(ctx context.Context) map[string]string { 40 | const op = "event controller: list supported events" 41 | defer wlog.Start(ctx, op).StopPrint() 42 | 43 | return c.eventMgr.ListSupportEvents() 44 | } 45 | -------------------------------------------------------------------------------- /core/controller/group/convert.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package group 16 | 17 | import ( 18 | "github.com/horizoncd/horizon/pkg/group/models" 19 | ) 20 | 21 | // convertNewGroupToGroup convert newGroup model to group model 22 | func convertNewGroupToGroup(newGroup *NewGroup) *models.Group { 23 | return &models.Group{ 24 | Name: newGroup.Name, 25 | Path: newGroup.Path, 26 | VisibilityLevel: newGroup.VisibilityLevel, 27 | Description: newGroup.Description, 28 | ParentID: newGroup.ParentID, 29 | } 30 | } 31 | 32 | // convertUpdateGroupToGroup convert updateGroup model to group model 33 | func convertUpdateGroupToGroup(updateGroup *UpdateGroup) *models.Group { 34 | return &models.Group{ 35 | Name: updateGroup.Name, 36 | Path: updateGroup.Path, 37 | VisibilityLevel: updateGroup.VisibilityLevel, 38 | Description: updateGroup.Description, 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /core/controller/role/controller.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package role 16 | 17 | import ( 18 | "context" 19 | "net/http" 20 | 21 | "github.com/horizoncd/horizon/pkg/param" 22 | "github.com/horizoncd/horizon/pkg/rbac/role" 23 | "github.com/horizoncd/horizon/pkg/rbac/types" 24 | "github.com/horizoncd/horizon/pkg/util/errors" 25 | ) 26 | 27 | type Controller interface { 28 | ListRole(ctx context.Context) ([]types.Role, error) 29 | } 30 | 31 | func NewController(param *param.Param) Controller { 32 | return &controller{roleService: param.RoleService} 33 | } 34 | 35 | type controller struct { 36 | roleService role.Service 37 | } 38 | 39 | func (c controller) ListRole(ctx context.Context) ([]types.Role, error) { 40 | const op = "role *controller: list role" 41 | roles, err := c.roleService.ListRole(ctx) 42 | if err != nil { 43 | return nil, errors.E(op, http.StatusInternalServerError, err.Error()) 44 | } 45 | return roles, nil 46 | } 47 | -------------------------------------------------------------------------------- /core/controller/scope/controller.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package scope 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/horizoncd/horizon/pkg/oauth/scope" 21 | "github.com/horizoncd/horizon/pkg/param" 22 | ) 23 | 24 | type Controller interface { 25 | ListScopes(ctx context.Context) []BasicInfo 26 | } 27 | 28 | func NewController(param *param.Param) Controller { 29 | return &controller{scopeSvc: param.ScopeService} 30 | } 31 | 32 | type controller struct { 33 | scopeSvc scope.Service 34 | } 35 | 36 | func (c controller) ListScopes(ctx context.Context) []BasicInfo { 37 | var resp []BasicInfo 38 | scopes := c.scopeSvc.GetAllScopes() 39 | for _, scope := range scopes { 40 | resp = append(resp, BasicInfo{ 41 | Name: scope.Name, 42 | Desc: scope.Desc, 43 | }) 44 | } 45 | return resp 46 | } 47 | -------------------------------------------------------------------------------- /core/controller/scope/models.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package scope 16 | 17 | type BasicInfo struct { 18 | Name string `json:"name"` 19 | Desc string `json:"desc"` 20 | } 21 | -------------------------------------------------------------------------------- /core/controller/terminal/models.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package terminal 16 | 17 | type SessionIDResp struct { 18 | ID string `json:"id"` 19 | } 20 | -------------------------------------------------------------------------------- /core/http/api/v1/access/routers.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package access 16 | 17 | import ( 18 | "net/http" 19 | 20 | "github.com/horizoncd/horizon/pkg/server/route" 21 | 22 | "github.com/gin-gonic/gin" 23 | ) 24 | 25 | // RegisterRoutes register routes 26 | func (a *API) RegisterRoute(engine *gin.Engine) { 27 | frontGroup := engine.Group("/apis/front/v1") 28 | var frontRoutes = route.Routes{ 29 | { 30 | Method: http.MethodPost, 31 | Pattern: "/accessreview", 32 | HandlerFunc: a.AccessReview, 33 | }, 34 | } 35 | 36 | route.RegisterRoutes(frontGroup, frontRoutes) 37 | } 38 | -------------------------------------------------------------------------------- /core/http/api/v1/applicationregion/routers.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package applicationregion 16 | 17 | import ( 18 | "fmt" 19 | "net/http" 20 | 21 | "github.com/horizoncd/horizon/core/common" 22 | "github.com/horizoncd/horizon/pkg/server/route" 23 | 24 | "github.com/gin-gonic/gin" 25 | ) 26 | 27 | // RegisterRoutes register routes 28 | func (api *API) RegisterRoute(engine *gin.Engine) { 29 | apiGroup := engine.Group("/apis/core/v1") 30 | var routes = route.Routes{ 31 | { 32 | Method: http.MethodGet, 33 | Pattern: fmt.Sprintf("/applications/:%v/defaultregions", common.ParamApplicationID), 34 | HandlerFunc: api.List, 35 | }, 36 | { 37 | Method: http.MethodPost, 38 | Pattern: fmt.Sprintf("/applications/:%v/defaultregions", common.ParamApplicationID), 39 | HandlerFunc: api.Update, 40 | }, 41 | } 42 | 43 | route.RegisterRoutes(apiGroup, routes) 44 | } 45 | -------------------------------------------------------------------------------- /core/http/api/v1/code/routers.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package code 16 | 17 | import ( 18 | "net/http" 19 | 20 | "github.com/gin-gonic/gin" 21 | "github.com/horizoncd/horizon/pkg/server/route" 22 | ) 23 | 24 | func (api *API) RegisterRoute(engine *gin.Engine) { 25 | group := engine.Group("/apis/front/v1") 26 | var routes = route.Routes{ 27 | { 28 | Method: http.MethodGet, 29 | Pattern: "code/listbranch", 30 | HandlerFunc: api.ListBranch, 31 | }, 32 | { 33 | Method: http.MethodGet, 34 | Pattern: "code/listtag", 35 | HandlerFunc: api.ListTag, 36 | }, 37 | } 38 | route.RegisterRoutes(group, routes) 39 | } 40 | -------------------------------------------------------------------------------- /core/http/api/v1/environmentregion/routers.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package environmentregion 16 | 17 | import ( 18 | "fmt" 19 | "net/http" 20 | 21 | "github.com/gin-gonic/gin" 22 | "github.com/horizoncd/horizon/pkg/server/route" 23 | ) 24 | 25 | // RegisterRoutes register routes 26 | func (api *API) RegisterRoute(engine *gin.Engine) { 27 | apiGroup := engine.Group("/apis/core/v1/environmentregions") 28 | var routes = route.Routes{ 29 | { 30 | Method: http.MethodGet, 31 | HandlerFunc: api.List, 32 | }, { 33 | Method: http.MethodPost, 34 | HandlerFunc: api.Create, 35 | }, { 36 | Method: http.MethodPost, 37 | Pattern: fmt.Sprintf("/:%v/setdefault", _environmentRegionIDParam), 38 | HandlerFunc: api.SetDefault, 39 | }, { 40 | Method: http.MethodDelete, 41 | Pattern: fmt.Sprintf("/:%v", _environmentRegionIDParam), 42 | HandlerFunc: api.DeleteByID, 43 | }, 44 | } 45 | route.RegisterRoutes(apiGroup, routes) 46 | } 47 | -------------------------------------------------------------------------------- /core/http/api/v1/envtemplate/routers.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package envtemplate 16 | 17 | import ( 18 | "fmt" 19 | "net/http" 20 | 21 | "github.com/gin-gonic/gin" 22 | "github.com/horizoncd/horizon/pkg/server/route" 23 | ) 24 | 25 | // RegisterRoutes register routes 26 | func (api *API) RegisterRoute(engine *gin.Engine) { 27 | apiGroup := engine.Group("/apis/core/v1") 28 | var routes = route.Routes{ 29 | { 30 | Method: http.MethodGet, 31 | Pattern: fmt.Sprintf("/applications/:%v/envtemplates", _applicationIDParam), 32 | HandlerFunc: api.Get, 33 | }, 34 | { 35 | Method: http.MethodPost, 36 | Pattern: fmt.Sprintf("/applications/:%v/envtemplates", _applicationIDParam), 37 | HandlerFunc: api.Update, 38 | }, 39 | } 40 | route.RegisterRoutes(apiGroup, routes) 41 | } 42 | -------------------------------------------------------------------------------- /core/http/api/v1/event/apis.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package event 16 | 17 | import ( 18 | "github.com/horizoncd/horizon/core/controller/event" 19 | "github.com/horizoncd/horizon/pkg/server/response" 20 | 21 | "github.com/gin-gonic/gin" 22 | ) 23 | 24 | type API struct { 25 | eventCtl event.Controller 26 | } 27 | 28 | // NewAPI initializes a new event api 29 | func NewAPI(controller event.Controller) *API { 30 | return &API{ 31 | eventCtl: controller, 32 | } 33 | } 34 | 35 | // ListSupportEvents list actions categorized based on resources 36 | func (a *API) ListSupportEvents(c *gin.Context) { 37 | response.SuccessWithData(c, a.eventCtl.ListSupportEvents(c)) 38 | } 39 | -------------------------------------------------------------------------------- /core/http/api/v1/event/routers.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package event 16 | 17 | import ( 18 | "net/http" 19 | 20 | "github.com/horizoncd/horizon/pkg/server/route" 21 | 22 | "github.com/gin-gonic/gin" 23 | ) 24 | 25 | // RegisterRoutes register routes 26 | func (a *API) RegisterRoute(engine *gin.Engine) { 27 | coreAPI := engine.Group("/apis/core/v1") 28 | var coreRoutes = route.Routes{ 29 | { 30 | Pattern: "/supportevents", 31 | Method: http.MethodGet, 32 | HandlerFunc: a.ListSupportEvents, 33 | }, 34 | } 35 | 36 | route.RegisterRoutes(coreAPI, coreRoutes) 37 | } 38 | -------------------------------------------------------------------------------- /core/http/api/v1/oauthserver/routes.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package oauthserver 16 | 17 | import ( 18 | "net/http" 19 | 20 | "github.com/gin-gonic/gin" 21 | "github.com/horizoncd/horizon/pkg/server/route" 22 | ) 23 | 24 | const ( 25 | BasicPath = "/login/oauth" 26 | AuthorizePath = "/authorize" 27 | AccessTokenPath = "/access_token" 28 | ) 29 | 30 | func (a *API) RegisterRoute(engine *gin.Engine) { 31 | apiGroup := engine.Group(BasicPath) 32 | 33 | var routes = route.Routes{ 34 | { 35 | Pattern: AuthorizePath, 36 | Method: http.MethodGet, 37 | HandlerFunc: a.HandleAuthorizationGetReq, 38 | }, { 39 | Pattern: AuthorizePath, 40 | Method: http.MethodPost, 41 | HandlerFunc: a.HandleAuthorizationReq, 42 | }, { 43 | Pattern: AccessTokenPath, 44 | Method: http.MethodPost, 45 | HandlerFunc: a.HandleAccessTokenReq, 46 | }, 47 | } 48 | route.RegisterRoutes(apiGroup, routes) 49 | } 50 | -------------------------------------------------------------------------------- /core/http/api/v1/role/apis.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package role 16 | 17 | import ( 18 | "github.com/gin-gonic/gin" 19 | "github.com/horizoncd/horizon/core/controller/role" 20 | "github.com/horizoncd/horizon/pkg/server/response" 21 | ) 22 | 23 | type API struct { 24 | roleCtrl role.Controller 25 | } 26 | 27 | func NewAPI(controller role.Controller) *API { 28 | return &API{roleCtrl: controller} 29 | } 30 | 31 | func (a *API) ListRole(c *gin.Context) { 32 | roles, err := a.roleCtrl.ListRole(c) 33 | if err != nil { 34 | response.AbortWithInternalError(c, err.Error()) 35 | return 36 | } 37 | response.SuccessWithData(c, roles) 38 | } 39 | -------------------------------------------------------------------------------- /core/http/api/v1/role/routers.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package role 16 | 17 | import ( 18 | "net/http" 19 | 20 | "github.com/gin-gonic/gin" 21 | "github.com/horizoncd/horizon/pkg/server/route" 22 | ) 23 | 24 | // RegisterRoutes register routes 25 | func (api *API) RegisterRoute(engine *gin.Engine) { 26 | apiGroup := engine.Group("/apis/core/v1") 27 | 28 | var routes = route.Routes{ 29 | { 30 | Method: http.MethodGet, 31 | Pattern: "/roles", 32 | HandlerFunc: api.ListRole, 33 | }, 34 | } 35 | route.RegisterRoutes(apiGroup, routes) 36 | } 37 | -------------------------------------------------------------------------------- /core/http/api/v1/scope/apis.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package scope 16 | 17 | import ( 18 | "github.com/gin-gonic/gin" 19 | 20 | "github.com/horizoncd/horizon/core/controller/scope" 21 | "github.com/horizoncd/horizon/pkg/server/response" 22 | ) 23 | 24 | type API struct { 25 | scopeCtrl scope.Controller 26 | } 27 | 28 | func NewAPI(controller scope.Controller) *API { 29 | return &API{scopeCtrl: controller} 30 | } 31 | 32 | func (a *API) ListScopes(c *gin.Context) { 33 | scopes := a.scopeCtrl.ListScopes(c) 34 | response.SuccessWithData(c, scopes) 35 | } 36 | -------------------------------------------------------------------------------- /core/http/api/v1/scope/routers.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package scope 16 | 17 | import ( 18 | "net/http" 19 | 20 | "github.com/gin-gonic/gin" 21 | "github.com/horizoncd/horizon/pkg/server/route" 22 | ) 23 | 24 | // RegisterRoutes register routes 25 | func (api *API) RegisterRoute(engine *gin.Engine) { 26 | apiGroup := engine.Group("/apis/core/v1") 27 | 28 | var routes = route.Routes{ 29 | { 30 | Method: http.MethodGet, 31 | Pattern: "/scopes", 32 | HandlerFunc: api.ListScopes, 33 | }, 34 | } 35 | route.RegisterRoutes(apiGroup, routes) 36 | } 37 | -------------------------------------------------------------------------------- /core/http/api/v1/tag/routers.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package tag 16 | 17 | import ( 18 | "fmt" 19 | "net/http" 20 | 21 | "github.com/horizoncd/horizon/pkg/server/route" 22 | 23 | "github.com/gin-gonic/gin" 24 | ) 25 | 26 | func (api *API) RegisterRoute(engine *gin.Engine) { 27 | group := engine.Group("/apis/core/v1") 28 | var routes = route.Routes{ 29 | { 30 | Method: http.MethodGet, 31 | Pattern: fmt.Sprintf("/:%v/:%v/tags", _resourceTypeParam, _resourceIDParam), 32 | HandlerFunc: api.List, 33 | }, { 34 | Method: http.MethodPost, 35 | Pattern: fmt.Sprintf("/:%v/:%v/tags", _resourceTypeParam, _resourceIDParam), 36 | HandlerFunc: api.Update, 37 | }, { 38 | Method: http.MethodGet, 39 | Pattern: fmt.Sprintf("/:%v/:%v/subresourcetags", _resourceTypeParam, _resourceIDParam), 40 | HandlerFunc: api.ListSubResourceTags, 41 | }, 42 | } 43 | route.RegisterRoutes(group, routes) 44 | } 45 | -------------------------------------------------------------------------------- /core/http/api/v1/templateschematag/routes.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package templateschematag 16 | 17 | import ( 18 | "fmt" 19 | "net/http" 20 | 21 | "github.com/gin-gonic/gin" 22 | "github.com/horizoncd/horizon/pkg/server/route" 23 | ) 24 | 25 | func (api *API) RegisterRoute(engine *gin.Engine) { 26 | group := engine.Group("/apis/core/v1") 27 | var routes = route.Routes{ 28 | { 29 | Method: http.MethodGet, 30 | Pattern: fmt.Sprintf("/clusters/:%v/templateschematags", _clusterIDParam), 31 | HandlerFunc: api.List, 32 | }, { 33 | Method: http.MethodPost, 34 | Pattern: fmt.Sprintf("/clusters/:%v/templateschematags", _clusterIDParam), 35 | HandlerFunc: api.Update, 36 | }, 37 | } 38 | route.RegisterRoutes(group, routes) 39 | } 40 | -------------------------------------------------------------------------------- /core/http/api/v2/access/routers.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package access 16 | 17 | import ( 18 | "net/http" 19 | 20 | "github.com/horizoncd/horizon/pkg/server/route" 21 | 22 | "github.com/gin-gonic/gin" 23 | ) 24 | 25 | // RegisterRoutes register routes 26 | func (api *API) RegisterRoute(engine *gin.Engine) { 27 | frontGroup := engine.Group("/apis/front/v2") 28 | var frontRoutes = route.Routes{ 29 | { 30 | Method: http.MethodPost, 31 | Pattern: "/accessreview", 32 | HandlerFunc: api.AccessReview, 33 | }, 34 | } 35 | 36 | route.RegisterRoutes(frontGroup, frontRoutes) 37 | } 38 | -------------------------------------------------------------------------------- /core/http/api/v2/applicationregion/routers.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package applicationregion 16 | 17 | import ( 18 | "fmt" 19 | "net/http" 20 | 21 | "github.com/horizoncd/horizon/core/common" 22 | "github.com/horizoncd/horizon/pkg/server/route" 23 | 24 | "github.com/gin-gonic/gin" 25 | ) 26 | 27 | // RegisterRoutes register routes 28 | func (api *API) RegisterRoute(engine *gin.Engine) { 29 | apiGroup := engine.Group("/apis/core/v2") 30 | var routes = route.Routes{ 31 | { 32 | Method: http.MethodGet, 33 | Pattern: fmt.Sprintf("/applications/:%v/defaultregions", common.ParamApplicationID), 34 | HandlerFunc: api.List, 35 | }, 36 | { 37 | Method: http.MethodPost, 38 | Pattern: fmt.Sprintf("/applications/:%v/defaultregions", common.ParamApplicationID), 39 | HandlerFunc: api.Update, 40 | }, 41 | } 42 | 43 | route.RegisterRoutes(apiGroup, routes) 44 | } 45 | -------------------------------------------------------------------------------- /core/http/api/v2/badge/routers.go: -------------------------------------------------------------------------------- 1 | package badge 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | 7 | "github.com/gin-gonic/gin" 8 | 9 | "github.com/horizoncd/horizon/core/common" 10 | "github.com/horizoncd/horizon/pkg/server/route" 11 | ) 12 | 13 | func (a *API) RegisterRoute(engine *gin.Engine) { 14 | apiV2Group := engine.Group("/apis/core/v2") 15 | apiV2Routes := route.Routes{ 16 | { 17 | Method: http.MethodPost, 18 | Pattern: fmt.Sprintf("/:%v/:%v/badges", common.ParamResourceType, common.ParamResourceID), 19 | HandlerFunc: a.Create, 20 | }, 21 | { 22 | Method: http.MethodGet, 23 | Pattern: fmt.Sprintf("/:%v/:%v/badges", common.ParamResourceType, common.ParamResourceID), 24 | HandlerFunc: a.List, 25 | }, 26 | { 27 | Method: http.MethodGet, 28 | Pattern: fmt.Sprintf("/:%v/:%v/badges/:%v", 29 | common.ParamResourceType, common.ParamResourceID, _paramBadgeIDorName), 30 | HandlerFunc: a.Get, 31 | }, 32 | { 33 | Method: http.MethodPut, 34 | Pattern: fmt.Sprintf("/clusters/:%v/badges/:%v", 35 | common.ParamClusterID, _paramBadgeIDorName), 36 | HandlerFunc: a.UpdateClusterBadge, 37 | }, 38 | { 39 | Method: http.MethodDelete, 40 | Pattern: fmt.Sprintf("/:%v/:%v/badges/:%v", 41 | common.ParamResourceType, common.ParamResourceID, _paramBadgeIDorName), 42 | HandlerFunc: a.Delete, 43 | }, 44 | } 45 | route.RegisterRoutes(apiV2Group, apiV2Routes) 46 | } 47 | -------------------------------------------------------------------------------- /core/http/api/v2/build/apis.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package build 16 | 17 | import ( 18 | "github.com/gin-gonic/gin" 19 | "github.com/horizoncd/horizon/core/common" 20 | "github.com/horizoncd/horizon/core/controller/build" 21 | "github.com/horizoncd/horizon/pkg/server/response" 22 | "github.com/horizoncd/horizon/pkg/util/log" 23 | ) 24 | 25 | type API struct { 26 | buildCtl build.Controller 27 | } 28 | 29 | func NewAPI(buildCtl build.Controller) *API { 30 | return &API{buildCtl: buildCtl} 31 | } 32 | 33 | func (a *API) Get(c *gin.Context) { 34 | const op = "build: schemaGet" 35 | schema, err := a.buildCtl.GetSchema(c) 36 | if err != nil { 37 | log.WithFiled(c, "op", op).Errorf(err.Error()) 38 | response.AbortWithRequestError(c, common.InternalError, err.Error()) 39 | } 40 | response.SuccessWithData(c, schema) 41 | } 42 | -------------------------------------------------------------------------------- /core/http/api/v2/build/routers.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package build 16 | 17 | import ( 18 | "net/http" 19 | 20 | "github.com/gin-gonic/gin" 21 | "github.com/horizoncd/horizon/pkg/server/route" 22 | ) 23 | 24 | func (api *API) RegisterRoute(engine *gin.Engine) { 25 | apiV2Group := engine.Group("/apis/front/v2") 26 | apiV2Route := route.Routes{ 27 | { 28 | Method: http.MethodGet, 29 | Pattern: "buildschema", 30 | HandlerFunc: api.Get, 31 | }, 32 | } 33 | route.RegisterRoutes(apiV2Group, apiV2Route) 34 | } 35 | -------------------------------------------------------------------------------- /core/http/api/v2/code/routers.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package code 16 | 17 | import ( 18 | "net/http" 19 | 20 | "github.com/gin-gonic/gin" 21 | "github.com/horizoncd/horizon/pkg/server/route" 22 | ) 23 | 24 | func (api *API) RegisterRoute(engine *gin.Engine) { 25 | group := engine.Group("/apis/front/v2") 26 | var routes = route.Routes{ 27 | { 28 | Method: http.MethodGet, 29 | Pattern: "code/listbranch", 30 | HandlerFunc: api.ListBranch, 31 | }, 32 | { 33 | Method: http.MethodGet, 34 | Pattern: "code/listtag", 35 | HandlerFunc: api.ListTag, 36 | }, 37 | } 38 | route.RegisterRoutes(group, routes) 39 | } 40 | -------------------------------------------------------------------------------- /core/http/api/v2/environmentregion/routers.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package environmentregion 16 | 17 | import ( 18 | "fmt" 19 | "net/http" 20 | 21 | "github.com/gin-gonic/gin" 22 | "github.com/horizoncd/horizon/pkg/server/route" 23 | ) 24 | 25 | // RegisterRoutes register routes 26 | func (api *API) RegisterRoute(engine *gin.Engine) { 27 | apiGroup := engine.Group("/apis/core/v2/environmentregions") 28 | var routes = route.Routes{ 29 | { 30 | Method: http.MethodGet, 31 | HandlerFunc: api.List, 32 | }, { 33 | Method: http.MethodPost, 34 | HandlerFunc: api.Create, 35 | }, { 36 | Method: http.MethodPost, 37 | Pattern: fmt.Sprintf("/:%v/setdefault", _environmentRegionIDParam), 38 | HandlerFunc: api.SetDefault, 39 | }, { 40 | Method: http.MethodDelete, 41 | Pattern: fmt.Sprintf("/:%v", _environmentRegionIDParam), 42 | HandlerFunc: api.DeleteByID, 43 | }, 44 | } 45 | route.RegisterRoutes(apiGroup, routes) 46 | } 47 | -------------------------------------------------------------------------------- /core/http/api/v2/envtemplate/routers.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package envtemplate 16 | 17 | import ( 18 | "fmt" 19 | "net/http" 20 | 21 | "github.com/gin-gonic/gin" 22 | "github.com/horizoncd/horizon/pkg/server/route" 23 | ) 24 | 25 | // RegisterRoutes register routes 26 | func (api *API) RegisterRoute(engine *gin.Engine) { 27 | apiGroup := engine.Group("/apis/core/v2") 28 | var routes = route.Routes{ 29 | { 30 | Method: http.MethodGet, 31 | Pattern: fmt.Sprintf("/applications/:%v/envtemplates", _applicationIDParam), 32 | HandlerFunc: api.Get, 33 | }, 34 | { 35 | Method: http.MethodPost, 36 | Pattern: fmt.Sprintf("/applications/:%v/envtemplates", _applicationIDParam), 37 | HandlerFunc: api.Update, 38 | }, 39 | } 40 | route.RegisterRoutes(apiGroup, routes) 41 | } 42 | -------------------------------------------------------------------------------- /core/http/api/v2/event/apis.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package event 16 | 17 | import ( 18 | "github.com/horizoncd/horizon/core/controller/event" 19 | "github.com/horizoncd/horizon/pkg/server/response" 20 | 21 | "github.com/gin-gonic/gin" 22 | ) 23 | 24 | type API struct { 25 | eventCtl event.Controller 26 | } 27 | 28 | // NewAPI initializes a new event api 29 | func NewAPI(controller event.Controller) *API { 30 | return &API{ 31 | eventCtl: controller, 32 | } 33 | } 34 | 35 | // ListSupportEvents list actions categorized based on resources 36 | func (a *API) ListSupportEvents(c *gin.Context) { 37 | response.SuccessWithData(c, a.eventCtl.ListSupportEvents(c)) 38 | } 39 | -------------------------------------------------------------------------------- /core/http/api/v2/event/routers.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package event 16 | 17 | import ( 18 | "net/http" 19 | 20 | "github.com/horizoncd/horizon/pkg/server/route" 21 | 22 | "github.com/gin-gonic/gin" 23 | ) 24 | 25 | // RegisterRoutes register routes 26 | func (a *API) RegisterRoute(engine *gin.Engine) { 27 | coreAPI := engine.Group("/apis/core/v2") 28 | var coreRoutes = route.Routes{ 29 | { 30 | Pattern: "/supportevents", 31 | Method: http.MethodGet, 32 | HandlerFunc: a.ListSupportEvents, 33 | }, 34 | } 35 | 36 | route.RegisterRoutes(coreAPI, coreRoutes) 37 | } 38 | -------------------------------------------------------------------------------- /core/http/api/v2/role/apis.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package role 16 | 17 | import ( 18 | "github.com/gin-gonic/gin" 19 | "github.com/horizoncd/horizon/core/controller/role" 20 | "github.com/horizoncd/horizon/pkg/server/response" 21 | ) 22 | 23 | type API struct { 24 | roleCtrl role.Controller 25 | } 26 | 27 | func NewAPI(controller role.Controller) *API { 28 | return &API{roleCtrl: controller} 29 | } 30 | 31 | func (a *API) ListRole(c *gin.Context) { 32 | roles, err := a.roleCtrl.ListRole(c) 33 | if err != nil { 34 | response.AbortWithInternalError(c, err.Error()) 35 | return 36 | } 37 | response.SuccessWithData(c, roles) 38 | } 39 | -------------------------------------------------------------------------------- /core/http/api/v2/role/routers.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package role 16 | 17 | import ( 18 | "net/http" 19 | 20 | "github.com/gin-gonic/gin" 21 | "github.com/horizoncd/horizon/pkg/server/route" 22 | ) 23 | 24 | // RegisterRoutes register routes 25 | func (api *API) RegisterRoute(engine *gin.Engine) { 26 | apiGroup := engine.Group("/apis/core/v2") 27 | 28 | var routes = route.Routes{ 29 | { 30 | Method: http.MethodGet, 31 | Pattern: "/roles", 32 | HandlerFunc: api.ListRole, 33 | }, 34 | } 35 | route.RegisterRoutes(apiGroup, routes) 36 | } 37 | -------------------------------------------------------------------------------- /core/http/api/v2/scope/apis.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package scope 16 | 17 | import ( 18 | "github.com/gin-gonic/gin" 19 | 20 | "github.com/horizoncd/horizon/core/controller/scope" 21 | "github.com/horizoncd/horizon/pkg/server/response" 22 | ) 23 | 24 | type API struct { 25 | scopeCtrl scope.Controller 26 | } 27 | 28 | func NewAPI(controller scope.Controller) *API { 29 | return &API{scopeCtrl: controller} 30 | } 31 | 32 | func (a *API) ListScopes(c *gin.Context) { 33 | scopes := a.scopeCtrl.ListScopes(c) 34 | response.SuccessWithData(c, scopes) 35 | } 36 | -------------------------------------------------------------------------------- /core/http/api/v2/scope/routers.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package scope 16 | 17 | import ( 18 | "net/http" 19 | 20 | "github.com/gin-gonic/gin" 21 | "github.com/horizoncd/horizon/pkg/server/route" 22 | ) 23 | 24 | // RegisterRoutes register routes 25 | func (api *API) RegisterRoute(engine *gin.Engine) { 26 | apiGroup := engine.Group("/apis/core/v2") 27 | 28 | var routes = route.Routes{ 29 | { 30 | Method: http.MethodGet, 31 | Pattern: "/scopes", 32 | HandlerFunc: api.ListScopes, 33 | }, 34 | } 35 | route.RegisterRoutes(apiGroup, routes) 36 | } 37 | -------------------------------------------------------------------------------- /core/http/api/v2/templateschematag/routes.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package templateschematag 16 | 17 | import ( 18 | "fmt" 19 | "net/http" 20 | 21 | "github.com/gin-gonic/gin" 22 | "github.com/horizoncd/horizon/pkg/server/route" 23 | ) 24 | 25 | func (api *API) RegisterRoute(engine *gin.Engine) { 26 | group := engine.Group("/apis/core/v2") 27 | var routes = route.Routes{ 28 | { 29 | Method: http.MethodGet, 30 | Pattern: fmt.Sprintf("/clusters/:%v/templateschematags", _clusterIDParam), 31 | HandlerFunc: api.List, 32 | }, { 33 | Method: http.MethodPost, 34 | Pattern: fmt.Sprintf("/clusters/:%v/templateschematags", _clusterIDParam), 35 | HandlerFunc: api.Update, 36 | }, 37 | } 38 | route.RegisterRoutes(group, routes) 39 | } 40 | -------------------------------------------------------------------------------- /core/http/api/v2/terminal/routers.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package terminal 16 | 17 | import ( 18 | "fmt" 19 | "net/http" 20 | 21 | "github.com/horizoncd/horizon/pkg/server/route" 22 | 23 | "github.com/gin-gonic/gin" 24 | ) 25 | 26 | // RegisterRoutes register routes 27 | func (api *API) RegisterRoute(engine *gin.Engine) { 28 | coreGroup := engine.Group("/apis/core/v2") 29 | var coreRoutes = route.Routes{ 30 | { 31 | Method: http.MethodGet, 32 | Pattern: fmt.Sprintf("/clusters/:%v/shell", _clusterIDParam), 33 | HandlerFunc: api.CreateShell, 34 | }, 35 | } 36 | route.RegisterRoutes(coreGroup, coreRoutes) 37 | } 38 | -------------------------------------------------------------------------------- /core/http/cloudevent/routers.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package cloudevent 16 | 17 | import ( 18 | "net/http" 19 | 20 | "github.com/gin-gonic/gin" 21 | "github.com/horizoncd/horizon/pkg/server/route" 22 | ) 23 | 24 | func RegisterRoutes(engine *gin.Engine, api *API) { 25 | group := engine.Group("/apis/internal") 26 | var routes = route.Routes{ 27 | { 28 | Method: http.MethodPost, 29 | Pattern: "/cloudevents", 30 | HandlerFunc: api.CloudEvent, 31 | }, 32 | } 33 | route.RegisterRoutes(group, routes) 34 | } 35 | -------------------------------------------------------------------------------- /core/http/health/routers.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package health 16 | 17 | import ( 18 | "net/http" 19 | 20 | "github.com/gin-gonic/gin" 21 | "github.com/horizoncd/horizon/pkg/server/response" 22 | "github.com/horizoncd/horizon/pkg/server/route" 23 | ) 24 | 25 | // RegisterRoutes register routes 26 | func RegisterRoutes(engine *gin.Engine) { 27 | api := engine.Group("/health") 28 | 29 | var routes = route.Routes{ 30 | { 31 | Method: http.MethodGet, 32 | HandlerFunc: healthCheck, 33 | }, 34 | } 35 | route.RegisterRoutes(api, routes) 36 | } 37 | 38 | func healthCheck(c *gin.Context) { 39 | response.Success(c) 40 | } 41 | -------------------------------------------------------------------------------- /core/http/metrics/routers.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package metrics 16 | 17 | import ( 18 | "net/http" 19 | 20 | "github.com/horizoncd/horizon/pkg/server/route" 21 | 22 | "github.com/gin-gonic/gin" 23 | "github.com/prometheus/client_golang/prometheus/promhttp" 24 | ) 25 | 26 | func RegisterRoutes(engine *gin.Engine) { 27 | api := engine.Group("/metrics") 28 | 29 | var routes = route.Routes{ 30 | { 31 | Method: http.MethodGet, 32 | HandlerFunc: gin.WrapH(promhttp.Handler()), 33 | }, 34 | } 35 | route.RegisterRoutes(api, routes) 36 | } 37 | -------------------------------------------------------------------------------- /core/main.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | _ "net/http/pprof" 19 | 20 | "github.com/horizoncd/horizon/core/cmd" 21 | 22 | // for image registry 23 | _ "github.com/horizoncd/horizon/pkg/cluster/registry/harbor/v1" 24 | _ "github.com/horizoncd/horizon/pkg/cluster/registry/harbor/v2" 25 | 26 | _ "github.com/horizoncd/horizon/pkg/git" 27 | _ "github.com/horizoncd/horizon/pkg/git/github" 28 | _ "github.com/horizoncd/horizon/pkg/git/gitlab" 29 | 30 | // for template repo 31 | _ "github.com/horizoncd/horizon/pkg/templaterepo/chartmuseumbase" 32 | 33 | // for k8s workload 34 | _ "github.com/horizoncd/horizon/pkg/workload/deployment" 35 | _ "github.com/horizoncd/horizon/pkg/workload/kservice" 36 | _ "github.com/horizoncd/horizon/pkg/workload/pod" 37 | _ "github.com/horizoncd/horizon/pkg/workload/rollout" 38 | _ "github.com/horizoncd/horizon/pkg/workload/statefulset" 39 | ) 40 | 41 | func main() { 42 | cmd.Run(cmd.ParseFlags()) 43 | } 44 | -------------------------------------------------------------------------------- /core/middleware/log/log.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package log 16 | 17 | import ( 18 | "github.com/gin-gonic/gin" 19 | middleware "github.com/horizoncd/horizon/core/middleware" 20 | "github.com/horizoncd/horizon/core/middleware/requestid" 21 | "github.com/horizoncd/horizon/pkg/util/log" 22 | ) 23 | 24 | // Middleware add logger to context 25 | func Middleware(skippers ...middleware.Skipper) gin.HandlerFunc { 26 | return middleware.New(func(c *gin.Context) { 27 | rid := c.Value(requestid.HeaderXRequestID) 28 | if rid != "" { 29 | c.Set(log.Key(), rid) 30 | } 31 | c.Next() 32 | }, skippers...) 33 | } 34 | -------------------------------------------------------------------------------- /core/middleware/middleware.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package middleware 16 | 17 | import ( 18 | "github.com/gin-gonic/gin" 19 | ) 20 | 21 | // New make a middleware 22 | func New(handler gin.HandlerFunc, skippers ...Skipper) gin.HandlerFunc { 23 | return func(c *gin.Context) { 24 | for _, skipper := range skippers { 25 | if skipper(c.Request) { 26 | c.Next() 27 | return 28 | } 29 | } 30 | handler(c) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /core/middleware/skipper.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package middleware 16 | 17 | import ( 18 | "net/http" 19 | "path" 20 | "regexp" 21 | ) 22 | 23 | // Skipper defines a function to skip middleware. 24 | // Returning true skips processing the middleware. 25 | type Skipper func(*http.Request) bool 26 | 27 | // MethodAndPathSkipper returns skipper which 28 | // will skip the middleware when r.Method equals the method and r.URL.Path matches the re 29 | // when method is "*" it equals all http method 30 | func MethodAndPathSkipper(method string, re *regexp.Regexp) Skipper { 31 | return func(r *http.Request) bool { 32 | path := path.Clean(r.URL.EscapedPath()) 33 | if (method == "*" || r.Method == method) && re.MatchString(path) { 34 | return true 35 | } 36 | return false 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /core/middleware/tag/tag_test.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package tag 16 | 17 | import ( 18 | "net/http" 19 | "testing" 20 | 21 | "github.com/gin-gonic/gin" 22 | "github.com/horizoncd/horizon/core/common" 23 | "github.com/horizoncd/horizon/pkg/tag/models" 24 | "github.com/stretchr/testify/assert" 25 | ) 26 | 27 | func TestMiddleware(t *testing.T) { 28 | f := Middleware() 29 | expected := map[string][]string{ 30 | "a": {"b"}, 31 | "c": {"d"}, 32 | } 33 | 34 | // %3d -> "=" 35 | // %2c -> "," 36 | req, err := http.NewRequest(http.MethodGet, "/?tagSelector=a%3db%2cc%3dd", nil) 37 | assert.Nil(t, err) 38 | ctx := &gin.Context{} 39 | ctx.Request = req 40 | f(ctx) 41 | 42 | tssi, ok := ctx.Get(common.TagSelector) 43 | assert.True(t, ok) 44 | 45 | tss, ok := tssi.([]models.TagSelector) 46 | assert.True(t, ok) 47 | 48 | for _, ts := range tss { 49 | v, ok := expected[ts.Key] 50 | assert.True(t, ok) 51 | assert.Equal(t, v, ts.Values.List()) 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /db/migrations/20211124_add_cluster_status.up.sql: -------------------------------------------------------------------------------- 1 | -- Copyright © 2023 Horizoncd. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | -- add status column for cluster table 16 | ALTER TABLE cluster ADD status varchar(64) NULL; -------------------------------------------------------------------------------- /db/migrations/20211125_add_cluster_template_schema_tag.up.sql: -------------------------------------------------------------------------------- 1 | -- Copyright © 2023 Horizoncd. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | -- cluster template schema tag table 16 | CREATE TABLE `cluster_template_schema_tag` 17 | ( 18 | `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, 19 | `cluster_id` bigint(20) unsigned NOT NULL COMMENT 'cluster id', 20 | `tag_key` varchar(64) NOT NULL DEFAULT '' COMMENT 'key of tag', 21 | `tag_value` varchar(1280) NOT NULL DEFAULT '' COMMENT 'value of tag', 22 | `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, 23 | `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, 24 | `created_by` bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT 'creator', 25 | `updated_by` bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT 'updater', 26 | PRIMARY KEY (`id`), 27 | KEY `idx_key` (`tag_key`), 28 | UNIQUE KEY `idx_cluster_id_key` (`cluster_id`, `tag_key`) 29 | ) ENGINE = InnoDB 30 | AUTO_INCREMENT = 1 31 | DEFAULT CHARSET = utf8mb4; 32 | -------------------------------------------------------------------------------- /db/migrations/20220506_add_k8s_region.sql: -------------------------------------------------------------------------------- 1 | -- Copyright © 2023 Horizoncd. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | -- merge k8s_cluster to region 16 | ALTER TABLE tb_region ADD server varchar(256) NULL COMMENT 'k8s server url' AFTER display_name; 17 | ALTER TABLE tb_region ADD certificate text NULL COMMENT 'k8s kube config' AFTER server; 18 | ALTER TABLE tb_region ADD ingress_domain text NULL COMMENT 'k8s ingress domain' AFTER certificate; 19 | 20 | -- add default_region to environment 21 | ALTER TABLE tb_environment ADD default_region varchar(128) NULL COMMENT 'default region of the environment' AFTER display_name; 22 | -------------------------------------------------------------------------------- /db/migrations/20220517_add_field_to_environment_region.sql: -------------------------------------------------------------------------------- 1 | -- Copyright © 2023 Horizoncd. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | -- set region to be default 16 | ALTER TABLE horizon.tb_environment_region ADD is_default tinyint(1) NOT NULL DEFAULT 0 COMMENT '0 means not default region, 1 means default region' AFTER region_name; 17 | 18 | -- this field is not used anymore 19 | Alter TABLE horizon.tb_region DROP k8s_cluster_id; 20 | 21 | -- all fields has been moved to tb_region, this table can be dropped 22 | DROP TABLE horizon.tb_k8s_cluster; 23 | 24 | -- add name field to harbor 25 | ALTER TABLE horizon.tb_harbor ADD name varchar(128) NOT NULL DEFAULT '' COMMENT 'name of the harbor registry' AFTER id; 26 | -------------------------------------------------------------------------------- /db/migrations/20220519_reactor_clustertag_to_tag.sql: -------------------------------------------------------------------------------- 1 | -- Copyright © 2023 Horizoncd. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | -- add resource_type field to tb_tag, and update to "cluster" 16 | ALTER TABLE `horizon`.`tb_cluster_tag` ADD resource_type varchar(64) NOT NULL DEFAULT "" COMMENT 'resource type' AFTER cluster_id; 17 | update `horizon`.`tb_cluster_tag` set resource_type="clusters"; 18 | 19 | -- add new index and remove old index 20 | CREATE UNIQUE INDEX idx_resource_key ON `horizon`.`tb_cluster_tag` (`resource_type`, `cluster_id`, `tag_key`); 21 | DROP INDEX idx_cluster_id_key ON `horizon`.`tb_cluster_tag`; 22 | 23 | -- rename cluster_id field to resource_id 24 | ALTER TABLE `horizon`.`tb_cluster_tag` CHANGE `cluster_id` `resource_id` bigint(20) unsigned NOT NULL COMMENT 'resource id'; 25 | 26 | -- rename tb_cluster_tag to tb_tag 27 | alter table `horizon`.`tb_cluster_tag` rename to `horizon`.`tb_tag`; -------------------------------------------------------------------------------- /db/migrations/20220520_cluster_add_env_.sql: -------------------------------------------------------------------------------- 1 | -- Copyright © 2023 Horizoncd. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | alter table tb_cluster 16 | add environment_name varchar(128) default '' not null after name; 17 | alter table tb_cluster 18 | add region_name varchar(128) default '' not null after environment_name; 19 | -------------------------------------------------------------------------------- /db/migrations/20220712_git_ref.sql: -------------------------------------------------------------------------------- 1 | -- Copyright © 2023 Horizoncd. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | ALTER TABLE horizon.tb_pipelinerun ADD git_ref varchar(128) NULL after git_branch; 16 | ALTER TABLE horizon.tb_cluster ADD git_ref varchar(128) NULL after git_branch; 17 | ALTER TABLE horizon.tb_application ADD git_ref varchar(128) NULL after git_branch; 18 | 19 | ALTER TABLE horizon.tb_pipelinerun ADD git_ref_type varchar(64) NULL after git_ref; 20 | ALTER TABLE horizon.tb_cluster ADD git_ref_type varchar(64) NULL after git_ref; 21 | ALTER TABLE horizon.tb_application ADD git_ref_type varchar(64) NULL after git_ref; 22 | 23 | UPDATE horizon.tb_cluster set git_ref_type = 'branch'; 24 | UPDATE horizon.tb_application set git_ref_type = 'branch'; 25 | UPDATE horizon.tb_pipelinerun set git_ref_type = 'branch'; 26 | 27 | UPDATE horizon.tb_cluster set git_ref = git_branch; 28 | UPDATE horizon.tb_application set git_ref = git_branch; 29 | UPDATE horizon.tb_pipelinerun set git_ref = git_branch; -------------------------------------------------------------------------------- /db/migrations/20220824_template_add_columns_owner_only.sql: -------------------------------------------------------------------------------- 1 | -- Copyright © 2023 Horizoncd. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | alter table `tb_template` add column `only_owner` boolean not null default false comment 'only owner could access'; 16 | alter table `tb_template_release` add column `only_owner` boolean not null default false comment 'only owner could access'; 17 | -------------------------------------------------------------------------------- /db/migrations/20220908_add_prometheus_url.sql: -------------------------------------------------------------------------------- 1 | -- Copyright © 2023 Horizoncd. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | alter table tb_region add column prometheus_url varchar(128) comment 'prometheus url'; 16 | -------------------------------------------------------------------------------- /db/migrations/20220921_add_auto_free.sql: -------------------------------------------------------------------------------- 1 | -- Copyright © 2023 Horizoncd. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | ALTER TABLE tb_environment 16 | ADD auto_free tinyint(1) NOT NULL DEFAULT 0 COMMENT 'auto free configuration, 0 means disabled'; 17 | ALTER TABLE tb_cluster 18 | ADD expire_seconds bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT 'expiration seconds, 0 means permanent'; -------------------------------------------------------------------------------- /db/migrations/20221101_add_template_ci.sql: -------------------------------------------------------------------------------- 1 | -- Copyright © 2023 Horizoncd. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | ALTER TABLE tb_template 16 | ADD without_ci tinyint(1) NOT NULL DEFAULT 0 COMMENT 'without_ci configuration, 0 means with ci'; -------------------------------------------------------------------------------- /db/migrations/20221103_add_user_type.sql: -------------------------------------------------------------------------------- 1 | -- Copyright © 2023 Horizoncd. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | ALTER TABLE 16 | tb_user 17 | ADD 18 | column `created_by` bigint(20) unsigned NOT NULL DEFAULT 0, 19 | ADD 20 | column `user_type` tinyint(1) unsigned NOT NULL DEFAULT 0 COMMENT 'the option type is: 0 (common user), 1(robot user)'; 21 | 22 | ALTER TABLE 23 | tb_token 24 | ADD 25 | column `name` varchar(64) NOT NULL DEFAULT '', 26 | ADD 27 | column `user_id` bigint(20) unsigned NOT NULL DEFAULT '0', 28 | ADD 29 | column `created_by` bigint(20) unsigned NOT NULL DEFAULT '0'; -------------------------------------------------------------------------------- /db/migrations/20221110_add_user_password.sql: -------------------------------------------------------------------------------- 1 | -- Copyright © 2023 Horizoncd. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | ALTER TABLE tb_user ADD COLUMN `password` varchar(256) NOT NULL DEFAULT '' COMMENT 'password of user'; -------------------------------------------------------------------------------- /db/migrations/20221130_add_event_id.sql: -------------------------------------------------------------------------------- 1 | -- Copyright © 2023 Horizoncd. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | ALTER TABLE tb_pipelinerun 16 | ADD column `ci_event_id` varchar(36) NOT NULL DEFAULT '', 17 | ADD INDEX idx_ci_event_id (`ci_event_id`); 18 | -------------------------------------------------------------------------------- /db/migrations/20230302_add_event_extra.sql: -------------------------------------------------------------------------------- 1 | -- Copyright © 2023 Horizoncd. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | ALTER TABLE tb_event 16 | ADD COLUMN extra varchar(255) NOT NULL DEFAULT '' 17 | COMMENT 'extra infos to describe the event' -------------------------------------------------------------------------------- /db/migrations/20230512_add_metatag_table.sql: -------------------------------------------------------------------------------- 1 | -- Copyright © 2023 Horizoncd. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | -- metatag table 16 | CREATE TABLE `tb_metatag` 17 | ( 18 | `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, 19 | `tag_key` varchar(64) NOT NULL DEFAULT '' comment 'key of the metatag', 20 | `tag_value` varchar(128) NOT NULL DEFAULT '' comment 'value of the metatag', 21 | `description` varchar(64) NOT NULL DEFAULT '' comment 'description', 22 | `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, 23 | `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, 24 | PRIMARY KEY (`id`), 25 | UNIQUE KEY `idx_key_value` (`tag_key`, `tag_value`) 26 | ) ENGINE = InnoDB 27 | AUTO_INCREMENT = 1 28 | DEFAULT CHARSET = utf8mb4; 29 | -------------------------------------------------------------------------------- /db/migrations/20230515_add_image_to_app.sql: -------------------------------------------------------------------------------- 1 | -- Copyright © 2023 Horizoncd. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | ALTER TABLE tb_application 16 | ADD COLUMN `image` varchar(256) DEFAULT NULL 17 | COMMENT 'artifact image url for the application'; 18 | 19 | ALTER TABLE tb_cluster 20 | ADD COLUMN `image` varchar(256) DEFAULT NULL 21 | COMMENT 'artifact image url for the cluster'; 22 | -------------------------------------------------------------------------------- /db/migrations/20230710_add_ref_id_to_token.sql: -------------------------------------------------------------------------------- 1 | -- Copyright © 2023 Horizoncd. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | ALTER TABLE tb_token 16 | ADD COLUMN `ref_id` bigint(20) unsigned null 17 | COMMENT 'id associated to the access token for refresh token'; 18 | -------------------------------------------------------------------------------- /db/migrations/20240130_add_system_to_pr_msg.sql: -------------------------------------------------------------------------------- 1 | -- Copyright © 2023 Horizoncd. 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); 4 | -- you may not use this file except in compliance with the License. 5 | -- You may obtain a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, 11 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | -- See the License for the specific language governing permissions and 13 | -- limitations under the License. 14 | 15 | ALTER TABLE tb_pr_msg 16 | ADD COLUMN `message_type` tinyint(1) unsigned NOT NULL DEFAULT 0 17 | COMMENT '0 for user message, 1 for system message'; 18 | -------------------------------------------------------------------------------- /image/DEVELOPMENT/core-debug.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/horizoncd/horizon/6cdb919ad8a131dc1c0d97eda435e34d08dc29b1/image/DEVELOPMENT/core-debug.png -------------------------------------------------------------------------------- /image/DEVELOPMENT/core-running.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/horizoncd/horizon/6cdb919ad8a131dc1c0d97eda435e34d08dc29b1/image/DEVELOPMENT/core-running.png -------------------------------------------------------------------------------- /image/DEVELOPMENT/nocalhost-active.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/horizoncd/horizon/6cdb919ad8a131dc1c0d97eda435e34d08dc29b1/image/DEVELOPMENT/nocalhost-active.png -------------------------------------------------------------------------------- /image/DEVELOPMENT/nocalhost-add.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/horizoncd/horizon/6cdb919ad8a131dc1c0d97eda435e34d08dc29b1/image/DEVELOPMENT/nocalhost-add.png -------------------------------------------------------------------------------- /image/DEVELOPMENT/nocalhost-extension.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/horizoncd/horizon/6cdb919ad8a131dc1c0d97eda435e34d08dc29b1/image/DEVELOPMENT/nocalhost-extension.png -------------------------------------------------------------------------------- /image/DEVELOPMENT/nocalhost-remote-debug.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/horizoncd/horizon/6cdb919ad8a131dc1c0d97eda435e34d08dc29b1/image/DEVELOPMENT/nocalhost-remote-debug.png -------------------------------------------------------------------------------- /image/DEVELOPMENT/nocalhost-workload.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/horizoncd/horizon/6cdb919ad8a131dc1c0d97eda435e34d08dc29b1/image/DEVELOPMENT/nocalhost-workload.png -------------------------------------------------------------------------------- /image/DEVELOPMENT/web-debug.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/horizoncd/horizon/6cdb919ad8a131dc1c0d97eda435e34d08dc29b1/image/DEVELOPMENT/web-debug.png -------------------------------------------------------------------------------- /image/DEVELOPMENT/web-running.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/horizoncd/horizon/6cdb919ad8a131dc1c0d97eda435e34d08dc29b1/image/DEVELOPMENT/web-running.png -------------------------------------------------------------------------------- /image/readme/wechat.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/horizoncd/horizon/6cdb919ad8a131dc1c0d97eda435e34d08dc29b1/image/readme/wechat.jpg -------------------------------------------------------------------------------- /openapi/v1/front/common.yaml: -------------------------------------------------------------------------------- 1 | # Copyright © 2023 Horizoncd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | components: 16 | parameters: 17 | pageNumber: 18 | name: pageNumber 19 | in: query 20 | pageSize: 21 | name: pageSize 22 | in: query 23 | 24 | schemas: 25 | PageParams: 26 | type: object 27 | properties: 28 | current: 29 | type: number 30 | pageSize: 31 | type: number 32 | 33 | Error: 34 | type: object 35 | required: 36 | - code 37 | - message 38 | properties: 39 | code: 40 | type: string 41 | message: 42 | type: string 43 | requestId: 44 | type: string 45 | -------------------------------------------------------------------------------- /openapi/v1/front/terminal.yaml: -------------------------------------------------------------------------------- 1 | # Copyright © 2023 Horizoncd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | openapi: 3.0.1 16 | info: 17 | title: Horizon-Terminal-Front 18 | description: Front API About Terminal 19 | version: 1.0.0 20 | servers: 21 | - url: 'http://localhost:8080/' 22 | paths: 23 | /apis/front/v1/terminal/{terminalID}/websocket: 24 | parameters: 25 | - name: terminalID 26 | in: path 27 | description: id of terminal session 28 | required: true 29 | get: 30 | tags: 31 | - terminal 32 | operationId: connectTerminal 33 | summary: connect to terminal 34 | responses: 35 | '200': 36 | description: Succuss 37 | default: 38 | description: Unexpected error 39 | content: 40 | application/json: 41 | schema: 42 | $ref: "common.yaml#/components/schemas/Error" -------------------------------------------------------------------------------- /openapi/v2/restful/scope.yaml: -------------------------------------------------------------------------------- 1 | # Copyright © 2023 Horizoncd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | openapi: 3.0.1 16 | info: 17 | title: Horizon Scope Restful 18 | version: 2.0.0 19 | servers: 20 | - url: 'http://localhost:8080/' 21 | paths: 22 | /apis/core/v2/scopes: 23 | get: 24 | tags: 25 | - scope 26 | description: list scopes 27 | operationId: listScopes 28 | responses: 29 | '200': 30 | description: Success 31 | content: 32 | application/json: 33 | schema: 34 | properties: 35 | data: 36 | type: array 37 | items: 38 | properties: 39 | name: 40 | type: string 41 | description: name of scope 42 | desc: 43 | type: string 44 | description: description of scope -------------------------------------------------------------------------------- /pkg/accesstoken/models/models.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package models 16 | 17 | import ( 18 | tokenmodels "github.com/horizoncd/horizon/pkg/token/models" 19 | ) 20 | 21 | type AccessToken struct { 22 | tokenmodels.Token 23 | Role string 24 | } 25 | -------------------------------------------------------------------------------- /pkg/admission/models/models.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | import "strings" 4 | 5 | type Kind string 6 | 7 | func (k Kind) String() string { 8 | return strings.ToLower(string(k)) 9 | } 10 | 11 | func (k Kind) Eq(other Kind) bool { 12 | return strings.EqualFold(string(k), string(other)) 13 | } 14 | 15 | type Operation string 16 | 17 | func (o Operation) Eq(other Operation) bool { 18 | return strings.EqualFold(string(o), string(other)) 19 | } 20 | 21 | const ( 22 | KindValidating Kind = "validating" 23 | KindMutating Kind = "mutating" 24 | 25 | MatchAll string = "*" 26 | 27 | OperationCreate Operation = "create" 28 | OperationUpdate Operation = "update" 29 | 30 | PatchTypeJSONPatch = "JSONPatch" 31 | ) 32 | -------------------------------------------------------------------------------- /pkg/application/models/application.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package models 16 | 17 | import ( 18 | "github.com/horizoncd/horizon/pkg/server/global" 19 | ) 20 | 21 | type Priority string 22 | 23 | const ( 24 | P0 Priority = "P0" 25 | P1 Priority = "P1" 26 | P2 Priority = "P2" 27 | P3 Priority = "P3" 28 | ) 29 | 30 | type Application struct { 31 | global.Model 32 | GroupID uint 33 | Name string 34 | Description string 35 | Priority Priority 36 | GitURL string 37 | GitSubfolder string 38 | GitRef string 39 | GitRefType string 40 | Image string 41 | Template string 42 | TemplateRelease string 43 | CreatedBy uint 44 | UpdatedBy uint 45 | } 46 | -------------------------------------------------------------------------------- /pkg/application/service/models.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package service 16 | 17 | import ( 18 | applicationmodels "github.com/horizoncd/horizon/pkg/application/models" 19 | ) 20 | 21 | // ApplicationDetail contains the fullPath 22 | type ApplicationDetail struct { 23 | applicationmodels.Application 24 | FullPath string 25 | FullName string 26 | } 27 | -------------------------------------------------------------------------------- /pkg/applicationregion/models/applicationregion.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package models 16 | 17 | import "time" 18 | 19 | type ApplicationRegion struct { 20 | ID uint 21 | ApplicationID uint `gorm:"uniqueIndex:idx_application_environment"` 22 | EnvironmentName string `gorm:"uniqueIndex:idx_application_environment"` 23 | RegionName string 24 | CreatedAt time.Time 25 | UpdatedAt time.Time 26 | CreatedBy uint 27 | UpdatedBy uint 28 | } 29 | -------------------------------------------------------------------------------- /pkg/badge/models/models.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | import ( 4 | "github.com/horizoncd/horizon/pkg/server/global" 5 | ) 6 | 7 | type Badge struct { 8 | global.Model 9 | ID uint `gorm:"primary_key"` 10 | ResourceID uint `gorm:"uniqueIndex:idx_resource_name"` 11 | ResourceType string `gorm:"uniqueIndex:idx_resource_name"` 12 | Name string `gorm:"uniqueIndex:idx_resource_name"` 13 | SvgLink string `gorm:"column:svg_link"` 14 | RedirectLink string `gorm:"column:redirect_link"` 15 | CreatedBy uint 16 | UpdatedBy uint 17 | } 18 | -------------------------------------------------------------------------------- /pkg/cd/legacycd.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package cd 16 | 17 | import "context" 18 | 19 | // nolint 20 | // 21 | //go:generate mockgen -source=$GOFILE -destination=../../mock/pkg/cd/lagacycd_mock.go -package=mock_cd -aux_files=github.com/horizoncd/horizon/pkg/cd=cd.go 22 | type LegacyCD interface { 23 | CD 24 | 25 | GetClusterStateV1(ctx context.Context, params *GetClusterStateParams) (*ClusterState, error) 26 | } 27 | -------------------------------------------------------------------------------- /pkg/cluster/models/cluster.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package models 16 | 17 | import ( 18 | "github.com/horizoncd/horizon/pkg/server/global" 19 | "github.com/horizoncd/horizon/pkg/tag/models" 20 | ) 21 | 22 | type Cluster struct { 23 | global.Model 24 | 25 | ApplicationID uint 26 | Name string 27 | EnvironmentName string 28 | RegionName string 29 | Description string 30 | Type *string `gorm:"->"` 31 | GitURL string 32 | GitSubfolder string 33 | GitRef string 34 | GitRefType string 35 | Image string 36 | Template string 37 | TemplateRelease string 38 | Status string 39 | CreatedBy uint 40 | UpdatedBy uint 41 | ExpireSeconds uint 42 | } 43 | 44 | type ClusterWithTags struct { 45 | *Cluster 46 | Tags []*models.Tag 47 | } 48 | 49 | type ClusterWithRegion struct { 50 | *Cluster 51 | 52 | RegionDisplayName string 53 | } 54 | -------------------------------------------------------------------------------- /pkg/cluster/service/models.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package service 16 | 17 | import ( 18 | clustermodels "github.com/horizoncd/horizon/pkg/cluster/models" 19 | ) 20 | 21 | // ClusterDetail contains the fullPath 22 | type ClusterDetail struct { 23 | clustermodels.Cluster 24 | FullPath string 25 | } 26 | -------------------------------------------------------------------------------- /pkg/cluster/tekton/log/log.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2019 The Tekton Authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // fork from https://github.com/tektoncd/cli/blob/v0.13.1/pkg/log/log.go 16 | 17 | package log 18 | 19 | const ( 20 | LogTypePipeline = "pipeline" 21 | LogTypeTask = "task" 22 | ) 23 | 24 | // Log represents data to write on log channel 25 | type Log struct { 26 | Pipeline string 27 | Task string 28 | Step string 29 | Log string 30 | } 31 | -------------------------------------------------------------------------------- /pkg/cluster/tekton/tekton_test.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package tekton 16 | 17 | import ( 18 | "os" 19 | "testing" 20 | 21 | tektonconfig "github.com/horizoncd/horizon/pkg/config/tekton" 22 | 23 | "github.com/stretchr/testify/assert" 24 | ) 25 | 26 | func TestNewTekton(t *testing.T) { 27 | tektonConfig := &tektonconfig.Tekton{ 28 | Kubeconfig: "/", 29 | } 30 | tekton, err := NewTekton(tektonConfig) 31 | assert.Nil(t, tekton) 32 | assert.NotNil(t, err) 33 | 34 | tektonConfig = &tektonconfig.Tekton{ 35 | Kubeconfig: "", 36 | } 37 | tekton, err = NewTekton(tektonConfig) 38 | host, port := os.Getenv("KUBERNETES_SERVICE_HOST"), os.Getenv("KUBERNETES_SERVICE_PORT") 39 | if len(host) == 0 || len(port) == 0 { 40 | assert.Nil(t, tekton) 41 | assert.NotNil(t, err) 42 | } else { 43 | assert.NotNil(t, tekton) 44 | assert.Nil(t, err) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /pkg/collection/models/models.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package models 16 | 17 | type Collection struct { 18 | ID uint `gorm:"primarykey"` 19 | 20 | ResourceID uint `gorm:"column:resource_id"` 21 | ResourceType string 22 | UserID uint `gorm:"column:user_id"` 23 | } 24 | -------------------------------------------------------------------------------- /pkg/common/models.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package common 16 | 17 | type Manifest struct { 18 | // TODO(encode the template info into manifest),currently only the Version 19 | Version string `yaml:"version" json:"version"` 20 | } 21 | -------------------------------------------------------------------------------- /pkg/config/admission/config.go: -------------------------------------------------------------------------------- 1 | package admission 2 | 3 | import ( 4 | "strings" 5 | "time" 6 | 7 | "github.com/horizoncd/horizon/pkg/admission/models" 8 | ) 9 | 10 | type FailurePolicy string 11 | 12 | func (f FailurePolicy) Eq(other FailurePolicy) bool { 13 | return strings.EqualFold(string(f), string(other)) 14 | } 15 | 16 | const ( 17 | FailurePolicyIgnore FailurePolicy = "ignore" 18 | FailurePolicyFail FailurePolicy = "fail" 19 | ) 20 | 21 | type ClientConfig struct { 22 | URL string `yaml:"url"` 23 | CABundle string `yaml:"caBundle"` 24 | Insecure bool `yaml:"insecure"` 25 | } 26 | 27 | type Rule struct { 28 | Resources []string `yaml:"resources"` 29 | Operations []models.Operation `yaml:"operations"` 30 | Versions []string `yaml:"versions"` 31 | } 32 | 33 | type Webhook struct { 34 | Kind models.Kind `yaml:"kind"` 35 | FailurePolicy FailurePolicy `yaml:"failurePolicy"` 36 | Timeout time.Duration `yaml:"timeout"` 37 | Rules []Rule `yaml:"rules"` 38 | ClientConfig ClientConfig `yaml:"clientConfig"` 39 | } 40 | 41 | type Admission struct { 42 | Webhooks []Webhook `yaml:"webhooks"` 43 | } 44 | -------------------------------------------------------------------------------- /pkg/config/argocd/argocd.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package argocd 16 | 17 | // RegionMapper represents a region-to-ArgoCD Mapper configurations. 18 | type RegionMapper map[string]*ArgoCD 19 | 20 | type Mapper map[string]*ArgoCD 21 | 22 | type ArgoCD struct { 23 | URL string `yaml:"url"` 24 | Token string `yaml:"token"` 25 | HelmRepo string `yaml:"helmRepo"` 26 | Namespace string `yaml:"namespace"` 27 | } 28 | -------------------------------------------------------------------------------- /pkg/config/authenticate/authenticate.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package authenticate 16 | 17 | type Key struct { 18 | AccessKey string `yaml:"accessKey"` 19 | SecretKey string `yaml:"secretKey"` 20 | IDP string `yaml:"idp"` 21 | } 22 | 23 | type Keys []*Key 24 | 25 | type KeysConfig map[string]Keys 26 | -------------------------------------------------------------------------------- /pkg/config/autofree/config.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package autofree 16 | 17 | import "time" 18 | 19 | type Config struct { 20 | SupportedEnvs []string `yaml:"supportedEnvs"` 21 | AccountID uint `yaml:"accountID"` 22 | JobInterval time.Duration `yaml:"jobInterval"` 23 | BatchInterval time.Duration `yaml:"batchInterval"` 24 | BatchSize int `yaml:"batchSize"` 25 | } 26 | -------------------------------------------------------------------------------- /pkg/config/db/config.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package db 16 | 17 | type Config struct { 18 | Host string `yaml:"host"` 19 | Port int `yaml:"port"` 20 | Username string `yaml:"username"` 21 | Password string `yaml:"password,omitempty"` 22 | Database string `yaml:"database"` 23 | PrometheusEnabled bool `yaml:"prometheusEnabled"` 24 | } 25 | -------------------------------------------------------------------------------- /pkg/config/eventhandler/eventhandler.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package eventhandler 16 | 17 | type Config struct { 18 | // how many events to process in one batch 19 | BatchEventsCount uint `yaml:"batchEventsCount"` 20 | // seconds to save after each cursor save 21 | CursorSaveInterval uint `yaml:"cursorSaveInterval"` 22 | // seconds to wait when there is no events 23 | IdleWaitInterval uint `yaml:"idleWaitInterval"` 24 | } 25 | -------------------------------------------------------------------------------- /pkg/config/git/git.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package git 16 | 17 | type Repo struct { 18 | Kind string `yaml:"kind"` 19 | URL string `yaml:"url"` 20 | Token string `yaml:"token"` 21 | } 22 | -------------------------------------------------------------------------------- /pkg/config/gitlab/gitlab.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package gitlab 16 | 17 | // GitopsRepoConfig gitops repo config 18 | type GitopsRepoConfig struct { 19 | URL string `yaml:"url"` 20 | Token string `yaml:"token"` 21 | RootGroupPath string `yaml:"rootGroupPath"` 22 | DefaultBranch string `yaml:"defaultBranch"` 23 | DefaultVisibility string `yaml:"defaultVisibility"` 24 | } 25 | -------------------------------------------------------------------------------- /pkg/config/grafana/grafana.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package grafana 16 | 17 | import "time" 18 | 19 | type Config struct { 20 | Host string `yaml:"host"` 21 | Namespace string `yaml:"namespace"` 22 | SyncDatasourceConfig SyncDatasourceConfig `yaml:"syncDatasourceConfig"` 23 | Dashboards Dashboards `yaml:"dashboards"` 24 | } 25 | 26 | type SyncDatasourceConfig struct { 27 | Period time.Duration `yaml:"period"` 28 | LabelKey string `yaml:"labelKey"` 29 | LabelValue string `yaml:"labelValue"` 30 | } 31 | 32 | type Dashboards struct { 33 | LabelKey string `yaml:"labelKey"` 34 | LabelValue string `yaml:"labelValue"` 35 | } 36 | -------------------------------------------------------------------------------- /pkg/config/job/job.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package job 16 | 17 | type Config struct { 18 | 19 | // LockName is the name of the lock resource 20 | LockName string `yaml:"lockName"` 21 | 22 | // LockNS is the namespace of the lock resource 23 | LockNS string `yaml:"lockNS"` 24 | 25 | // LeaseDuration is the duration that non-leader candidates will 26 | // wait to force acquire leadership 27 | LeaseDuration int `yaml:"leaseDuration"` 28 | 29 | // RenewDeadline is the duration that the acting master will retry 30 | // refreshing leadership before giving up 31 | RenewDeadline int `yaml:"renewDeadline"` 32 | 33 | // RetryPeriod is the duration the LeaderElector clients should wait 34 | // between tries of actions 35 | RetryPeriod int `yaml:"retryPeriod"` 36 | } 37 | -------------------------------------------------------------------------------- /pkg/config/k8sevent/k8sevent.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package k8sevent 16 | 17 | import ( 18 | "k8s.io/apimachinery/pkg/runtime/schema" 19 | ) 20 | 21 | type Reason struct { 22 | Reason string `yaml:"reason"` 23 | Messages []string `yaml:"messages"` 24 | } 25 | 26 | type Rule struct { 27 | schema.GroupVersionKind `yaml:",inline"` 28 | Reasons []Reason `yaml:"reasons"` 29 | } 30 | 31 | type Config struct { 32 | Rules []Rule `yaml:"rules"` 33 | } 34 | -------------------------------------------------------------------------------- /pkg/config/oauth/config.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package oauth 16 | 17 | import ( 18 | "time" 19 | 20 | "github.com/horizoncd/horizon/pkg/rbac/types" 21 | ) 22 | 23 | type Scopes struct { 24 | DefaultScopes []string `yaml:"defaultScope"` 25 | Roles []types.Role `yaml:"roles"` 26 | } 27 | type Server struct { 28 | OauthHTMLLocation string `yaml:"oauthHTMLLocation"` 29 | AuthorizeCodeExpireIn time.Duration `yaml:"authorizeCodeExpireIn"` 30 | AccessTokenExpireIn time.Duration `yaml:"accessTokenExpireIn"` 31 | RefreshTokenExpireIn time.Duration `yaml:"refreshTokenExpireIn"` 32 | } 33 | -------------------------------------------------------------------------------- /pkg/config/oidc/config.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package oidc 16 | 17 | type Config struct { 18 | UserHeader string `yaml:"userHeader"` 19 | FullNameHeader string `yaml:"fullNameHeader"` 20 | EmailHeader string `yaml:"emailHeader"` 21 | OIDCIDHeader string `yaml:"oidcIDHeader"` 22 | OIDCTypeHeader string `yaml:"oidcTypeHeader"` 23 | } 24 | -------------------------------------------------------------------------------- /pkg/config/pprof/config.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package pprof 16 | 17 | type Config struct { 18 | Enabled bool `yaml:"enabled"` 19 | Port int `yaml:"port"` 20 | } 21 | -------------------------------------------------------------------------------- /pkg/config/redis/config.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package redis 16 | 17 | // Redis 18 | // ```yaml 19 | // redisConfig: 20 | // 21 | // protocol: tcp 22 | // location: 10.124.135.25 23 | // password: redis 24 | // db: 1 25 | // 26 | // ``` 27 | type Redis struct { 28 | Protocol string `yaml:"protocol"` 29 | Address string `yaml:"address"` 30 | Password string `yaml:"password"` 31 | DB uint8 `yaml:"db"` 32 | } 33 | -------------------------------------------------------------------------------- /pkg/config/role/config.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package role 16 | 17 | import "github.com/horizoncd/horizon/pkg/rbac/types" 18 | 19 | type Config struct { 20 | RolePriorityRankDesc []string `yaml:"RolePriorityRankDesc"` 21 | DefaultRole string `yaml:"DefaultRole"` 22 | Roles []types.Role `yaml:"Roles"` 23 | } 24 | -------------------------------------------------------------------------------- /pkg/config/server/config.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package server 16 | 17 | type Config struct { 18 | Port int `yaml:"port"` 19 | } 20 | -------------------------------------------------------------------------------- /pkg/config/session/config.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package session 16 | 17 | type Config struct { 18 | MaxAge uint32 `yaml:"maxAge"` 19 | } 20 | -------------------------------------------------------------------------------- /pkg/config/tekton/tekton.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package tekton 16 | 17 | type Mapper map[string]*Tekton 18 | 19 | type Tekton struct { 20 | Server string `yaml:"server"` 21 | Namespace string `yaml:"namespace"` 22 | Kubeconfig string `yaml:"kubeconfig"` 23 | LogStorage *LogStorage `yaml:"logStorage"` 24 | } 25 | 26 | type LogStorage struct { 27 | Type string `yaml:"type"` 28 | AccessKey string `yaml:"accessKey"` 29 | SecretKey string `yaml:"secretKey"` 30 | Region string `yaml:"region"` 31 | Endpoint string `yaml:"endpoint"` 32 | Bucket string `yaml:"bucket"` 33 | DisableSSL bool `yaml:"disableSSL"` 34 | SkipVerify bool `yaml:"skipVerify"` 35 | S3ForcePathStyle bool `yaml:"s3ForcePathStyle"` 36 | } 37 | -------------------------------------------------------------------------------- /pkg/config/template/template.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package template 16 | 17 | type UpgradeMapper map[string]TargetTemplate 18 | 19 | type TargetTemplate struct { 20 | Name string `json:"name" yaml:"name"` 21 | Release string `json:"release" yaml:"release"` 22 | BuildConfig BuildConfig `json:"buildConfig" yaml:"buildConfig"` 23 | } 24 | 25 | type BuildConfig struct { 26 | Language string `json:"language" yaml:"language"` 27 | Environment string `json:"environment" yaml:"environment"` 28 | } 29 | -------------------------------------------------------------------------------- /pkg/config/templaterepo/template_repo.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package templaterepo 16 | 17 | type Repo struct { 18 | Kind string `yaml:"kind"` 19 | Host string `yaml:"host"` 20 | Username string `yaml:"username"` 21 | Password string `yaml:"password"` 22 | Token string `yaml:"token"` 23 | Insecure bool `yaml:"insecure"` 24 | CertFile string `yaml:"certFile"` 25 | KeyFile string `yaml:"keyFile"` 26 | CAFile string `yaml:"caFile"` 27 | RepoName string `yaml:"repoName"` 28 | } 29 | -------------------------------------------------------------------------------- /pkg/config/token/token.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package token 16 | 17 | import "time" 18 | 19 | type Config struct { 20 | // JwtSigningKey is used to sign JWT tokens 21 | JwtSigningKey string `yaml:"jwtSigningKey"` 22 | // CallbackTokenExpireIn is the expiration time of token for tekton callback 23 | CallbackTokenExpireIn time.Duration `yaml:"callbackTokenExpireIn"` 24 | } 25 | -------------------------------------------------------------------------------- /pkg/config/webhook/webhook.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package webhook 16 | 17 | type Config struct { 18 | // seconds for http client timeout 19 | ClientTimeout uint `yaml:"clientTimeout"` 20 | // seconds to wait when there is no log to proress 21 | IdleWaitInterval uint `yaml:"idleWaitInterval"` 22 | // seconds to wait after complete a worker reconciliation 23 | WorkerReconcileInterval uint `yaml:"workerReconcileInterval"` 24 | // bytes limit to truncate for response body 25 | ResponseBodyTruncateSize uint `yaml:"responseBodyTruncateSize"` 26 | } 27 | -------------------------------------------------------------------------------- /pkg/context/context.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package context 16 | 17 | // nolint 18 | type contextKey struct{ payload uint8 } 19 | 20 | var MemberQueryOnCondition = &contextKey{} 21 | var MemberEmails = &contextKey{} 22 | var MemberRole = &contextKey{} 23 | var MemberDirectMemberOnly = &contextKey{} 24 | 25 | var TemplateWithRelease = &contextKey{} 26 | var TemplateOnlyRefCount = &contextKey{} 27 | var TemplateWithFullPath = &contextKey{} 28 | var TemplateListSelfOnly = &contextKey{} 29 | var TemplateListRecursively = &contextKey{} 30 | 31 | var ReleaseSyncToRepo = &contextKey{} 32 | 33 | var JWTTokenString = &contextKey{} 34 | -------------------------------------------------------------------------------- /pkg/context/scope.go: -------------------------------------------------------------------------------- 1 | package context 2 | 3 | import ( 4 | "context" 5 | "net/http" 6 | 7 | "github.com/gin-gonic/gin" 8 | ) 9 | 10 | const ParamScope = "scope" 11 | 12 | func scopeKey() string { 13 | return "contextScope" 14 | } 15 | 16 | func GetScope(ctx context.Context, req *http.Request) string { 17 | scope, ok := ScopeFromContext(ctx) 18 | if !ok { 19 | return req.URL.Query().Get(ParamScope) 20 | } 21 | return scope 22 | } 23 | 24 | func ScopeFromContext(ctx context.Context) (string, bool) { 25 | scope, ok := ctx.Value(scopeKey()).(string) 26 | return scope, ok 27 | } 28 | 29 | func SetScope(c *gin.Context, scope string) { 30 | // attach cluster scope to context 31 | c.Set(scopeKey(), scope) 32 | } 33 | -------------------------------------------------------------------------------- /pkg/environment/models/environment.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package models 16 | 17 | import ( 18 | "github.com/horizoncd/horizon/pkg/server/global" 19 | ) 20 | 21 | type Environment struct { 22 | global.Model 23 | 24 | Name string 25 | DisplayName string 26 | CreatedBy uint 27 | UpdatedBy uint 28 | } 29 | 30 | type EnvironmentList []*Environment 31 | 32 | func (e EnvironmentList) Len() int { 33 | return len(e) 34 | } 35 | 36 | func (e EnvironmentList) Less(i, j int) bool { 37 | const pre = "pre" 38 | const online = "online" 39 | if e[i].Name == online { 40 | return false 41 | } 42 | if e[j].Name == online { 43 | return true 44 | } 45 | if e[i].Name == pre { 46 | return false 47 | } 48 | if e[j].Name == pre { 49 | return true 50 | } 51 | return e[i].Name < e[j].Name 52 | } 53 | 54 | func (e EnvironmentList) Swap(i, j int) { 55 | e[i], e[j] = e[j], e[i] 56 | } 57 | -------------------------------------------------------------------------------- /pkg/environment/service/autofree.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package service 16 | 17 | type AutoFreeSVC struct { 18 | envsWithAutoFree map[string]struct{} 19 | } 20 | 21 | func New(envsWithAutoFreeArr []string) *AutoFreeSVC { 22 | m := make(map[string]struct{}) 23 | for _, env := range envsWithAutoFreeArr { 24 | m[env] = struct{}{} 25 | } 26 | return &AutoFreeSVC{ 27 | envsWithAutoFree: m, 28 | } 29 | } 30 | 31 | func (s *AutoFreeSVC) WhetherSupported(env string) bool { 32 | _, ok := s.envsWithAutoFree[env] 33 | return ok 34 | } 35 | -------------------------------------------------------------------------------- /pkg/environmentregion/models/environment_region.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package models 16 | 17 | import ( 18 | "github.com/horizoncd/horizon/pkg/server/global" 19 | ) 20 | 21 | type EnvironmentRegion struct { 22 | global.Model 23 | 24 | EnvironmentName string 25 | RegionName string 26 | IsDefault bool 27 | CreatedBy uint 28 | UpdatedBy uint 29 | } 30 | -------------------------------------------------------------------------------- /pkg/git/models.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package git 16 | 17 | const ( 18 | GitRefTypeBranch = "branch" 19 | GitRefTypeTag = "tag" 20 | GitRefTypeCommit = "commit" 21 | ) 22 | 23 | type Tag struct { 24 | ShortID string 25 | Name string 26 | ArchiveData []byte 27 | } 28 | 29 | type Commit struct { 30 | ID string 31 | Message string 32 | } 33 | 34 | // SearchParams contains parameters for searching operation 35 | type SearchParams struct { 36 | Filter string 37 | PageNumber int 38 | PageSize int 39 | } 40 | -------------------------------------------------------------------------------- /pkg/group/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/horizoncd/horizon/6cdb919ad8a131dc1c0d97eda435e34d08dc29b1/pkg/group/.DS_Store -------------------------------------------------------------------------------- /pkg/group/service/models.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package service 16 | 17 | import "time" 18 | 19 | // Child subResource of a group, including group & application 20 | type Child struct { 21 | ID uint `json:"id"` 22 | Name string `json:"name"` 23 | Path string `json:"path"` 24 | VisibilityLevel string `json:"visibilityLevel"` 25 | Description string `json:"description"` 26 | ParentID uint `json:"parentID"` 27 | TraversalIDs string `json:"traversalIDs"` 28 | UpdatedAt time.Time `json:"updatedAt"` 29 | FullName string `json:"fullName"` 30 | FullPath string `json:"fullPath"` 31 | Type string `json:"type"` 32 | ChildrenCount int `json:"childrenCount"` 33 | Children []*Child `json:"children"` 34 | } 35 | 36 | // Full is the fullName&fullPath for a group/application/applicationInstance 37 | type Full struct { 38 | FullName string `json:"fullName"` 39 | FullPath string `json:"fullPath"` 40 | } 41 | -------------------------------------------------------------------------------- /pkg/hook/handler/handler.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package handler 16 | 17 | import "github.com/horizoncd/horizon/pkg/hook/hook" 18 | 19 | type EventHandler interface { 20 | Process(event *hook.EventCtx) error 21 | } 22 | -------------------------------------------------------------------------------- /pkg/hook/hook/hooks.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package hook 16 | 17 | import "context" 18 | 19 | type Hook interface { 20 | Push(ctx context.Context, hooks Event) 21 | Process() 22 | Stop() 23 | WaitStop() 24 | } 25 | -------------------------------------------------------------------------------- /pkg/hook/hook/models.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package hook 16 | 17 | import ( 18 | "context" 19 | "time" 20 | ) 21 | 22 | type EventType string 23 | 24 | const ( 25 | CreateApplication EventType = "CreateApplication" 26 | DeleteApplication EventType = "DeleteApplication" 27 | CreateCluster EventType = "CreateCluster" 28 | DeleteCluster EventType = "DeleteCluster" 29 | ) 30 | 31 | var ( 32 | DefaultDelay = 1 * time.Second 33 | MaxDelay = 1000 * time.Second 34 | ) 35 | 36 | type Event struct { 37 | EventType EventType 38 | Event interface{} 39 | } 40 | 41 | type EventCtx struct { 42 | EventType EventType 43 | Event interface{} 44 | Ctx context.Context 45 | FailedTimes uint 46 | } 47 | -------------------------------------------------------------------------------- /pkg/horizonapp/dao/dao.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package dao 16 | 17 | import ( 18 | "golang.org/x/net/context" 19 | ) 20 | 21 | type DAO interface { 22 | Create(ctx context.Context) 23 | Get() 24 | DeleteByID() 25 | List() 26 | } 27 | -------------------------------------------------------------------------------- /pkg/horizonapp/models/models.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package models 16 | 17 | type OwnerType uint8 18 | 19 | const ( 20 | GroupOwnerType OwnerType = 1 21 | ) 22 | 23 | type HorizonApp struct { 24 | ID uint 25 | Name string 26 | Desc string 27 | HomeURL string 28 | WebHook string 29 | 30 | OauthAppID uint 31 | 32 | OwnerType OwnerType 33 | OwnerID uint 34 | } 35 | 36 | type Permissions struct { 37 | ID uint 38 | Permissions string 39 | } 40 | -------------------------------------------------------------------------------- /pkg/jobs/eventhandler/eventhandler.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package eventhandler 16 | 17 | import ( 18 | "context" 19 | 20 | eventhandlercfg "github.com/horizoncd/horizon/pkg/config/eventhandler" 21 | eventhandlersvc "github.com/horizoncd/horizon/pkg/eventhandler" 22 | "github.com/horizoncd/horizon/pkg/jobs" 23 | "github.com/horizoncd/horizon/pkg/param/managerparam" 24 | ) 25 | 26 | func New(ctx context.Context, eventHandlerConfig eventhandlercfg.Config, 27 | mgrs *managerparam.Manager) (jobs.Job, eventhandlersvc.Service) { 28 | // start event handler service to generate webhook log by events 29 | eventHandlerService := eventhandlersvc.NewService(ctx, mgrs, eventHandlerConfig) 30 | 31 | return func(ctx context.Context) { 32 | eventHandlerService.Start() 33 | <-ctx.Done() 34 | // graceful exit 35 | eventHandlerService.StopAndWait() 36 | }, eventHandlerService 37 | } 38 | -------------------------------------------------------------------------------- /pkg/jobs/grafanasync/grafanasync.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package grafanasync 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/horizoncd/horizon/core/config" 21 | "github.com/horizoncd/horizon/pkg/grafana" 22 | "github.com/horizoncd/horizon/pkg/param/managerparam" 23 | "k8s.io/client-go/kubernetes" 24 | ) 25 | 26 | func Run(ctx context.Context, coreConfig *config.Config, 27 | manager *managerparam.Manager, client kubernetes.Interface) { 28 | grafanaService := grafana.NewService(coreConfig.GrafanaConfig, manager, client) 29 | grafanaService.SyncDatasource(ctx) 30 | } 31 | -------------------------------------------------------------------------------- /pkg/pr/manager/message.go: -------------------------------------------------------------------------------- 1 | package manager 2 | 3 | import ( 4 | "context" 5 | 6 | "gorm.io/gorm" 7 | 8 | "github.com/horizoncd/horizon/lib/q" 9 | "github.com/horizoncd/horizon/pkg/pr/dao" 10 | "github.com/horizoncd/horizon/pkg/pr/models" 11 | ) 12 | 13 | type PRMessageManager interface { 14 | // Create creates a pipelinerun message 15 | Create(ctx context.Context, prMessage *models.PRMessage) (*models.PRMessage, error) 16 | // List lists messages order by created_at asc 17 | List(ctx context.Context, pipelineRunID uint, query *q.Query) (int, []*models.PRMessage, error) 18 | } 19 | 20 | type prMessageManager struct { 21 | dao dao.PRMessageDAO 22 | } 23 | 24 | func NewPRMessageManager(db *gorm.DB) PRMessageManager { 25 | return &prMessageManager{ 26 | dao: dao.NewPRMessageDAO(db), 27 | } 28 | } 29 | 30 | func (m *prMessageManager) Create(ctx context.Context, prMessage *models.PRMessage) (*models.PRMessage, error) { 31 | return m.dao.Create(ctx, prMessage) 32 | } 33 | 34 | func (m *prMessageManager) List(ctx context.Context, pipelineRunID uint, 35 | query *q.Query) (int, []*models.PRMessage, error) { 36 | if query == nil { 37 | query = &q.Query{} 38 | } 39 | return m.dao.List(ctx, pipelineRunID, query) 40 | } 41 | -------------------------------------------------------------------------------- /pkg/pr/manager/pr.go: -------------------------------------------------------------------------------- 1 | package manager 2 | 3 | import ( 4 | "gorm.io/gorm" 5 | ) 6 | 7 | type PRManager struct { 8 | PipelineRun PipelineRunManager 9 | Message PRMessageManager 10 | Check CheckManager 11 | } 12 | 13 | func NewPRManager(db *gorm.DB) *PRManager { 14 | return &PRManager{ 15 | PipelineRun: NewPipelineRunManager(db), 16 | Message: NewPRMessageManager(db), 17 | Check: NewCheckManager(db), 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /pkg/pr/models/check.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | import ( 4 | "github.com/horizoncd/horizon/core/common" 5 | "github.com/horizoncd/horizon/pkg/server/global" 6 | ) 7 | 8 | type CheckRunStatus string 9 | 10 | const ( 11 | CheckStatusPending CheckRunStatus = "Pending" 12 | CheckStatusInProgress CheckRunStatus = "InProgress" 13 | CheckStatusSuccess CheckRunStatus = "Success" 14 | CheckStatusFailure CheckRunStatus = "Failure" 15 | CheckStatusCancelled CheckRunStatus = "Cancelled" 16 | ) 17 | 18 | var CheckRunStatusArr = [...]CheckRunStatus{ 19 | CheckStatusPending, 20 | CheckStatusInProgress, 21 | CheckStatusSuccess, 22 | CheckStatusFailure, 23 | CheckStatusCancelled, 24 | } 25 | 26 | func String2CheckRunStatus(s string) CheckRunStatus { 27 | for _, status := range CheckRunStatusArr { 28 | if s == string(status) { 29 | return status 30 | } 31 | } 32 | return CheckStatusPending 33 | } 34 | 35 | type Check struct { 36 | global.Model 37 | common.Resource `json:",inline"` 38 | } 39 | 40 | type CheckRun struct { 41 | global.Model `json:",inline"` 42 | Name string `json:"name"` 43 | CheckID uint `json:"checkId"` 44 | Status CheckRunStatus `json:"status"` 45 | Message string `json:"message"` 46 | PipelineRunID uint `gorm:"column:pipeline_run_id" json:"pipelineRunId"` 47 | DetailURL string `gorm:"column:detail_url" json:"detailUrl"` 48 | } 49 | 50 | func (CheckRun) TableName() string { 51 | return "tb_checkrun" 52 | } 53 | -------------------------------------------------------------------------------- /pkg/pr/models/message.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | import ( 4 | "github.com/horizoncd/horizon/pkg/server/global" 5 | ) 6 | 7 | const ( 8 | MessageTypeUser = iota 9 | MessageTypeSystem 10 | ) 11 | 12 | type PRMessage struct { 13 | global.Model 14 | PipelineRunID uint `gorm:"column:pipeline_run_id"` 15 | Content string 16 | MessageType uint 17 | CreatedBy uint 18 | UpdatedBy uint 19 | } 20 | 21 | func (PRMessage) TableName() string { 22 | return "tb_pr_msg" 23 | } 24 | -------------------------------------------------------------------------------- /pkg/pr/pipeline/models/pipeline.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package models 16 | 17 | import "time" 18 | 19 | type Pipeline struct { 20 | ID uint 21 | PipelinerunID uint 22 | Application string 23 | Cluster string 24 | Region string 25 | Pipeline string 26 | Result string 27 | Duration uint 28 | StartedAt time.Time 29 | FinishedAt time.Time 30 | CreatedAt time.Time 31 | UpdatedAt time.Time 32 | } 33 | -------------------------------------------------------------------------------- /pkg/pr/pipeline/models/stats.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package models 16 | 17 | import "time" 18 | 19 | type StepStats struct { 20 | Step string `json:"step"` 21 | Result string `json:"result"` 22 | Duration uint `json:"duration"` 23 | } 24 | 25 | type TaskStats struct { 26 | Task string `json:"task"` 27 | Result string `json:"result"` 28 | Duration uint `json:"duration"` 29 | Steps []*StepStats `json:"steps"` 30 | } 31 | 32 | type PipelineStats struct { 33 | PipelinerunID uint `json:"pipelinerunID"` 34 | Application string `json:"application"` 35 | Cluster string `json:"cluster"` 36 | Pipeline string `json:"pipeline"` 37 | Result string `json:"result"` 38 | Duration uint `json:"duration"` 39 | Tasks []*TaskStats `json:"tasks"` 40 | StartedAt time.Time `json:"startedAt"` 41 | } 42 | -------------------------------------------------------------------------------- /pkg/pr/pipeline/models/step.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package models 16 | 17 | import "time" 18 | 19 | type Step struct { 20 | ID uint 21 | PipelinerunID uint 22 | Application string 23 | Cluster string 24 | Region string 25 | Pipeline string 26 | Task string 27 | Step string 28 | Result string 29 | Duration uint 30 | StartedAt time.Time 31 | FinishedAt time.Time 32 | CreatedAt time.Time 33 | UpdatedAt time.Time 34 | } 35 | -------------------------------------------------------------------------------- /pkg/pr/pipeline/models/task.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package models 16 | 17 | import "time" 18 | 19 | type Task struct { 20 | ID uint 21 | PipelinerunID uint 22 | Application string 23 | Cluster string 24 | Region string 25 | Pipeline string 26 | Task string 27 | Result string 28 | Duration uint 29 | StartedAt time.Time 30 | FinishedAt time.Time 31 | CreatedAt time.Time 32 | UpdatedAt time.Time 33 | } 34 | -------------------------------------------------------------------------------- /pkg/rbac/types/types.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package types 16 | 17 | // attention: rbac is refers to the kubernetes rbac 18 | // copy core struct and logics from the kubernetes code 19 | // and do same modify 20 | const ( 21 | APIGroupAll = "*" 22 | ResourceAll = "*" 23 | VerbAll = "*" 24 | ScopeAll = "*" 25 | NonResourceAll = "*" 26 | ) 27 | 28 | type Role struct { 29 | Name string `yaml:"name" json:"name"` 30 | Desc string `yaml:"desc" json:"desc"` 31 | PolicyRules []PolicyRule `yaml:"rules" json:"rules"` 32 | } 33 | 34 | type PolicyRule struct { 35 | Verbs []string `yaml:"verbs" json:"verbs"` 36 | APIGroups []string `yaml:"apiGroups" json:"apiGroups"` 37 | Resources []string `yaml:"resources" json:"resources"` 38 | Scopes []string `yaml:"scopes" json:"scopes"` 39 | NonResourceURLs []string `yaml:"nonResourceURLs" json:"nonResourceURLs"` 40 | } 41 | -------------------------------------------------------------------------------- /pkg/registry/models/registry.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package models 16 | 17 | import ( 18 | "github.com/horizoncd/horizon/pkg/server/global" 19 | ) 20 | 21 | type Registry struct { 22 | global.Model 23 | 24 | Name string 25 | Server string 26 | Path string 27 | Token string 28 | // for delete 29 | InsecureSkipTLSVerify bool `gorm:"column:insecure_skip_tls_verify"` 30 | Kind string 31 | } 32 | -------------------------------------------------------------------------------- /pkg/server/global/model.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package global 16 | 17 | import ( 18 | "time" 19 | 20 | "gorm.io/plugin/soft_delete" 21 | ) 22 | 23 | type Model struct { 24 | ID uint `gorm:"primarykey" json:"id"` 25 | CreatedAt time.Time `json:"createdAt"` 26 | UpdatedAt time.Time `json:"updatedAt"` 27 | DeletedTs soft_delete.DeletedAt `json:"-"` 28 | } 29 | 30 | type HorizonMetaData struct { 31 | Application string 32 | Cluster string 33 | ApplicationID uint 34 | ClusterID uint 35 | Environment string 36 | Operator string 37 | PipelinerunID uint 38 | Region string 39 | Template string 40 | EventID string 41 | } 42 | -------------------------------------------------------------------------------- /pkg/template/models/template.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package models 16 | 17 | import ( 18 | "github.com/horizoncd/horizon/pkg/server/global" 19 | ) 20 | 21 | const TemplateTypeWorkload = "workload" 22 | 23 | type Template struct { 24 | global.Model 25 | 26 | Name string 27 | // TODO: remove the ChartName, now ChartName equals Name 28 | ChartName string 29 | Description string 30 | Repository string 31 | GroupID uint 32 | OnlyOwner *bool 33 | WithoutCI bool 34 | Type string 35 | CreatedBy uint 36 | UpdatedBy uint 37 | } 38 | -------------------------------------------------------------------------------- /pkg/templateschematag/models/models.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package models 16 | 17 | import "time" 18 | 19 | type ClusterTemplateSchemaTag struct { 20 | ID uint `gorm:"primarykey"` 21 | ClusterID uint `gorm:"uniqueIndex:idx_cluster_id_key"` 22 | Key string `gorm:"uniqueIndex:idx_cluster_id_key;column:tag_key"` 23 | Value string `gorm:"column:tag_value"` 24 | CreatedAt time.Time 25 | UpdatedAt time.Time 26 | CreatedBy uint 27 | UpdatedBy uint 28 | } 29 | -------------------------------------------------------------------------------- /pkg/token/generator/generator_types.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package generator 16 | 17 | import ( 18 | "net/http" 19 | 20 | "github.com/horizoncd/horizon/pkg/token/models" 21 | ) 22 | 23 | type CodeGenerateInfo struct { 24 | Token models.Token 25 | Request *http.Request 26 | } 27 | 28 | type CodeGenerator interface { 29 | Generate(info *CodeGenerateInfo) string 30 | } 31 | -------------------------------------------------------------------------------- /pkg/token/models/token.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package models 16 | 17 | import ( 18 | "time" 19 | ) 20 | 21 | type Token struct { 22 | ID uint `gorm:"primarykey"` 23 | 24 | // grant client info 25 | ClientID string `gorm:"column:client_id"` 26 | RedirectURI string `gorm:"column:redirect_uri"` 27 | State string `gorm:"column:state"` 28 | 29 | // token basic info 30 | Name string `gorm:"column:name"` 31 | // Code authorize_code/access_token/refresh_token 32 | Code string `gorm:"column:code"` 33 | CreatedAt time.Time `gorm:"column:created_at"` 34 | CreatedBy uint `gorm:"column:created_by"` 35 | ExpiresIn time.Duration `gorm:"column:expires_in"` 36 | Scope string `gorm:"column:scope"` 37 | 38 | // access token id when code type is refresh_token 39 | RefID uint `gorm:"column:ref_id"` 40 | 41 | UserID uint `gorm:"column:user_id"` 42 | } 43 | -------------------------------------------------------------------------------- /pkg/token/service/claims.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package service 16 | 17 | import "github.com/golang-jwt/jwt/v4" 18 | 19 | const ClaimsIssuer = "horizon" 20 | 21 | type Claims struct { 22 | PipelinerunID *uint 23 | jwt.RegisteredClaims 24 | } 25 | 26 | type ClaimsOption func(*Claims) 27 | 28 | func WithPipelinerunID(pipelinerunID uint) ClaimsOption { 29 | return func(claims *Claims) { 30 | claims.PipelinerunID = &pipelinerunID 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /pkg/token/service/models.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package service 16 | 17 | const ( 18 | NeverExpire = "never" 19 | ExpiresAtFormat = "2006-01-02" 20 | ) 21 | -------------------------------------------------------------------------------- /pkg/token/store/types.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package store 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/horizoncd/horizon/pkg/token/models" 21 | ) 22 | 23 | type Store interface { 24 | Create(ctx context.Context, token *models.Token) (*models.Token, error) 25 | GetByID(ctx context.Context, id uint) (*models.Token, error) 26 | GetByCode(ctx context.Context, code string) (*models.Token, error) 27 | UpdateByID(ctx context.Context, id uint, token *models.Token) error 28 | DeleteByID(ctx context.Context, id uint) error 29 | DeleteByCode(ctx context.Context, code string) error 30 | DeleteByClientID(ctx context.Context, clientID string) error 31 | } 32 | -------------------------------------------------------------------------------- /pkg/user/models/user.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package models 16 | 17 | import ( 18 | "github.com/horizoncd/horizon/pkg/server/global" 19 | ) 20 | 21 | const ( 22 | UserTypeCommon = iota 23 | UserTypeRobot 24 | ) 25 | 26 | type User struct { 27 | global.Model 28 | 29 | Name string 30 | FullName string 31 | Email string 32 | Phone string 33 | UserType uint 34 | Password string 35 | OidcID string `gorm:"column:oidc_id"` 36 | OidcType string `gorm:"column:oidc_type"` 37 | Admin bool 38 | Banned bool 39 | } 40 | 41 | type UserBasic struct { 42 | ID uint `json:"id"` 43 | Name string `json:"name"` 44 | Email string `json:"email"` 45 | } 46 | 47 | func ToUser(user *User) *UserBasic { 48 | if user == nil { 49 | return nil 50 | } 51 | return &UserBasic{ 52 | ID: user.ID, 53 | Name: user.Name, 54 | Email: user.Email, 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /pkg/userlink/models/models.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package models 16 | 17 | import "github.com/horizoncd/horizon/pkg/server/global" 18 | 19 | type UserLink struct { 20 | global.Model 21 | 22 | Sub string 23 | IdpID uint 24 | UserID uint 25 | Name string 26 | Email string 27 | Deletable bool 28 | } 29 | 30 | func (UserLink) TableName() string { 31 | return "tb_idp_user" 32 | } 33 | -------------------------------------------------------------------------------- /pkg/util/common/common.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package common 16 | 17 | import ( 18 | "fmt" 19 | "runtime" 20 | ) 21 | 22 | func StringPtr(str string) *string { 23 | return &str 24 | } 25 | 26 | func IntPtr(i int) *int { 27 | return &i 28 | } 29 | 30 | func UintPtr(i uint) *uint { 31 | return &i 32 | } 33 | 34 | func BoolPtr(b bool) *bool { 35 | return &b 36 | } 37 | 38 | func PrintStack() { 39 | var buf [4096]byte 40 | n := runtime.Stack(buf[:], false) 41 | fmt.Printf("==> %s\n", string(buf[:n])) 42 | } 43 | -------------------------------------------------------------------------------- /pkg/util/permission/permission.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package permission 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/horizoncd/horizon/core/common" 21 | herrors "github.com/horizoncd/horizon/core/errors" 22 | perror "github.com/horizoncd/horizon/pkg/errors" 23 | ) 24 | 25 | func OnlySelfAndAdmin(ctx context.Context, self uint) error { 26 | currentUser, err := common.UserFromContext(ctx) 27 | if err != nil { 28 | return err 29 | } 30 | 31 | if !currentUser.IsAdmin() && currentUser.GetID() != self { 32 | return perror.Wrap(herrors.ErrForbidden, "you can only access resources of yourself") 33 | } 34 | return nil 35 | } 36 | -------------------------------------------------------------------------------- /pkg/util/sets/empty.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Code generated by set-gen. DO NOT EDIT. 18 | 19 | package sets 20 | 21 | // Empty is public since it is used by some internal API objects for conversions between external 22 | // string arrays and internal sets, and conversion logic requires public types today. 23 | type Empty struct{} 24 | -------------------------------------------------------------------------------- /pkg/util/time/time.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package time 16 | 17 | import ( 18 | "time" 19 | 20 | v1 "k8s.io/apimachinery/pkg/apis/meta/v1" 21 | ) 22 | 23 | const defaultTimeFormat = "2006-01-02 15:04:05" 24 | 25 | var cstSh, _ = time.LoadLocation("Asia/Shanghai") 26 | 27 | func Now(timeFormat *string) string { 28 | var format = defaultTimeFormat 29 | if timeFormat != nil { 30 | format = *timeFormat 31 | } 32 | return time.Now().Format(format) 33 | } 34 | 35 | func K8sTimeToStrByNowTimezone(t v1.Time) string { 36 | return t.In(cstSh).Format(defaultTimeFormat) 37 | } 38 | -------------------------------------------------------------------------------- /pkg/util/wlog/log.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package wlog 16 | 17 | import ( 18 | "context" 19 | "runtime/debug" 20 | "time" 21 | 22 | "github.com/horizoncd/horizon/pkg/util/log" 23 | ) 24 | 25 | type Log struct { 26 | ctx context.Context 27 | start time.Time 28 | op string 29 | } 30 | 31 | func Start(ctx context.Context, op string) Log { 32 | return Log{op: op, ctx: ctx, start: time.Now()} 33 | } 34 | 35 | func (l Log) StopPrint() { 36 | if err := recover(); err != nil { 37 | log.Error(l.ctx, string(debug.Stack())) 38 | } 39 | duration := time.Since(l.start) 40 | 41 | log.WithFiled(l.ctx, "op", 42 | l.op).WithField("duration", duration.String()).Info("") 43 | } 44 | 45 | func (l Log) GetDuration() time.Duration { 46 | return time.Since(l.start) 47 | } 48 | -------------------------------------------------------------------------------- /pkg/workload/dummy/dummy.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package dummy 16 | 17 | import ( 18 | "github.com/horizoncd/horizon/pkg/workload" 19 | "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" 20 | "k8s.io/apimachinery/pkg/runtime/schema" 21 | ) 22 | 23 | func init() { 24 | workload.Register(ability, 25 | schema.GroupVersionResource{ 26 | Group: "argoproj.io", 27 | Version: "v1alpha1", 28 | Resource: "applications", 29 | }, 30 | schema.GroupVersionResource{ 31 | Group: "apps", 32 | Version: "v1", 33 | Resource: "deployments", 34 | }) 35 | } 36 | 37 | var ability = &dummy{} 38 | 39 | // dummy is a dummy implementation of workload.Interface 40 | // It is used to register the ability to handle some required resources. 41 | type dummy struct{} 42 | 43 | func (*dummy) MatchGK(_ schema.GroupKind) bool { 44 | return false 45 | } 46 | 47 | func (*dummy) Action(_ string, un *unstructured.Unstructured) (*unstructured.Unstructured, error) { 48 | return un, nil 49 | } 50 | -------------------------------------------------------------------------------- /pkg/workload/type.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package workload 16 | 17 | import ( 18 | v1 "k8s.io/api/core/v1" 19 | ) 20 | 21 | type Step struct { 22 | Index int 23 | Total int 24 | Replicas []int 25 | ManualPaused bool 26 | AutoPromote bool 27 | Extra *string 28 | } 29 | 30 | type Revision struct { 31 | Name string 32 | Pods []v1.Pod 33 | } 34 | -------------------------------------------------------------------------------- /pkg/workload/util.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2023 Horizoncd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package workload 16 | 17 | import ( 18 | "context" 19 | "fmt" 20 | 21 | "github.com/horizoncd/horizon/pkg/util/log" 22 | corev1 "k8s.io/api/core/v1" 23 | "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" 24 | "k8s.io/apimachinery/pkg/runtime" 25 | ) 26 | 27 | func ObjIntoPod(objs ...runtime.Object) []corev1.Pod { 28 | pods := make([]corev1.Pod, len(objs)) 29 | for i, obj := range objs { 30 | pod := corev1.Pod{} 31 | err := ObjUnmarshal(obj, &pod) 32 | if err != nil { 33 | log.Errorf(context.TODO(), "failed to unmarshal pod object: %v", err) 34 | continue 35 | } 36 | pods[i] = pod 37 | } 38 | return pods 39 | } 40 | 41 | func ObjUnmarshal(obj runtime.Object, container interface{}) error { 42 | un, ok := obj.(*unstructured.Unstructured) 43 | if !ok { 44 | return fmt.Errorf("obj is not *unstructured.Unstructured") 45 | } 46 | 47 | return runtime.DefaultUnstructuredConverter.FromUnstructured(un.Object, container) 48 | } 49 | -------------------------------------------------------------------------------- /scripts/LICENSE_TEMPLATE: -------------------------------------------------------------------------------- 1 | Copyright © {{.Year}} {{.Holder}} 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /scripts/coverage.awk: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env awk 2 | 3 | { 4 | print $0 5 | if (match($0, /^total:/)) { 6 | sub(/%/, "", $NF); 7 | printf("test coverage is %s%(quality gate is %s%)\n", $NF, target) 8 | if (strtonum($NF) < target) { 9 | printf("test coverage does not meet expectations: %d%, please add test cases!\n", target) 10 | exit 1; 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /scripts/coverage.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # http://stackoverflow.com/a/21142256/2055281 4 | 5 | echo "mode: atomic" > coverage.txt 6 | 7 | for d in $(find ./* -maxdepth 10 -type d); do 8 | if ls $d/*.go &> /dev/null; then 9 | go test -coverprofile=profile.out -covermode=atomic $d 10 | if [ -f profile.out ]; then 11 | cat profile.out | grep -v "mode: " >> /tmp/coverage.txt 12 | rm profile.out 13 | fi 14 | fi 15 | done 16 | 17 | echo "========> coverage output: /tmp/coverage.txt" 18 | -------------------------------------------------------------------------------- /scripts/make-rules/gen.mk: -------------------------------------------------------------------------------- 1 | # Copyright 2023 The Horizoncd Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # ============================================================================== 16 | # Makefile helper functions for generate necessary files and docs 17 | # https://cloud.redhat.com/blog/kubernetes-deep-dive-code-generation-customresources 18 | # ! The stock of code generated by `make gen` should be idempotent 19 | # 20 | 21 | ## gen.run: gen.code gen.docgo 22 | .PHONY: gen.run 23 | gen.run: gen.code gen.docgo 24 | 25 | ## gen.code: generate code 26 | .PHONY: gen.code 27 | gen.code: tools.install.mockgen 28 | @echo "===========> Generating codegen" 29 | @$(GO) generate ./... 30 | 31 | ## gen.docgo: generate doc.go 32 | .PHONY: gen.docgo 33 | gen.docgo: 34 | @echo "===========> Generating doc.go" 35 | 36 | ## gen.help: show help for gen 37 | .PHONY: gen.help 38 | gen.help: scripts/make-rules/gen.mk 39 | $(call smallhelp) 40 | --------------------------------------------------------------------------------