diff --git a/cmd/ks-iam/app/options/options.go b/cmd/ks-iam/app/options/options.go index 9de464ec60b02ca31f23515ec2958598a54409a7..85c678447fea265cec6f8abeac03adb6a2bccc68 100644 --- a/cmd/ks-iam/app/options/options.go +++ b/cmd/ks-iam/app/options/options.go @@ -28,6 +28,7 @@ type ServerRunOptions struct { AdminPassword string TokenExpireTime string JWTSecret string + AuthRateLimit string } func NewServerRunOptions() *ServerRunOptions { @@ -42,5 +43,6 @@ func (s *ServerRunOptions) AddFlags(fs *pflag.FlagSet) { fs.StringVar(&s.AdminPassword, "admin-password", "passw0rd", "default administrator's password") fs.StringVar(&s.TokenExpireTime, "token-expire-time", "2h", "token expire time,valid time units are \"ns\",\"us\",\"ms\",\"s\",\"m\",\"h\"") fs.StringVar(&s.JWTSecret, "jwt-secret", "", "jwt secret") + fs.StringVar(&s.AuthRateLimit, "auth-rate-limit", "5/30m", "specifies the maximum number of authentication attempts permitted and time interval,valid time units are \"s\",\"m\",\"h\"") s.GenericServerRunOptions.AddFlags(fs) } diff --git a/cmd/ks-iam/app/server.go b/cmd/ks-iam/app/server.go index cd9e31c6d2442c884752f7b93866fb6611c57652..17239a7baeb1b1c107177746bc0cb9ed3ec17850 100644 --- a/cmd/ks-iam/app/server.go +++ b/cmd/ks-iam/app/server.go @@ -75,7 +75,7 @@ func Run(s *options.ServerRunOptions) error { initializeAdminJenkins() initializeDevOpsDatabase() - err = iam.Init(s.AdminEmail, s.AdminPassword, expireTime) + err = iam.Init(s.AdminEmail, s.AdminPassword, expireTime, s.AuthRateLimit) jwtutil.Setup(s.JWTSecret) if err != nil { diff --git a/pkg/apis/devops/v1alpha2/register.go b/pkg/apis/devops/v1alpha2/register.go index 4cb4c4cdfffb4b763708b2de8261e351afda9609..d010b48beb53c0d0122a8303b4ed96b815617462 100644 --- a/pkg/apis/devops/v1alpha2/register.go +++ b/pkg/apis/devops/v1alpha2/register.go @@ -216,18 +216,18 @@ func addWebService(c *restful.Container) error { Returns(http.StatusOK, RespOK, []devops.JenkinsCredential{}). Reads([]devops.JenkinsCredential{})) - // match Jenkisn api "/blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}" - webservice.Route(webservice.GET("/devops/{devops}/pipelines/{pipelines}"). + // match Jenkisn api "/blue/rest/organizations/jenkins/pipelines/{devops}/{pipeline}" + webservice.Route(webservice.GET("/devops/{devops}/pipelines/{pipeline}"). To(devopsapi.GetPipeline). Metadata(restfulspec.KeyOpenAPITags, tags). Doc("Get a Pipeline Inside a DevOps Project"). - Param(webservice.PathParameter("pipelines", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). - Param(webservice.PathParameter("devops", "the name of devops project.")). + Param(webservice.PathParameter("pipeline", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). + Param(webservice.PathParameter("devops", "DevOps Project's Id, e.g. project-RRRRAzLBlLEm")). Returns(http.StatusOK, RespOK, devops.Pipeline{}). Writes(devops.Pipeline{})) // match Jenkisn api: "jenkins_api/blue/rest/search" - webservice.Route(webservice.GET("/devops/search"). + webservice.Route(webservice.GET("/search"). To(devopsapi.SearchPipelines). Metadata(restfulspec.KeyOpenAPITags, tags). Doc("Search DevOps resource."). @@ -246,13 +246,13 @@ func addWebService(c *restful.Container) error { Returns(http.StatusOK, RespOK, []devops.Pipeline{}). Writes([]devops.Pipeline{})) - // match Jenkisn api "/blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/runs/" - webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/runs"). + // match Jenkisn api "/blue/rest/organizations/jenkins/pipelines/{devops}/{pipeline}/runs/" + webservice.Route(webservice.GET("/devops/{devops}/pipelines/{pipeline}/runs"). To(devopsapi.SearchPipelineRuns). Metadata(restfulspec.KeyOpenAPITags, tags). Doc("Search DevOps Pipelines runs in branch."). - Param(webservice.PathParameter("pipelineName", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). - Param(webservice.PathParameter("projectName", "the name of devops project.")). + Param(webservice.PathParameter("pipeline", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). + Param(webservice.PathParameter("devops", "DevOps Project's Id, e.g. project-RRRRAzLBlLEm")). Param(webservice.QueryParameter("start", "the count of item start."). Required(false). DataFormat("start=%d")). @@ -265,30 +265,30 @@ func addWebService(c *restful.Container) error { Returns(http.StatusOK, RespOK, []devops.BranchPipelineRun{}). Writes([]devops.BranchPipelineRun{})) - // match Jenkins api "/blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/branches/{branchName}/runs/{runId}/" - webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}"). + // match Jenkins api "/blue/rest/organizations/jenkins/pipelines/{devops}/{pipeline}/branches/{branch}/runs/{run}/" + webservice.Route(webservice.GET("/devops/{devops}/pipelines/{pipeline}/branches/{branch}/runs/{run}"). To(devopsapi.GetBranchPipelineRun). Metadata(restfulspec.KeyOpenAPITags, tags). Doc("Get all runs in a branch"). - Param(webservice.PathParameter("pipelineName", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). - Param(webservice.PathParameter("projectName", "the name of devops project.")). - Param(webservice.PathParameter("branchName", "the name of branch, same as repository brnach.")). - Param(webservice.PathParameter("runId", "pipeline run id, the unique id for a pipeline once build.")). + Param(webservice.PathParameter("pipeline", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). + Param(webservice.PathParameter("devops", "DevOps Project's Id, e.g. project-RRRRAzLBlLEm")). + Param(webservice.PathParameter("branch", "the name of branch, same as repository brnach.")). + Param(webservice.PathParameter("run", "pipeline run id, the unique id for a pipeline once build.")). Param(webservice.QueryParameter("start", "the count of item start."). Required(false). DataFormat("start=%d")). Returns(http.StatusOK, RespOK, devops.BranchPipelineRun{}). Writes(devops.BranchPipelineRun{})) - // match Jenkins api "/blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/branches/{branchName}/runs/{runId}/nodes" - webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/nodes"). + // match Jenkins api "/blue/rest/organizations/jenkins/pipelines/{devops}/{pipeline}/branches/{branch}/runs/{run}/nodes" + webservice.Route(webservice.GET("/devops/{devops}/pipelines/{pipeline}/branches/{branch}/runs/{run}/nodes"). To(devopsapi.GetPipelineRunNodesbyBranch). Metadata(restfulspec.KeyOpenAPITags, tags). Doc("Get MultiBranch Pipeline run nodes."). - Param(webservice.PathParameter("projectName", "the name of devops project.")). - Param(webservice.PathParameter("pipelineName", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). - Param(webservice.PathParameter("branchName", "the name of branch, same as repository brnach.")). - Param(webservice.PathParameter("runId", "pipeline run id, the unique id for a pipeline once build.")). + Param(webservice.PathParameter("devops", "DevOps Project's Id, e.g. project-RRRRAzLBlLEm")). + Param(webservice.PathParameter("pipeline", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). + Param(webservice.PathParameter("branch", "the name of branch, same as repository brnach.")). + Param(webservice.PathParameter("run", "pipeline run id, the unique id for a pipeline once build.")). Param(webservice.QueryParameter("limit", "the count of item limit."). Required(false). DataFormat("limit=%d"). @@ -296,67 +296,67 @@ func addWebService(c *restful.Container) error { Returns(http.StatusOK, RespOK, []devops.BranchPipelineRunNodes{}). Writes([]devops.BranchPipelineRunNodes{})) - // match "/blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/branches/{branchName}/runs/{runId}/nodes/{nodeId}/steps/{stepId}/log/?start=0" - webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/nodes/{nodeId}/steps/{stepId}/log"). + // match "/blue/rest/organizations/jenkins/pipelines/{devops}/{pipeline}/branches/{branch}/runs/{run}/nodes/{node}/steps/{step}/log/?start=0" + webservice.Route(webservice.GET("/devops/{devops}/pipelines/{pipeline}/branches/{branch}/runs/{run}/nodes/{node}/steps/{step}/log"). To(devopsapi.GetBranchStepLog). Metadata(restfulspec.KeyOpenAPITags, tags). Doc("Get pipelines step log."). Produces("text/plain; charset=utf-8"). - Param(webservice.PathParameter("projectName", "the name of devops project.")). - Param(webservice.PathParameter("pipelineName", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). - Param(webservice.PathParameter("branchName", "the name of branch, same as repository brnach.")). - Param(webservice.PathParameter("runId", "pipeline run id, the unique id for a pipeline once build.")). - Param(webservice.PathParameter("nodeId", "pipeline node id, the one node in pipeline.")). - Param(webservice.PathParameter("stepId", "pipeline step id, the one step in pipeline.")). + Param(webservice.PathParameter("devops", "DevOps Project's Id, e.g. project-RRRRAzLBlLEm")). + Param(webservice.PathParameter("pipeline", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). + Param(webservice.PathParameter("branch", "the name of branch, same as repository brnach.")). + Param(webservice.PathParameter("run", "pipeline run id, the unique id for a pipeline once build.")). + Param(webservice.PathParameter("node", "pipeline node id, the one node in pipeline.")). + Param(webservice.PathParameter("step", "pipeline step id, the one step in pipeline.")). Param(webservice.QueryParameter("start", "the count of item start."). Required(true). DataFormat("start=%d"). DefaultValue("start=0"))) - // match "/blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/runs/{runId}/nodes/{nodeId}/steps/{stepId}/log/?start=0" - webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/runs/{runId}/nodes/{nodeId}/steps/{stepId}/log"). + // match "/blue/rest/organizations/jenkins/pipelines/{devops}/{pipeline}/runs/{run}/nodes/{node}/steps/{step}/log/?start=0" + webservice.Route(webservice.GET("/devops/{devops}/pipelines/{pipeline}/runs/{run}/nodes/{node}/steps/{step}/log"). To(devopsapi.GetStepLog). Metadata(restfulspec.KeyOpenAPITags, tags). Doc("Get pipelines step log."). Produces("text/plain; charset=utf-8"). - Param(webservice.PathParameter("projectName", "the name of devops project.")). - Param(webservice.PathParameter("pipelineName", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). - Param(webservice.PathParameter("runId", "pipeline run id, the unique id for a pipeline once build.")). - Param(webservice.PathParameter("nodeId", "pipeline node id, the one node in pipeline.")). - Param(webservice.PathParameter("stepId", "pipeline step id, the one step in pipeline.")). + Param(webservice.PathParameter("devops", "DevOps Project's Id, e.g. project-RRRRAzLBlLEm")). + Param(webservice.PathParameter("pipeline", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). + Param(webservice.PathParameter("run", "pipeline run id, the unique id for a pipeline once build.")). + Param(webservice.PathParameter("node", "pipeline node id, the one node in pipeline.")). + Param(webservice.PathParameter("step", "pipeline step id, the one step in pipeline.")). Param(webservice.QueryParameter("start", "the count of item start."). Required(true). DataFormat("start=%d"). DefaultValue("start=0"))) // match "/blue/rest/organizations/jenkins/scm/github/validate/" - webservice.Route(webservice.PUT("/devops/scm/{scmId}/validate"). + webservice.Route(webservice.POST("/scms/{scm}/verify"). To(devopsapi.Validate). Metadata(restfulspec.KeyOpenAPITags, tags). Doc("Validate Github personal access token."). - Param(webservice.PathParameter("scmId", "the id of SCM.")). + Param(webservice.PathParameter("scm", "the id of SCM.")). Returns(http.StatusOK, RespOK, devops.Validates{}). Writes(devops.Validates{})) - // match "/blue/rest/organizations/jenkins/scm/{scmId}/organizations/?credentialId=github" - webservice.Route(webservice.GET("/devops/scm/{scmId}/organizations"). + // match "/blue/rest/organizations/jenkins/scm/{scm}/organizations/?credentialId=github" + webservice.Route(webservice.GET("/scms/{scm}/organizations"). To(devopsapi.GetSCMOrg). Metadata(restfulspec.KeyOpenAPITags, tags). Doc("List organizations of SCM"). - Param(webservice.PathParameter("scmId", "the id of SCM.")). + Param(webservice.PathParameter("scm", "the id of SCM.")). Param(webservice.QueryParameter("credentialId", "credential id for SCM."). Required(true). DataFormat("credentialId=%s")). Returns(http.StatusOK, RespOK, []devops.SCMOrg{}). Writes([]devops.SCMOrg{})) - // match "/blue/rest/organizations/jenkins/scm/{scmId}/organizations/{organizationId}/repositories/?credentialId=&pageNumber&pageSize=" - webservice.Route(webservice.GET("/devops/scm/{scmId}/organizations/{organizationId}/repositories"). + // match "/blue/rest/organizations/jenkins/scm/{scm}/organizations/{organization}/repositories/?credentialId=&pageNumber&pageSize=" + webservice.Route(webservice.GET("/scms/{scm}/organizations/{organization}/repositories"). To(devopsapi.GetOrgRepo). Metadata(restfulspec.KeyOpenAPITags, tags). Doc("Get SCM repositories in an organization"). - Param(webservice.PathParameter("scmId", "SCM id")). - Param(webservice.PathParameter("organizationId", "organization Id, such as github username.")). + Param(webservice.PathParameter("scm", "SCM id")). + Param(webservice.PathParameter("organization", "organization Id, such as github username.")). Param(webservice.QueryParameter("credentialId", "credential id for SCM."). Required(true). DataFormat("credentialId=%s")). @@ -369,15 +369,15 @@ func addWebService(c *restful.Container) error { Returns(http.StatusOK, RespOK, []devops.OrgRepo{}). Writes([]devops.OrgRepo{})) - // match /blue/rest/organizations/jenkins/pipelines/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/stop/ - webservice.Route(webservice.PUT("/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/stop"). + // match /blue/rest/organizations/jenkins/pipelines/{devops}/pipelines/{pipeline}/branches/{branch}/runs/{run}/stop/ + webservice.Route(webservice.POST("/devops/{devops}/pipelines/{pipeline}/branches/{branch}/runs/{run}/stop"). To(devopsapi.StopBranchPipeline). Metadata(restfulspec.KeyOpenAPITags, tags). - Doc("Stop pipeline in running"). - Param(webservice.PathParameter("projectName", "the name of devops project.")). - Param(webservice.PathParameter("pipelineName", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). - Param(webservice.PathParameter("branchName", "the name of branch, same as repository brnach.")). - Param(webservice.PathParameter("runId", "pipeline run id, the unique id for a pipeline once build.")). + Doc("Stop pipeline in running filter by branch"). + Param(webservice.PathParameter("devops", "DevOps Project's Id, e.g. project-RRRRAzLBlLEm")). + Param(webservice.PathParameter("pipeline", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). + Param(webservice.PathParameter("branch", "the name of branch, same as repository brnach.")). + Param(webservice.PathParameter("run", "pipeline run id, the unique id for a pipeline once build.")). Param(webservice.QueryParameter("blocking", "stop and between each retries will sleep."). Required(false). DataFormat("blocking=%t"). @@ -389,14 +389,14 @@ func addWebService(c *restful.Container) error { Returns(http.StatusOK, RespOK, devops.StopPipe{}). Writes(devops.StopPipe{})) - // match /blue/rest/organizations/jenkins/pipelines/{projectName}/pipelines/{pipelineName}/runs/{runId}/stop/ - webservice.Route(webservice.PUT("/devops/{projectName}/pipelines/{pipelineName}/runs/{runId}/stop"). + // match /blue/rest/organizations/jenkins/pipelines/{devops}/pipelines/{pipeline}/runs/{run}/stop/ + webservice.Route(webservice.POST("/devops/{devops}/pipelines/{pipeline}/runs/{run}/stop"). To(devopsapi.StopPipeline). Metadata(restfulspec.KeyOpenAPITags, tags). Doc("Stop pipeline in running"). - Param(webservice.PathParameter("projectName", "the name of devops project.")). - Param(webservice.PathParameter("pipelineName", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). - Param(webservice.PathParameter("runId", "pipeline run id, the unique id for a pipeline once build.")). + Param(webservice.PathParameter("devops", "DevOps Project's Id, e.g. project-RRRRAzLBlLEm")). + Param(webservice.PathParameter("pipeline", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). + Param(webservice.PathParameter("run", "pipeline run id, the unique id for a pipeline once build.")). Param(webservice.QueryParameter("blocking", "stop and between each retries will sleep."). Required(false). DataFormat("blocking=%t"). @@ -408,67 +408,67 @@ func addWebService(c *restful.Container) error { Returns(http.StatusOK, RespOK, devops.StopPipe{}). Writes(devops.StopPipe{})) - // match /blue/rest/organizations/jenkins/pipelines/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/Replay/ - webservice.Route(webservice.POST("/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/replay"). + // match /blue/rest/organizations/jenkins/pipelines/{devops}/pipelines/{pipeline}/branches/{branch}/runs/{run}/Replay/ + webservice.Route(webservice.POST("/devops/{devops}/pipelines/{pipeline}/branches/{branch}/runs/{run}/replay"). To(devopsapi.ReplayBranchPipeline). Metadata(restfulspec.KeyOpenAPITags, tags). Doc("Replay pipeline"). - Param(webservice.PathParameter("projectName", "the name of devops project.")). - Param(webservice.PathParameter("pipelineName", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). - Param(webservice.PathParameter("branchName", "the name of branch, same as repository brnach.")). - Param(webservice.PathParameter("runId", "pipeline run id, the unique id for a pipeline once build.")). + Param(webservice.PathParameter("devops", "DevOps Project's Id, e.g. project-RRRRAzLBlLEm")). + Param(webservice.PathParameter("pipeline", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). + Param(webservice.PathParameter("branch", "the name of branch, same as repository brnach.")). + Param(webservice.PathParameter("run", "pipeline run id, the unique id for a pipeline once build.")). Returns(http.StatusOK, RespOK, devops.ReplayPipe{}). Writes(devops.ReplayPipe{})) - // match /blue/rest/organizations/jenkins/pipelines/{projectName}/pipelines/{pipelineName}/runs/{runId}/Replay/ - webservice.Route(webservice.POST("/devops/{projectName}/pipelines/{pipelineName}/runs/{runId}/replay"). + // match /blue/rest/organizations/jenkins/pipelines/{devops}/pipelines/{pipeline}/runs/{run}/Replay/ + webservice.Route(webservice.POST("/devops/{devops}/pipelines/{pipeline}/runs/{run}/replay"). To(devopsapi.ReplayPipeline). Metadata(restfulspec.KeyOpenAPITags, tags). Doc("Replay pipeline"). - Param(webservice.PathParameter("projectName", "the name of devops project.")). - Param(webservice.PathParameter("pipelineName", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). - Param(webservice.PathParameter("runId", "pipeline run id, the unique id for a pipeline once build.")). + Param(webservice.PathParameter("devops", "DevOps Project's Id, e.g. project-RRRRAzLBlLEm")). + Param(webservice.PathParameter("pipeline", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). + Param(webservice.PathParameter("run", "pipeline run id, the unique id for a pipeline once build.")). Returns(http.StatusOK, RespOK, devops.ReplayPipe{}). Writes(devops.ReplayPipe{})) - // match /blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/branches/{branchName}/runs/{runId}/log/?start=0 - webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/log"). + // match /blue/rest/organizations/jenkins/pipelines/{devops}/{pipeline}/branches/{branch}/runs/{run}/log/?start=0 + webservice.Route(webservice.GET("/devops/{devops}/pipelines/{pipeline}/branches/{branch}/runs/{run}/log"). To(devopsapi.GetBranchRunLog). Metadata(restfulspec.KeyOpenAPITags, tags). Doc("Get Pipelines run log."). Produces("text/plain; charset=utf-8"). - Param(webservice.PathParameter("projectName", "the name of devops project.")). - Param(webservice.PathParameter("pipelineName", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). - Param(webservice.PathParameter("branchName", "the name of branch, same as repository brnach.")). - Param(webservice.PathParameter("runId", "pipeline run id, the unique id for a pipeline once build.")). + Param(webservice.PathParameter("devops", "DevOps Project's Id, e.g. project-RRRRAzLBlLEm")). + Param(webservice.PathParameter("pipeline", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). + Param(webservice.PathParameter("branch", "the name of branch, same as repository brnach.")). + Param(webservice.PathParameter("run", "pipeline run id, the unique id for a pipeline once build.")). Param(webservice.QueryParameter("start", "the count of item start."). Required(true). DataFormat("start=%d"). DefaultValue("start=0"))) - // match /blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/runs/{runId}/log/?start=0 - webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/runs/{runId}/log"). + // match /blue/rest/organizations/jenkins/pipelines/{devops}/{pipeline}/runs/{run}/log/?start=0 + webservice.Route(webservice.GET("/devops/{devops}/pipelines/{pipeline}/runs/{run}/log"). To(devopsapi.GetRunLog). Metadata(restfulspec.KeyOpenAPITags, tags). Doc("Get Pipelines run log."). Produces("text/plain; charset=utf-8"). - Param(webservice.PathParameter("projectName", "the name of devops project.")). - Param(webservice.PathParameter("pipelineName", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). - Param(webservice.PathParameter("runId", "pipeline run id, the unique id for a pipeline once build.")). + Param(webservice.PathParameter("devops", "DevOps Project's Id, e.g. project-RRRRAzLBlLEm")). + Param(webservice.PathParameter("pipeline", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). + Param(webservice.PathParameter("run", "pipeline run id, the unique id for a pipeline once build.")). Param(webservice.QueryParameter("start", "the count of item start."). Required(true). DataFormat("start=%d"). DefaultValue("start=0"))) - // match /blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/branches/{branchName}/runs/{runId}/artifacts - webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/artifacts"). + // match /blue/rest/organizations/jenkins/pipelines/{devops}/{pipeline}/branches/{branch}/runs/{run}/artifacts + webservice.Route(webservice.GET("/devops/{devops}/pipelines/{pipeline}/branches/{branch}/runs/{run}/artifacts"). To(devopsapi.GetBranchArtifacts). Metadata(restfulspec.KeyOpenAPITags, tags). Doc("Get pipeline artifacts."). - Param(webservice.PathParameter("projectName", "the name of devops project.")). - Param(webservice.PathParameter("pipelineName", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). - Param(webservice.PathParameter("branchName", "the name of branch, same as repository brnach.")). - Param(webservice.PathParameter("runId", "pipeline run id, the unique id for a pipeline once build.")). + Param(webservice.PathParameter("devops", "DevOps Project's Id, e.g. project-RRRRAzLBlLEm")). + Param(webservice.PathParameter("pipeline", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). + Param(webservice.PathParameter("branch", "the name of branch, same as repository brnach.")). + Param(webservice.PathParameter("run", "pipeline run id, the unique id for a pipeline once build.")). Param(webservice.QueryParameter("start", "the count of item start."). Required(false). DataFormat("start=%d")). @@ -478,14 +478,14 @@ func addWebService(c *restful.Container) error { Returns(http.StatusOK, "The filed of \"Url\" in response can download artifacts", []devops.Artifacts{}). Writes([]devops.Artifacts{})) - // match /blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/runs/{runId}/artifacts - webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/runs/{runId}/artifacts"). + // match /blue/rest/organizations/jenkins/pipelines/{devops}/{pipeline}/runs/{run}/artifacts + webservice.Route(webservice.GET("/devops/{devops}/pipelines/{pipeline}/runs/{run}/artifacts"). To(devopsapi.GetArtifacts). Metadata(restfulspec.KeyOpenAPITags, tags). Doc("Get pipeline artifacts."). - Param(webservice.PathParameter("projectName", "the name of devops project.")). - Param(webservice.PathParameter("pipelineName", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). - Param(webservice.PathParameter("runId", "pipeline run id, the unique id for a pipeline once build.")). + Param(webservice.PathParameter("devops", "DevOps Project's Id, e.g. project-RRRRAzLBlLEm")). + Param(webservice.PathParameter("pipeline", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). + Param(webservice.PathParameter("run", "pipeline run id, the unique id for a pipeline once build.")). Param(webservice.QueryParameter("start", "the count of item start."). Required(false). DataFormat("start=%d")). @@ -495,13 +495,13 @@ func addWebService(c *restful.Container) error { Returns(http.StatusOK, "The filed of \"Url\" in response can download artifacts", []devops.Artifacts{}). Writes([]devops.Artifacts{})) - // match /blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/branches/?filter=&start&limit= - webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/branches"). + // match /blue/rest/organizations/jenkins/pipelines/{devops}/{pipeline}/branches/?filter=&start&limit= + webservice.Route(webservice.GET("/devops/{devops}/pipelines/{pipeline}/branches"). To(devopsapi.GetPipeBranch). Metadata(restfulspec.KeyOpenAPITags, tags). Doc("Get MultiBranch pipeline branches."). - Param(webservice.PathParameter("projectName", "the name of devops project.")). - Param(webservice.PathParameter("pipelineName", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). + Param(webservice.PathParameter("devops", "DevOps Project's Id, e.g. project-RRRRAzLBlLEm")). + Param(webservice.PathParameter("pipeline", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). Param(webservice.QueryParameter("filter", "filter remote scm. e.g. origin"). Required(true). DataFormat("filter=%s")). @@ -514,170 +514,140 @@ func addWebService(c *restful.Container) error { Returns(http.StatusOK, RespOK, []devops.PipeBranch{}). Writes([]devops.PipeBranch{})) - // /blue/rest/organizations/jenkins/pipelines/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/nodes/{nodeId}/steps/{stepId} - webservice.Route(webservice.POST("/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/nodes/{nodeId}/steps/{stepId}"). + // /blue/rest/organizations/jenkins/pipelines/{devops}/pipelines/{pipeline}/branches/{branch}/runs/{run}/nodes/{node}/steps/{step} + webservice.Route(webservice.POST("/devops/{devops}/pipelines/{pipeline}/branches/{branch}/runs/{run}/nodes/{node}/steps/{step}"). To(devopsapi.CheckBranchPipeline). Metadata(restfulspec.KeyOpenAPITags, tags). Doc("Pauses pipeline execution and allows the user to interact and control the flow of the build."). Reads(devops.CheckPlayload{}). Produces("text/plain; charset=utf-8"). - Param(webservice.PathParameter("projectName", "the name of devops project.")). - Param(webservice.PathParameter("pipelineName", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). - Param(webservice.PathParameter("branchName", "the name of branch, same as repository brnach.")). - Param(webservice.PathParameter("runId", "pipeline run id, the unique id for a pipeline once build.")). - Param(webservice.PathParameter("nodeId", "pipeline node id, the one node in pipeline.")). - Param(webservice.PathParameter("stepId", "pipeline step id, the one step in pipeline."))) - - // match /blue/rest/organizations/jenkins/pipelines/{projectName}/pipelines/{pipelineName}/runs/{runId}/nodes/{nodeId}/steps/{stepId} - webservice.Route(webservice.POST("/devops/{projectName}/pipelines/{pipelineName}/runs/{runId}/nodes/{nodeId}/steps/{stepId}"). + Param(webservice.PathParameter("devops", "DevOps Project's Id, e.g. project-RRRRAzLBlLEm")). + Param(webservice.PathParameter("pipeline", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). + Param(webservice.PathParameter("branch", "the name of branch, same as repository brnach.")). + Param(webservice.PathParameter("run", "pipeline run id, the unique id for a pipeline once build.")). + Param(webservice.PathParameter("node", "pipeline node id, the one node in pipeline.")). + Param(webservice.PathParameter("step", "pipeline step id, the one step in pipeline."))) + + // match /blue/rest/organizations/jenkins/pipelines/{devops}/pipelines/{pipeline}/runs/{run}/nodes/{node}/steps/{step} + webservice.Route(webservice.POST("/devops/{devops}/pipelines/{pipeline}/runs/{run}/nodes/{node}/steps/{step}"). To(devopsapi.CheckPipeline). Metadata(restfulspec.KeyOpenAPITags, tags). Doc("Pauses pipeline execution and allows the user to interact and control the flow of the build."). Reads(devops.CheckPlayload{}). Produces("text/plain; charset=utf-8"). - Param(webservice.PathParameter("projectName", "the name of devops project.")). - Param(webservice.PathParameter("pipelineName", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). - Param(webservice.PathParameter("runId", "pipeline run id, the unique id for a pipeline once build.")). - Param(webservice.PathParameter("nodeId", "pipeline node id, the one node in pipeline.")). - Param(webservice.PathParameter("stepId", "pipeline step id"))) + Param(webservice.PathParameter("devops", "DevOps Project's Id, e.g. project-RRRRAzLBlLEm")). + Param(webservice.PathParameter("pipeline", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). + Param(webservice.PathParameter("run", "pipeline run id, the unique id for a pipeline once build.")). + Param(webservice.PathParameter("node", "pipeline node id, the one node in pipeline.")). + Param(webservice.PathParameter("step", "pipeline step id"))) // match /job/project-8QnvykoJw4wZ/job/test-1/indexing/consoleText - webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/console/log"). + webservice.Route(webservice.GET("/devops/{devops}/pipelines/{pipeline}/consolelog"). To(devopsapi.GetConsoleLog). Metadata(restfulspec.KeyOpenAPITags, tags). Doc("Get index console log."). Produces("text/plain; charset=utf-8"). - Param(webservice.PathParameter("projectName", "the name of devops project.")). - Param(webservice.PathParameter("pipelineName", "the name of pipeline, which helps to deliver continuous integration continuous deployment."))) + Param(webservice.PathParameter("devops", "DevOps Project's Id, e.g. project-RRRRAzLBlLEm")). + Param(webservice.PathParameter("pipeline", "the name of pipeline, which helps to deliver continuous integration continuous deployment."))) - // match /job/{projectName}/job/{pipelineName}/build?delay=0 - webservice.Route(webservice.POST("/devops/{projectName}/pipelines/{pipelineName}/scan"). + // match /job/{devops}/job/{pipeline}/build?delay=0 + webservice.Route(webservice.POST("/devops/{devops}/pipelines/{pipeline}/scan"). To(devopsapi.ScanBranch). Metadata(restfulspec.KeyOpenAPITags, tags). - Doc("Start a build."). + Doc("Scan remote Repositorie, Start a build if have new branch."). Produces("text/html; charset=utf-8"). - Param(webservice.PathParameter("projectName", "the name of devops project.")). - Param(webservice.PathParameter("pipelineName", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). + Param(webservice.PathParameter("devops", "DevOps Project's Id, e.g. project-RRRRAzLBlLEm")). + Param(webservice.PathParameter("pipeline", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). Param(webservice.QueryParameter("delay", "will be delay time to scan."). Required(false). DataFormat("delay=%d"))) - // match /blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/branches/{}/runs/ - webservice.Route(webservice.POST("/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/run"). + // match /blue/rest/organizations/jenkins/pipelines/{devops}/{pipeline}/branches/{}/runs/ + webservice.Route(webservice.POST("/devops/{devops}/pipelines/{pipeline}/branches/{branch}/run"). To(devopsapi.RunBranchPipeline). Metadata(restfulspec.KeyOpenAPITags, tags). Doc("Run pipeline."). Reads(devops.RunPayload{}). - Param(webservice.PathParameter("projectName", "the name of devops project.")). - Param(webservice.PathParameter("pipelineName", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). - Param(webservice.PathParameter("branchName", "the name of branch, same as repository brnach.")). + Param(webservice.PathParameter("devops", "DevOps Project's Id, e.g. project-RRRRAzLBlLEm")). + Param(webservice.PathParameter("pipeline", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). + Param(webservice.PathParameter("branch", "the name of branch, same as repository brnach.")). Returns(http.StatusOK, RespOK, devops.QueuedBlueRun{}). Writes(devops.QueuedBlueRun{})) - // match /blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/runs/ - webservice.Route(webservice.POST("/devops/{projectName}/pipelines/{pipelineName}/run"). + // match /blue/rest/organizations/jenkins/pipelines/{devops}/{pipeline}/runs/ + webservice.Route(webservice.POST("/devops/{devops}/pipelines/{pipeline}/run"). To(devopsapi.RunPipeline). Metadata(restfulspec.KeyOpenAPITags, tags). Doc("Run pipeline."). Reads(devops.RunPayload{}). - Param(webservice.PathParameter("projectName", "the name of devops project.")). - Param(webservice.PathParameter("pipelineName", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). + Param(webservice.PathParameter("devops", "DevOps Project's Id, e.g. project-RRRRAzLBlLEm")). + Param(webservice.PathParameter("pipeline", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). Returns(http.StatusOK, RespOK, devops.QueuedBlueRun{}). Writes(devops.QueuedBlueRun{})) - // match /pipeline_status/blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/branches/{branchName}/runs/{runId}/nodes/?limit= - webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/nodes/{nodeId}/steps/status"). - To(devopsapi.GetBranchStepsStatus). - Metadata(restfulspec.KeyOpenAPITags, tags). - Doc("Get pipeline steps status."). - Param(webservice.PathParameter("projectName", "the name of devops project.")). - Param(webservice.PathParameter("pipelineName", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). - Param(webservice.PathParameter("branchName", "the name of branch, same as repository brnach.")). - Param(webservice.PathParameter("runId", "pipeline run id, the unique id for a pipeline once build.")). - Param(webservice.PathParameter("nodeId", "pipeline node id, the one node in pipeline.")). - Param(webservice.QueryParameter("limit", "the count of item limit."). - Required(true). - DataFormat("limit=%d")). - Returns(http.StatusOK, RespOK, []devops.QueuedBlueRun{}). - Writes([]devops.QueuedBlueRun{})) - - // match /pipeline_status/blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/runs/{runId}/nodes/?limit= - webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/runs/{runId}/nodes/{nodeId}/steps/status"). - To(devopsapi.GetStepsStatus). - Metadata(restfulspec.KeyOpenAPITags, tags). - Doc("Get pipeline steps status."). - Param(webservice.PathParameter("projectName", "the name of devops project.")). - Param(webservice.PathParameter("pipelineName", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). - Param(webservice.PathParameter("runId", "pipeline run id, the unique id for a pipeline once build.")). - Param(webservice.PathParameter("nodeId", "pipeline node id, the one node in pipeline.")). - Param(webservice.QueryParameter("limit", "the count of item limit."). - Required(true). - DataFormat("limit=%d")). - Returns(http.StatusOK, RespOK, []devops.QueuedBlueRun{}). - Writes([]devops.QueuedBlueRun{})) - // match /crumbIssuer/api/json/ - webservice.Route(webservice.GET("/devops/crumbissuer"). + webservice.Route(webservice.GET("/crumbissuer"). To(devopsapi.GetCrumb). Metadata(restfulspec.KeyOpenAPITags, tags). Doc("Get crumb issuer. A CrumbIssuer represents an algorithm to generate a nonce value, known as a crumb, to counter cross site request forgery exploits. Crumbs are typically hashes incorporating information that uniquely identifies an agent that sends a request, along with a guarded secret so that the crumb value cannot be forged by a third party."). Returns(http.StatusOK, RespOK, devops.Crumb{}). Writes(devops.Crumb{})) - // match /job/init-job/descriptorByName/org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition/checkScriptCompile - webservice.Route(webservice.POST("/devops/check/scriptcompile"). - To(devopsapi.CheckScriptCompile). - Metadata(restfulspec.KeyOpenAPITags, tags). - Consumes("application/x-www-form-urlencoded", "charset=utf-8"). - Produces("application/json", "charset=utf-8"). - Doc("Check pipeline script compile."). - Reads(devops.ReqScript{}). - Returns(http.StatusOK, RespOK, devops.CheckScript{}). - Writes(devops.CheckScript{})) + // TODO are not used in this version. will be added in 2.1.0 + //// match /job/init-job/descriptorByName/org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition/checkScriptCompile + //webservice.Route(webservice.POST("/devops/check/scriptcompile"). + // To(devopsapi.CheckScriptCompile). + // Metadata(restfulspec.KeyOpenAPITags, tags). + // Consumes("application/x-www-form-urlencoded", "charset=utf-8"). + // Produces("application/json", "charset=utf-8"). + // Doc("Check pipeline script compile."). + // Reads(devops.ReqScript{}). + // Returns(http.StatusOK, RespOK, devops.CheckScript{}). + // Writes(devops.CheckScript{})) // match /job/init-job/descriptorByName/hudson.triggers.TimerTrigger/checkSpec - webservice.Route(webservice.GET("/devops/check/cron"). - To(devopsapi.CheckCron). - Metadata(restfulspec.KeyOpenAPITags, tags). - Produces("application/json", "charset=utf-8"). - Doc("Check cron script compile."). - Param(webservice.QueryParameter("value", "string of cron script."). - Required(true). - DataFormat("value=%s")). - Returns(http.StatusOK, RespOK, []devops.QueuedBlueRun{}). - Returns(http.StatusOK, RespOK, devops.CheckCronRes{}). - Writes(devops.CheckCronRes{})) - - // match /blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/runs/{runId}/ - webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/runs/{runId}"). + //webservice.Route(webservice.GET("/devops/check/cron"). + // To(devopsapi.CheckCron). + // Metadata(restfulspec.KeyOpenAPITags, tags). + // Produces("application/json", "charset=utf-8"). + // Doc("Check cron script compile."). + // Param(webservice.QueryParameter("value", "string of cron script."). + // Required(true). + // DataFormat("value=%s")). + // Returns(http.StatusOK, RespOK, []devops.QueuedBlueRun{}). + // Returns(http.StatusOK, RespOK, devops.CheckCronRes{}). + // Writes(devops.CheckCronRes{})) + + // match /blue/rest/organizations/jenkins/pipelines/{devops}/{pipeline}/runs/{run}/ + webservice.Route(webservice.GET("/devops/{devops}/pipelines/{pipeline}/runs/{run}"). To(devopsapi.GetPipelineRun). Metadata(restfulspec.KeyOpenAPITags, tags). Doc("Get run pipeline in project."). - Param(webservice.PathParameter("projectName", "the name of devops project")). - Param(webservice.PathParameter("pipelineName", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). - Param(webservice.PathParameter("runId", "pipeline run id, the unique id for a pipeline once build.")). + Param(webservice.PathParameter("devops", "the name of devops project")). + Param(webservice.PathParameter("pipeline", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). + Param(webservice.PathParameter("run", "pipeline run id, the unique id for a pipeline once build.")). Returns(http.StatusOK, RespOK, devops.PipelineRun{}). Writes(devops.PipelineRun{})) - // match /blue/rest/organizations/jenkins/pipelines/{projectName}/pipelines/{pipelineName}/branches/{branchName} - webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}"). + // match /blue/rest/organizations/jenkins/pipelines/{devops}/pipelines/{pipeline}/branches/{branch} + webservice.Route(webservice.GET("/devops/{devops}/pipelines/{pipeline}/branches/{branch}"). To(devopsapi.GetBranchPipeline). Metadata(restfulspec.KeyOpenAPITags, tags). Doc("Get Pipeline run by branch."). - Param(webservice.PathParameter("projectName", "the name of devops project")). - Param(webservice.PathParameter("pipelineName", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). - Param(webservice.PathParameter("branchName", "the name of branch, same as repository brnach")). + Param(webservice.PathParameter("devops", "the name of devops project")). + Param(webservice.PathParameter("pipeline", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). + Param(webservice.PathParameter("branch", "the name of branch, same as repository brnach")). Returns(http.StatusOK, RespOK, devops.BranchPipeline{}). Writes(devops.BranchPipeline{})) - // match /blue/rest/organizations/jenkins/pipelines/{projectName}/pipelines/{pipelineName}/runs/{runId}/nodes/?limit=10000 - webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/runs/{runId}/nodes"). + // match /blue/rest/organizations/jenkins/pipelines/{devops}/pipelines/{pipeline}/runs/{run}/nodes/?limit=10000 + webservice.Route(webservice.GET("/devops/{devops}/pipelines/{pipeline}/runs/{run}/nodes"). To(devopsapi.GetPipelineRunNodes). Metadata(restfulspec.KeyOpenAPITags, tags). Doc("Get Pipeline run nodes."). - Param(webservice.PathParameter("projectName", "the name of devops project")). - Param(webservice.PathParameter("pipelineName", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). - Param(webservice.PathParameter("runId", "pipeline run id, the unique id for a pipeline once build")). + Param(webservice.PathParameter("devops", "the name of devops project")). + Param(webservice.PathParameter("pipeline", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). + Param(webservice.PathParameter("run", "pipeline run id, the unique id for a pipeline once build")). Param(webservice.QueryParameter("limit", "the count of item limit"). Required(false). DataFormat("limit=%d")). @@ -685,15 +655,15 @@ func addWebService(c *restful.Container) error { Writes([]devops.PipelineRunNodes{})) // match /blue/rest/organizations/jenkins/pipelines/%s/%s/branches/%s/runs/%s/nodes/%s/steps/?limit= - webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/nodes/{nodeId}/steps"). + webservice.Route(webservice.GET("/devops/{devops}/pipelines/{pipeline}/branches/{branch}/runs/{run}/nodes/{node}/steps"). To(devopsapi.GetBranchNodeSteps). Metadata(restfulspec.KeyOpenAPITags, tags). Doc("Get steps in node by branch."). - Param(webservice.PathParameter("projectName", "the name of devops project")). - Param(webservice.PathParameter("pipelineName", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). - Param(webservice.PathParameter("branchName", "the name of branch, same as repository brnach.")). - Param(webservice.PathParameter("runId", "pipeline run id, the unique id for a pipeline once build.")). - Param(webservice.PathParameter("nodeId", "pipeline node id, the one node in pipeline.")). + Param(webservice.PathParameter("devops", "the name of devops project")). + Param(webservice.PathParameter("pipeline", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). + Param(webservice.PathParameter("branch", "the name of branch, same as repository brnach.")). + Param(webservice.PathParameter("run", "pipeline run id, the unique id for a pipeline once build.")). + Param(webservice.PathParameter("node", "pipeline node id, the one node in pipeline.")). Param(webservice.QueryParameter("limit", "the count of item limit."). Required(false). DataFormat("limit=%d")). @@ -701,14 +671,14 @@ func addWebService(c *restful.Container) error { Writes([]devops.NodeSteps{})) // match /blue/rest/organizations/jenkins/pipelines/%s/%s/runs/%s/nodes/%s/steps/?limit= - webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/runs/{runId}/nodes/{nodeId}/steps"). + webservice.Route(webservice.GET("/devops/{devops}/pipelines/{pipeline}/runs/{run}/nodes/{node}/steps"). To(devopsapi.GetNodeSteps). Metadata(restfulspec.KeyOpenAPITags, tags). Doc("Get steps in node."). - Param(webservice.PathParameter("projectName", "the name of devops project")). - Param(webservice.PathParameter("pipelineName", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). - Param(webservice.PathParameter("runId", "pipeline run id, the unique id for a pipeline once build")). - Param(webservice.PathParameter("nodeId", "pipeline node id, the one node in pipeline.")). + Param(webservice.PathParameter("devops", "the name of devops project")). + Param(webservice.PathParameter("pipeline", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). + Param(webservice.PathParameter("run", "pipeline run id, the unique id for a pipeline once build")). + Param(webservice.PathParameter("node", "pipeline node id, the one node in pipeline.")). Param(webservice.QueryParameter("limit", "the count of item limit."). Required(false). DataFormat("limit=%d")). @@ -716,7 +686,7 @@ func addWebService(c *restful.Container) error { Writes([]devops.NodeSteps{})) // match /pipeline-model-converter/toJenkinsfile - webservice.Route(webservice.POST("/devops/tojenkinsfile"). + webservice.Route(webservice.POST("/tojenkinsfile"). To(devopsapi.ToJenkinsfile). Metadata(restfulspec.KeyOpenAPITags, tags). Consumes("application/x-www-form-urlencoded"). @@ -727,7 +697,7 @@ func addWebService(c *restful.Container) error { Writes(devops.ResJenkinsfile{})) // match /pipeline-model-converter/toJson - webservice.Route(webservice.POST("/devops/tojson"). + webservice.Route(webservice.POST("/tojson"). To(devopsapi.ToJson). Metadata(restfulspec.KeyOpenAPITags, tags). Consumes("application/x-www-form-urlencoded"). @@ -738,40 +708,40 @@ func addWebService(c *restful.Container) error { Writes(devops.ResJson{})) // match /git/notifyCommit/?url= - webservice.Route(webservice.GET("/devops/notifycommit"). + webservice.Route(webservice.GET("/webhook/git"). To(devopsapi.GetNotifyCommit). Metadata(restfulspec.KeyOpenAPITags, tags). - Doc("Get notification commit by HTTP GET method."). + Doc("Get commit notification by HTTP GET method. Git webhook will request here."). Produces("text/plain; charset=utf-8"). Param(webservice.QueryParameter("url", "url of git scm"). Required(true). DataFormat("url=%s"))) // Gitlab or some other scm managers can only use HTTP method. match /git/notifyCommit/?url= - webservice.Route(webservice.POST("/devops/notifycommit"). + webservice.Route(webservice.POST("/webhook/git"). To(devopsapi.PostNotifyCommit). Metadata(restfulspec.KeyOpenAPITags, tags). - Doc("Get notification commit by HTTP POST method."). + Doc("Get commit notification by HTTP POST method. Git webhook will request here."). Consumes("application/json"). Produces("text/plain; charset=utf-8"). Param(webservice.QueryParameter("url", "url of git scm"). Required(true). DataFormat("url=%s"))) - webservice.Route(webservice.POST("/devops/github/webhook"). + webservice.Route(webservice.POST("/webhook/github"). To(devopsapi.GithubWebhook). Metadata(restfulspec.KeyOpenAPITags, tags). - Doc("receive webhook request.")) + Doc("Get commit notification. Github webhook will request here.")) // in scm get all steps in nodes. - webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/nodesdetail"). + webservice.Route(webservice.GET("/devops/{devops}/pipelines/{pipeline}/branches/{branch}/runs/{run}/nodesdetail"). To(devopsapi.GetBranchNodesDetail). Metadata(restfulspec.KeyOpenAPITags, tags). Doc("Gives steps details inside a pipeline node by branch. For a Stage, the steps will include all the steps defined inside the stage."). - Param(webservice.PathParameter("projectName", "the name of devops project.")). - Param(webservice.PathParameter("pipelineName", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). - Param(webservice.PathParameter("branchName", "the name of branch, same as repository brnach.")). - Param(webservice.PathParameter("runId", "pipeline run id, the unique id for a pipeline once build.")). + Param(webservice.PathParameter("devops", "DevOps Project's Id, e.g. project-RRRRAzLBlLEm")). + Param(webservice.PathParameter("pipeline", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). + Param(webservice.PathParameter("branch", "the name of branch, same as repository brnach.")). + Param(webservice.PathParameter("run", "pipeline run id, the unique id for a pipeline once build.")). Param(webservice.QueryParameter("limit", "the count of item limit."). Required(true). DataFormat("limit=%d")). @@ -779,14 +749,14 @@ func addWebService(c *restful.Container) error { Writes(devops.NodesDetail{})) // out of scm get all steps in nodes. - webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/runs/{runId}/nodesdetail"). + webservice.Route(webservice.GET("/devops/{devops}/pipelines/{pipeline}/runs/{run}/nodesdetail"). To(devopsapi.GetNodesDetail). Metadata(restfulspec.KeyOpenAPITags, tags). Doc("Gives steps details inside a pipeline node. For a Stage, the steps will include all the steps defined inside the stage."). - Param(webservice.PathParameter("projectName", "the name of devops project.")). - Param(webservice.PathParameter("pipelineName", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). - Param(webservice.PathParameter("branchName", "the name of branch, same as repository brnach.")). - Param(webservice.PathParameter("runId", "pipeline run id, the unique id for a pipeline once build.")). + Param(webservice.PathParameter("devops", "DevOps Project's Id, e.g. project-RRRRAzLBlLEm")). + Param(webservice.PathParameter("pipeline", "the name of pipeline, which helps to deliver continuous integration continuous deployment.")). + Param(webservice.PathParameter("branch", "the name of branch, same as repository brnach.")). + Param(webservice.PathParameter("run", "pipeline run id, the unique id for a pipeline once build.")). Param(webservice.QueryParameter("limit", "the count of item limit."). Required(true). DataFormat("limit=%d")). diff --git a/pkg/apis/iam/v1alpha2/register.go b/pkg/apis/iam/v1alpha2/register.go index 719dd000736f5d60161e411d85d4489abe36aee0..955448c50cc661bcf0e7ceb4ab7a16cfaa2ea946 100644 --- a/pkg/apis/iam/v1alpha2/register.go +++ b/pkg/apis/iam/v1alpha2/register.go @@ -116,15 +116,15 @@ func addWebService(c *restful.Container) error { Returns(http.StatusOK, ok, iam.TokenReview{}). Metadata(restfulspec.KeyOpenAPITags, tags)) ws.Route(ws.POST("/login"). - To(iam.LoginHandler). + To(iam.Login). Doc("KubeSphere APIs support token-based authentication via the Authtoken request header. The POST Login API is used to retrieve the authentication token. After the authentication token is obtained, it must be inserted into the Authtoken header for all requests."). Reads(iam.LoginRequest{}). Returns(http.StatusOK, ok, models.Token{}). Metadata(restfulspec.KeyOpenAPITags, tags)) - ws.Route(ws.GET("/users/{username}"). + ws.Route(ws.GET("/users/{user}"). To(iam.DescribeUser). - Doc("Describes the specified user."). - Param(ws.PathParameter("username", "username")). + Doc("Describe the specified user."). + Param(ws.PathParameter("user", "username")). Returns(http.StatusOK, ok, models.User{}). Metadata(restfulspec.KeyOpenAPITags, tags)) ws.Route(ws.POST("/users"). @@ -133,23 +133,23 @@ func addWebService(c *restful.Container) error { Reads(CreateUserRequest{}). Returns(http.StatusOK, ok, errors.Error{}). Metadata(restfulspec.KeyOpenAPITags, tags)) - ws.Route(ws.DELETE("/users/{username}"). + ws.Route(ws.DELETE("/users/{user}"). To(iam.DeleteUser). Doc("Remove a specified user."). - Param(ws.PathParameter("username", "username")). + Param(ws.PathParameter("user", "username")). Returns(http.StatusOK, ok, errors.Error{}). Metadata(restfulspec.KeyOpenAPITags, tags)) - ws.Route(ws.PUT("/users/{username}"). + ws.Route(ws.PUT("/users/{user}"). To(iam.UpdateUser). Doc("Updates information about the specified user."). - Param(ws.PathParameter("username", "username")). + Param(ws.PathParameter("user", "username")). Reads(UserUpdateRequest{}). Returns(http.StatusOK, ok, errors.Error{}). Metadata(restfulspec.KeyOpenAPITags, tags)) - ws.Route(ws.GET("/users/{username}/log"). - To(iam.UserLoginLog). + ws.Route(ws.GET("/users/{user}/logs"). + To(iam.UserLoginLogs). Doc("This method is used to retrieve the \"login logs\" for the specified user."). - Param(ws.PathParameter("username", "username")). + Param(ws.PathParameter("user", "username")). Returns(http.StatusOK, ok, LoginLog{}). Metadata(restfulspec.KeyOpenAPITags, tags)) ws.Route(ws.GET("/users"). @@ -160,43 +160,39 @@ func addWebService(c *restful.Container) error { ws.Route(ws.GET("/groups"). To(iam.ListGroups). Doc("List all user groups."). - Returns(http.StatusOK, ok, []models.Group{}). - Metadata(restfulspec.KeyOpenAPITags, tags)) - ws.Route(ws.GET("/groups/{path}"). + Returns(http.StatusOK, ok, []models.Group{})) + ws.Route(ws.GET("/groups/{group}"). To(iam.DescribeGroup). - Doc("Describes the specified user group."). - Param(ws.PathParameter("path", "user group path separated by colon.")). - Returns(http.StatusOK, ok, models.Group{}). - Metadata(restfulspec.KeyOpenAPITags, tags)) - ws.Route(ws.GET("/groups/{path}/users"). + Doc("Describe the specified user group."). + Param(ws.PathParameter("group", "user group path separated by colon.")). + Returns(http.StatusOK, ok, models.Group{})) + ws.Route(ws.GET("/groups/{group}/users"). To(iam.ListGroupUsers). Doc("List all users in the specified user group."). - Param(ws.PathParameter("path", "user group path separated by colon.")). - Returns(http.StatusOK, ok, []models.User{}). - Metadata(restfulspec.KeyOpenAPITags, tags)) + Param(ws.PathParameter("group", "user group path separated by colon.")). + Returns(http.StatusOK, ok, []models.User{})) ws.Route(ws.POST("/groups"). To(iam.CreateGroup). Doc("Create a user group."). Reads(models.Group{}). - Returns(http.StatusOK, ok, models.Group{}). - Metadata(restfulspec.KeyOpenAPITags, tags)) - ws.Route(ws.DELETE("/groups/{path}"). + Returns(http.StatusOK, ok, models.Group{})) + ws.Route(ws.DELETE("/groups/{group}"). To(iam.DeleteGroup). Doc("Delete a user group."). - Param(ws.PathParameter("path", "user group path separated by colon.")). + Param(ws.PathParameter("group", "user group path separated by colon.")). Returns(http.StatusOK, ok, errors.Error{}). Metadata(restfulspec.KeyOpenAPITags, tags)) - ws.Route(ws.PUT("/groups/{path}"). + ws.Route(ws.PUT("/groups/{group}"). To(iam.UpdateGroup). Doc("Updates information about the user group."). - Param(ws.PathParameter("path", "user group path separated by colon.")). + Param(ws.PathParameter("group", "user group path separated by colon.")). Reads(models.Group{}). Returns(http.StatusOK, ok, models.Group{}). Metadata(restfulspec.KeyOpenAPITags, tags)) - ws.Route(ws.GET("/users/{username}/roles"). + ws.Route(ws.GET("/users/{user}/roles"). To(iam.ListUserRoles). Doc("This method is used to retrieve all the roles that are assigned to the user."). - Param(ws.PathParameter("username", "username")). + Param(ws.PathParameter("user", "username")). Returns(http.StatusOK, ok, iam.RoleList{}). Metadata(restfulspec.KeyOpenAPITags, tags)) ws.Route(ws.GET("/namespaces/{namespace}/roles"). @@ -267,7 +263,7 @@ func addWebService(c *restful.Container) error { Metadata(restfulspec.KeyOpenAPITags, tags)) ws.Route(ws.GET("/workspaces/{workspace}/roles/{role}"). To(iam.DescribeWorkspaceRole). - Doc("Describes the workspace role."). + Doc("Describe the workspace role."). Param(ws.PathParameter("workspace", "workspace name")). Param(ws.PathParameter("role", "workspace role name")). Returns(http.StatusOK, ok, rbacv1.ClusterRole{}). @@ -292,18 +288,18 @@ func addWebService(c *restful.Container) error { Reads(InviteUserRequest{}). Returns(http.StatusOK, ok, errors.Error{}). Metadata(restfulspec.KeyOpenAPITags, tags)) - ws.Route(ws.DELETE("/workspaces/{workspace}/members/{username}"). + ws.Route(ws.DELETE("/workspaces/{workspace}/members/{member}"). To(iam.RemoveUser). Doc("Remove members from workspace."). Param(ws.PathParameter("workspace", "workspace name")). - Param(ws.PathParameter("username", "username")). + Param(ws.PathParameter("member", "username")). Returns(http.StatusOK, ok, errors.Error{}). Metadata(restfulspec.KeyOpenAPITags, tags)) - ws.Route(ws.GET("/workspaces/{workspace}/members/{username}"). + ws.Route(ws.GET("/workspaces/{workspace}/members/{member}"). To(iam.DescribeWorkspaceUser). - Doc("Describes the specified user."). + Doc("Describe the specified user."). Param(ws.PathParameter("workspace", "workspace name")). - Param(ws.PathParameter("username", "username")). + Param(ws.PathParameter("member", "username")). Returns(http.StatusOK, ok, DescribeWorkspaceUserResponse{}). Metadata(restfulspec.KeyOpenAPITags, tags)) c.Add(ws) diff --git a/pkg/apis/logging/v1alpha2/register.go b/pkg/apis/logging/v1alpha2/register.go index 705579bf47ce8f6ff405fb51136866f198d3db9c..1e2d23035124d905d02c34af2dc017cbcbba6644 100644 --- a/pkg/apis/logging/v1alpha2/register.go +++ b/pkg/apis/logging/v1alpha2/register.go @@ -186,20 +186,6 @@ func addWebService(c *restful.Container) error { Consumes(restful.MIME_JSON, restful.MIME_XML). Produces(restful.MIME_JSON) - ws.Route(ws.GET("/fluentbit/filters").To(logging.LoggingQueryFluentbitFilters). - Filter(filter.Logging). - Doc("List all Fluent bit filter plugins. This API is work-in-process."). - Metadata(restfulspec.KeyOpenAPITags, []string{"Logging", "setting"})). - Consumes(restful.MIME_JSON, restful.MIME_XML). - Produces(restful.MIME_JSON) - - ws.Route(ws.POST("/fluentbit/filters").To(logging.LoggingUpdateFluentbitFilters). - Filter(filter.Logging). - Doc("Add a new Fluent bit filter plugin. This API is work-in-process."). - Metadata(restfulspec.KeyOpenAPITags, []string{"Logging", "setting"})). - Consumes(restful.MIME_JSON, restful.MIME_XML). - Produces(restful.MIME_JSON) - ws.Route(ws.GET("/fluentbit/outputs").To(logging.LoggingQueryFluentbitOutputs). Filter(filter.Logging). Doc("List all Fluent bit output plugins."). diff --git a/pkg/apis/monitoring/v1alpha2/register.go b/pkg/apis/monitoring/v1alpha2/register.go index 5cfd548870fcda205c8e91964092cf2711ed14d8..4f9d97dbe2ffe4343d0a7e3a3645efb40ddd0834 100644 --- a/pkg/apis/monitoring/v1alpha2/register.go +++ b/pkg/apis/monitoring/v1alpha2/register.go @@ -227,10 +227,10 @@ func addWebService(c *restful.Container) error { // Only use this api to monitor status of pods under the {workload} // To monitor a specific workload, try the next two apis with "resources_filter" - ws.Route(ws.GET("/namespaces/{namespace}/workloads/{workload_kind}/{workload}").To(monitoring.MonitorSpecificWorkload). + ws.Route(ws.GET("/namespaces/{namespace}/workloads/{kind}/{workload}").To(monitoring.MonitorSpecificWorkload). Doc("Get specific workload metrics under a given namespace."). Param(ws.PathParameter("namespace", "Specify the target namespace.").DataType("string").Required(true)). - Param(ws.PathParameter("workload_kind", "Specify the target workload kind. One of deployment, daemonset, statefulset. Other values will be interpreted as any of three.").DataType("string").Required(true).DefaultValue("(.*)")). + Param(ws.PathParameter("kind", "Specify the target workload kind. One of deployment, daemonset, statefulset. Other values will be interpreted as any of three.").DataType("string").Required(true).DefaultValue("(.*)")). Param(ws.PathParameter("workload", "Specify the target workload.").DataType("string").Required(true)). Param(ws.QueryParameter("metrics_filter", "Metrics filter in regexp pattern, eg. workload_cpu|workload_memory.").DataType("string").Required(false)). Param(ws.QueryParameter("step", "Used to get metrics over a range of time. Query resolution step. eg. 10m.").DataType("string").Required(false)). @@ -243,10 +243,10 @@ func addWebService(c *restful.Container) error { Consumes(restful.MIME_JSON, restful.MIME_XML). Produces(restful.MIME_JSON) - ws.Route(ws.GET("/namespaces/{namespace}/workloads/{workload_kind}").To(monitoring.MonitorAllWorkloadsOfSpecificKind). + ws.Route(ws.GET("/namespaces/{namespace}/workloads/{kind}").To(monitoring.MonitorAllWorkloadsOfSpecificKind). Doc("Get all workload-level metrics of a specific workload kind under a given namespace."). Param(ws.PathParameter("namespace", "Specify the target namespace.").DataType("string").Required(true)). - Param(ws.PathParameter("workload_kind", "Specify the target workload kind. One of deployment, daemonset, statefulset. Other values will be interpreted as any of three.").DataType("string").Required(true).DefaultValue("(.*)")). + Param(ws.PathParameter("kind", "Specify the target workload kind. One of deployment, daemonset, statefulset. Other values will be interpreted as any of three.").DataType("string").Required(true).DefaultValue("(.*)")). Param(ws.QueryParameter("metrics_filter", "Metrics filter in regexp pattern, eg. node_cpu|node_memory.").DataType("string").Required(false)). Param(ws.QueryParameter("resources_filter", "Workload filter in regexp pattern.").DataType("string").Required(false)). Param(ws.QueryParameter("sort_metric", "Sort workloads by the specified metric. Valid only if type is rank.").DataType("string").Required(false)). diff --git a/pkg/apis/operations/v1alpha2/register.go b/pkg/apis/operations/v1alpha2/register.go index b3b23d755169c716275855c573782f7df54f92aa..06352280cd1cc6b077b91ee1ca73e4a6e947c172 100644 --- a/pkg/apis/operations/v1alpha2/register.go +++ b/pkg/apis/operations/v1alpha2/register.go @@ -19,7 +19,6 @@ package v1alpha2 import ( "github.com/emicklei/go-restful" - "github.com/emicklei/go-restful-openapi" "k8s.io/apimachinery/pkg/runtime/schema" "kubesphere.io/kubesphere/pkg/apiserver/operations" "kubesphere.io/kubesphere/pkg/apiserver/runtime" @@ -38,20 +37,17 @@ var ( func addWebService(c *restful.Container) error { - tags := []string{"Operations"} ok := "ok" webservice := runtime.NewWebService(GroupVersion) webservice.Route(webservice.POST("/nodes/{node}/drainage"). To(operations.DrainNode). - Metadata(restfulspec.KeyOpenAPITags, tags). Doc("Drain node"). Param(webservice.PathParameter("node", "node name")). Returns(http.StatusOK, ok, errors.Error{})) webservice.Route(webservice.POST("/namespaces/{namespace}/jobs/{job}"). To(operations.RerunJob). - Metadata(restfulspec.KeyOpenAPITags, tags). Doc("Job rerun"). Param(webservice.PathParameter("job", "job name")). Param(webservice.PathParameter("namespace", "job's namespace")). diff --git a/pkg/apis/resources/v1alpha2/register.go b/pkg/apis/resources/v1alpha2/register.go index 824adfa66b426f3f762cf7108d9de2c2e4f28e2b..c78ca754cf2a778b0340c41e4bfdf2e0eb4ce162 100644 --- a/pkg/apis/resources/v1alpha2/register.go +++ b/pkg/apis/resources/v1alpha2/register.go @@ -25,6 +25,7 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "kubesphere.io/kubesphere/pkg/apiserver/components" "kubesphere.io/kubesphere/pkg/apiserver/git" + "kubesphere.io/kubesphere/pkg/apiserver/operations" "kubesphere.io/kubesphere/pkg/apiserver/quotas" "kubesphere.io/kubesphere/pkg/apiserver/registries" "kubesphere.io/kubesphere/pkg/apiserver/resources" @@ -74,6 +75,15 @@ func addWebService(c *restful.Container) error { DefaultValue("limit=10,page=1")). Returns(http.StatusOK, ok, models.PageableResponse{})) + webservice.Route(webservice.POST("/namespaces/{namespace}/jobs/{job}"). + To(operations.RerunJob). + Metadata(restfulspec.KeyOpenAPITags, tags). + Doc("Rerun job whether the job is complete or not"). + Param(webservice.PathParameter("job", "job name")). + Param(webservice.PathParameter("namespace", "job's namespace")). + Param(webservice.QueryParameter("a", "action")). + Returns(http.StatusOK, ok, errors.Error{})) + tags = []string{"Cluster resources"} webservice.Route(webservice.GET("/{resources}"). @@ -91,6 +101,13 @@ func addWebService(c *restful.Container) error { DataFormat("limit=%d,page=%d"). DefaultValue("limit=10,page=1"))) + webservice.Route(webservice.POST("/nodes/{node}/drainage"). + To(operations.DrainNode). + Metadata(restfulspec.KeyOpenAPITags, tags). + Doc("Drain node"). + Param(webservice.PathParameter("node", "node name")). + Returns(http.StatusOK, ok, errors.Error{})) + tags = []string{"Applications"} webservice.Route(webservice.GET("/applications"). @@ -124,13 +141,13 @@ func addWebService(c *restful.Container) error { DataFormat("limit=%d,page=%d"). DefaultValue("limit=10,page=1"))) - webservice.Route(webservice.GET("/namespaces/{namespace}/applications/{cluster_id}"). + webservice.Route(webservice.GET("/namespaces/{namespace}/applications/{application}"). To(resources.DescribeApplication). Returns(http.StatusOK, ok, applications.Application{}). Metadata(restfulspec.KeyOpenAPITags, tags). Doc("Describe application"). Param(webservice.PathParameter("namespace", "namespace name")). - Param(webservice.PathParameter("cluster_id", "application id"))) + Param(webservice.PathParameter("application", "application id"))) webservice.Route(webservice.POST("/namespaces/{namespace}/applications"). To(resources.DeployApplication). @@ -140,28 +157,28 @@ func addWebService(c *restful.Container) error { Returns(http.StatusOK, ok, errors.Error{}). Param(webservice.PathParameter("namespace", "namespace name"))) - webservice.Route(webservice.DELETE("/namespaces/{namespace}/applications/{cluster_id}"). + webservice.Route(webservice.DELETE("/namespaces/{namespace}/applications/{application}"). To(resources.DeleteApplication). Doc("Delete application"). Metadata(restfulspec.KeyOpenAPITags, tags). Returns(http.StatusOK, ok, errors.Error{}). Param(webservice.PathParameter("namespace", "namespace name")). - Param(webservice.PathParameter("cluster_id", "application id"))) + Param(webservice.PathParameter("application", "application id"))) tags = []string{"User resources"} - webservice.Route(webservice.GET("/users/{username}/kubectl"). + webservice.Route(webservice.GET("/users/{user}/kubectl"). To(resources.GetKubectl). Doc("get user's kubectl pod"). - Param(webservice.PathParameter("username", "username")). + Param(webservice.PathParameter("user", "username")). Metadata(restfulspec.KeyOpenAPITags, tags). Returns(http.StatusOK, ok, models.PodInfo{})) - webservice.Route(webservice.GET("/users/{username}/kubeconfig"). + webservice.Route(webservice.GET("/users/{user}/kubeconfig"). Produces("text/plain"). To(resources.GetKubeconfig). Doc("get users' kubeconfig"). - Param(webservice.PathParameter("username", "username")). + Param(webservice.PathParameter("user", "username")). Returns(http.StatusOK, ok, ""). Metadata(restfulspec.KeyOpenAPITags, tags)) @@ -178,7 +195,7 @@ func addWebService(c *restful.Container) error { Doc(""). Param(webservice.PathParameter("component", "component name")). Returns(http.StatusOK, ok, models.Component{})) - webservice.Route(webservice.GET("/health"). + webservice.Route(webservice.GET("/componenthealth"). To(components.GetSystemHealthStatus). Metadata(restfulspec.KeyOpenAPITags, tags). Doc(""). @@ -202,7 +219,7 @@ func addWebService(c *restful.Container) error { tags = []string{"Registries"} - webservice.Route(webservice.POST("registries/verify"). + webservice.Route(webservice.POST("registry/verify"). To(registries.RegistryVerify). Metadata(restfulspec.KeyOpenAPITags, tags). Doc("docker registry verify"). @@ -279,17 +296,17 @@ func addWebService(c *restful.Container) error { tags = []string{"WorkloadStatus"} - webservice.Route(webservice.GET("/workloadstatuses"). + webservice.Route(webservice.GET("/abnormalworkloads"). Doc("get abnormal workloads' count of whole cluster"). Metadata(restfulspec.KeyOpenAPITags, tags). Returns(http.StatusOK, ok, status.WorkLoadStatus{}). - To(workloadstatuses.GetClusterResourceStatus)) - webservice.Route(webservice.GET("/namespaces/{namespace}/workloadstatuses"). + To(workloadstatuses.GetClusterAbnormalWorkloads)) + webservice.Route(webservice.GET("/namespaces/{namespace}/abnormalworkloads"). Doc("get abnormal workloads' count of specified namespace"). Param(webservice.PathParameter("namespace", "the name of namespace")). Metadata(restfulspec.KeyOpenAPITags, tags). Returns(http.StatusOK, ok, status.WorkLoadStatus{}). - To(workloadstatuses.GetNamespacesResourceStatus)) + To(workloadstatuses.GetNamespacedAbnormalWorkloads)) c.Add(webservice) diff --git a/pkg/apis/tenant/v1alpha2/register.go b/pkg/apis/tenant/v1alpha2/register.go index 51b4f3ed1cb5d9e528144d5508742c840682841b..eedcdc32e529e4e6bda69c0ba7c64e45191029aa 100644 --- a/pkg/apis/tenant/v1alpha2/register.go +++ b/pkg/apis/tenant/v1alpha2/register.go @@ -87,10 +87,10 @@ func addWebService(c *restful.Container) error { Doc("List the namespaces for the current user"). Returns(http.StatusOK, ok, []v1.Namespace{}). Metadata(restfulspec.KeyOpenAPITags, tags)) - ws.Route(ws.GET("/workspaces/{workspace}/members/{username}/namespaces"). + ws.Route(ws.GET("/workspaces/{workspace}/members/{member}/namespaces"). To(tenant.ListNamespacesByUsername). Param(ws.PathParameter("workspace", "workspace name")). - Param(ws.PathParameter("username", "workspace member's username")). + Param(ws.PathParameter("member", "workspace member's username")). Doc("List the namespaces for the workspace member"). Returns(http.StatusOK, ok, []v1.Namespace{}). Metadata(restfulspec.KeyOpenAPITags, tags)) @@ -120,10 +120,10 @@ func addWebService(c *restful.Container) error { DataFormat("key=%s,key~%s")). Doc("List devops projects for the current user"). Metadata(restfulspec.KeyOpenAPITags, tags)) - ws.Route(ws.GET("/workspaces/{workspace}/members/{username}/devops"). + ws.Route(ws.GET("/workspaces/{workspace}/members/{member}/devops"). To(tenant.ListDevopsProjectsByUsername). Param(ws.PathParameter("workspace", "workspace name")). - Param(ws.PathParameter("username", "workspace member's username")). + Param(ws.PathParameter("member", "workspace member's username")). Param(ws.QueryParameter(params.PagingParam, "page"). Required(false). DataFormat("limit=%d,page=%d"). @@ -141,14 +141,14 @@ func addWebService(c *restful.Container) error { Reads(devops.DevOpsProject{}). Returns(http.StatusOK, RespOK, devops.DevOpsProject{}). Metadata(restfulspec.KeyOpenAPITags, tags)) - ws.Route(ws.DELETE("/workspaces/{workspace}/devops/{id}"). + ws.Route(ws.DELETE("/workspaces/{workspace}/devops/{devops}"). To(tenant.DeleteDevopsProject). Param(ws.PathParameter("workspace", "workspace name")). - Param(ws.PathParameter("id", "devops project id")). + Param(ws.PathParameter("devops", "devops project id")). Doc("Delete devops project"). Returns(http.StatusOK, RespOK, devops.DevOpsProject{}). Metadata(restfulspec.KeyOpenAPITags, tags)) - ws.Route(ws.GET("/logging"). + ws.Route(ws.GET("/logs"). To(tenant.LogQuery). Doc("Query cluster-level logs in a multi-tenants environment"). Param(ws.QueryParameter("operation", "Query operation type. One of query, statistics, histogram.").DataType("string").Required(true)). diff --git a/pkg/apiserver/devops/devops.go b/pkg/apiserver/devops/devops.go index 53ddbf1e563fbcc7f95dedaaed28171a006ba3c6..1f9edae0ff680da4a277871a09afbb258c930145 100644 --- a/pkg/apiserver/devops/devops.go +++ b/pkg/apiserver/devops/devops.go @@ -30,7 +30,7 @@ const jenkinsHeaderPre = "X-" func GetPipeline(req *restful.Request, resp *restful.Response) { projectName := req.PathParameter("devops") - pipelineName := req.PathParameter("pipelines") + pipelineName := req.PathParameter("pipeline") res, err := devops.GetPipeline(projectName, pipelineName, req.Request) if err != nil { @@ -54,8 +54,8 @@ func SearchPipelines(req *restful.Request, resp *restful.Response) { } func SearchPipelineRuns(req *restful.Request, resp *restful.Response) { - projectName := req.PathParameter("projectName") - pipelineName := req.PathParameter("pipelineName") + projectName := req.PathParameter("devops") + pipelineName := req.PathParameter("pipeline") res, err := devops.SearchPipelineRuns(projectName, pipelineName, req.Request) if err != nil { @@ -68,10 +68,10 @@ func SearchPipelineRuns(req *restful.Request, resp *restful.Response) { } func GetBranchPipelineRun(req *restful.Request, resp *restful.Response) { - projectName := req.PathParameter("projectName") - pipelineName := req.PathParameter("pipelineName") - branchName := req.PathParameter("branchName") - runId := req.PathParameter("runId") + projectName := req.PathParameter("devops") + pipelineName := req.PathParameter("pipeline") + branchName := req.PathParameter("branch") + runId := req.PathParameter("run") res, err := devops.GetBranchPipelineRun(projectName, pipelineName, branchName, runId, req.Request) if err != nil { @@ -84,10 +84,10 @@ func GetBranchPipelineRun(req *restful.Request, resp *restful.Response) { } func GetPipelineRunNodesbyBranch(req *restful.Request, resp *restful.Response) { - projectName := req.PathParameter("projectName") - pipelineName := req.PathParameter("pipelineName") - branchName := req.PathParameter("branchName") - runId := req.PathParameter("runId") + projectName := req.PathParameter("devops") + pipelineName := req.PathParameter("pipeline") + branchName := req.PathParameter("branch") + runId := req.PathParameter("run") res, err := devops.GetPipelineRunNodesbyBranch(projectName, pipelineName, branchName, runId, req.Request) if err != nil { @@ -100,12 +100,12 @@ func GetPipelineRunNodesbyBranch(req *restful.Request, resp *restful.Response) { } func GetBranchStepLog(req *restful.Request, resp *restful.Response) { - projectName := req.PathParameter("projectName") - pipelineName := req.PathParameter("pipelineName") - branchName := req.PathParameter("branchName") - runId := req.PathParameter("runId") - nodeId := req.PathParameter("nodeId") - stepId := req.PathParameter("stepId") + projectName := req.PathParameter("devops") + pipelineName := req.PathParameter("pipeline") + branchName := req.PathParameter("branch") + runId := req.PathParameter("run") + nodeId := req.PathParameter("node") + stepId := req.PathParameter("step") res, header, err := devops.GetBranchStepLog(projectName, pipelineName, branchName, runId, nodeId, stepId, req.Request) @@ -122,11 +122,11 @@ func GetBranchStepLog(req *restful.Request, resp *restful.Response) { } func GetStepLog(req *restful.Request, resp *restful.Response) { - projectName := req.PathParameter("projectName") - pipelineName := req.PathParameter("pipelineName") - runId := req.PathParameter("runId") - nodeId := req.PathParameter("nodeId") - stepId := req.PathParameter("stepId") + projectName := req.PathParameter("devops") + pipelineName := req.PathParameter("pipeline") + runId := req.PathParameter("run") + nodeId := req.PathParameter("node") + stepId := req.PathParameter("step") res, header, err := devops.GetStepLog(projectName, pipelineName, runId, nodeId, stepId, req.Request) if err != nil { @@ -142,7 +142,7 @@ func GetStepLog(req *restful.Request, resp *restful.Response) { } func Validate(req *restful.Request, resp *restful.Response) { - scmId := req.PathParameter("scmId") + scmId := req.PathParameter("scm") res, err := devops.Validate(scmId, req.Request) if err != nil { @@ -155,7 +155,7 @@ func Validate(req *restful.Request, resp *restful.Response) { } func GetSCMOrg(req *restful.Request, resp *restful.Response) { - scmId := req.PathParameter("scmId") + scmId := req.PathParameter("scm") res, err := devops.GetSCMOrg(scmId, req.Request) if err != nil { @@ -168,8 +168,8 @@ func GetSCMOrg(req *restful.Request, resp *restful.Response) { } func GetOrgRepo(req *restful.Request, resp *restful.Response) { - scmId := req.PathParameter("scmId") - organizationId := req.PathParameter("organizationId") + scmId := req.PathParameter("scm") + organizationId := req.PathParameter("organization") res, err := devops.GetOrgRepo(scmId, organizationId, req.Request) if err != nil { @@ -182,10 +182,10 @@ func GetOrgRepo(req *restful.Request, resp *restful.Response) { } func StopBranchPipeline(req *restful.Request, resp *restful.Response) { - projectName := req.PathParameter("projectName") - pipelineName := req.PathParameter("pipelineName") - branchName := req.PathParameter("branchName") - runId := req.PathParameter("runId") + projectName := req.PathParameter("devops") + pipelineName := req.PathParameter("pipeline") + branchName := req.PathParameter("branch") + runId := req.PathParameter("run") res, err := devops.StopBranchPipeline(projectName, pipelineName, branchName, runId, req.Request) if err != nil { @@ -198,9 +198,9 @@ func StopBranchPipeline(req *restful.Request, resp *restful.Response) { } func StopPipeline(req *restful.Request, resp *restful.Response) { - projectName := req.PathParameter("projectName") - pipelineName := req.PathParameter("pipelineName") - runId := req.PathParameter("runId") + projectName := req.PathParameter("devops") + pipelineName := req.PathParameter("pipeline") + runId := req.PathParameter("run") res, err := devops.StopPipeline(projectName, pipelineName, runId, req.Request) if err != nil { @@ -213,10 +213,10 @@ func StopPipeline(req *restful.Request, resp *restful.Response) { } func ReplayBranchPipeline(req *restful.Request, resp *restful.Response) { - projectName := req.PathParameter("projectName") - pipelineName := req.PathParameter("pipelineName") - branchName := req.PathParameter("branchName") - runId := req.PathParameter("runId") + projectName := req.PathParameter("devops") + pipelineName := req.PathParameter("pipeline") + branchName := req.PathParameter("branch") + runId := req.PathParameter("run") res, err := devops.ReplayBranchPipeline(projectName, pipelineName, branchName, runId, req.Request) if err != nil { @@ -229,9 +229,9 @@ func ReplayBranchPipeline(req *restful.Request, resp *restful.Response) { } func ReplayPipeline(req *restful.Request, resp *restful.Response) { - projectName := req.PathParameter("projectName") - pipelineName := req.PathParameter("pipelineName") - runId := req.PathParameter("runId") + projectName := req.PathParameter("devops") + pipelineName := req.PathParameter("pipeline") + runId := req.PathParameter("run") res, err := devops.ReplayPipeline(projectName, pipelineName, runId, req.Request) if err != nil { @@ -244,10 +244,10 @@ func ReplayPipeline(req *restful.Request, resp *restful.Response) { } func GetBranchRunLog(req *restful.Request, resp *restful.Response) { - projectName := req.PathParameter("projectName") - pipelineName := req.PathParameter("pipelineName") - branchName := req.PathParameter("branchName") - runId := req.PathParameter("runId") + projectName := req.PathParameter("devops") + pipelineName := req.PathParameter("pipeline") + branchName := req.PathParameter("branch") + runId := req.PathParameter("run") res, err := devops.GetBranchRunLog(projectName, pipelineName, branchName, runId, req.Request) if err != nil { @@ -259,9 +259,9 @@ func GetBranchRunLog(req *restful.Request, resp *restful.Response) { } func GetRunLog(req *restful.Request, resp *restful.Response) { - projectName := req.PathParameter("projectName") - pipelineName := req.PathParameter("pipelineName") - runId := req.PathParameter("runId") + projectName := req.PathParameter("devops") + pipelineName := req.PathParameter("pipeline") + runId := req.PathParameter("run") res, err := devops.GetRunLog(projectName, pipelineName, runId, req.Request) if err != nil { @@ -273,10 +273,10 @@ func GetRunLog(req *restful.Request, resp *restful.Response) { } func GetBranchArtifacts(req *restful.Request, resp *restful.Response) { - projectName := req.PathParameter("projectName") - pipelineName := req.PathParameter("pipelineName") - branchName := req.PathParameter("branchName") - runId := req.PathParameter("runId") + projectName := req.PathParameter("devops") + pipelineName := req.PathParameter("pipeline") + branchName := req.PathParameter("branch") + runId := req.PathParameter("run") res, err := devops.GetBranchArtifacts(projectName, pipelineName, branchName, runId, req.Request) if err != nil { @@ -288,9 +288,9 @@ func GetBranchArtifacts(req *restful.Request, resp *restful.Response) { } func GetArtifacts(req *restful.Request, resp *restful.Response) { - projectName := req.PathParameter("projectName") - pipelineName := req.PathParameter("pipelineName") - runId := req.PathParameter("runId") + projectName := req.PathParameter("devops") + pipelineName := req.PathParameter("pipeline") + runId := req.PathParameter("run") res, err := devops.GetArtifacts(projectName, pipelineName, runId, req.Request) if err != nil { @@ -302,8 +302,8 @@ func GetArtifacts(req *restful.Request, resp *restful.Response) { } func GetPipeBranch(req *restful.Request, resp *restful.Response) { - projectName := req.PathParameter("projectName") - pipelineName := req.PathParameter("pipelineName") + projectName := req.PathParameter("devops") + pipelineName := req.PathParameter("pipeline") res, err := devops.GetPipeBranch(projectName, pipelineName, req.Request) if err != nil { @@ -315,12 +315,12 @@ func GetPipeBranch(req *restful.Request, resp *restful.Response) { } func CheckBranchPipeline(req *restful.Request, resp *restful.Response) { - projectName := req.PathParameter("projectName") - pipelineName := req.PathParameter("pipelineName") - branchName := req.PathParameter("branchName") - runId := req.PathParameter("runId") - nodeId := req.PathParameter("nodeId") - stepId := req.PathParameter("stepId") + projectName := req.PathParameter("devops") + pipelineName := req.PathParameter("pipeline") + branchName := req.PathParameter("branch") + runId := req.PathParameter("run") + nodeId := req.PathParameter("node") + stepId := req.PathParameter("step") res, err := devops.CheckBranchPipeline(projectName, pipelineName, branchName, runId, nodeId, stepId, req.Request) if err != nil { @@ -332,11 +332,11 @@ func CheckBranchPipeline(req *restful.Request, resp *restful.Response) { } func CheckPipeline(req *restful.Request, resp *restful.Response) { - projectName := req.PathParameter("projectName") - pipelineName := req.PathParameter("pipelineName") - runId := req.PathParameter("runId") - nodeId := req.PathParameter("nodeId") - stepId := req.PathParameter("stepId") + projectName := req.PathParameter("devops") + pipelineName := req.PathParameter("pipeline") + runId := req.PathParameter("run") + nodeId := req.PathParameter("node") + stepId := req.PathParameter("step") res, err := devops.CheckPipeline(projectName, pipelineName, runId, nodeId, stepId, req.Request) if err != nil { @@ -348,8 +348,8 @@ func CheckPipeline(req *restful.Request, resp *restful.Response) { } func GetConsoleLog(req *restful.Request, resp *restful.Response) { - projectName := req.PathParameter("projectName") - pipelineName := req.PathParameter("pipelineName") + projectName := req.PathParameter("devops") + pipelineName := req.PathParameter("pipeline") res, err := devops.GetConsoleLog(projectName, pipelineName, req.Request) if err != nil { @@ -361,8 +361,8 @@ func GetConsoleLog(req *restful.Request, resp *restful.Response) { } func ScanBranch(req *restful.Request, resp *restful.Response) { - projectName := req.PathParameter("projectName") - pipelineName := req.PathParameter("pipelineName") + projectName := req.PathParameter("devops") + pipelineName := req.PathParameter("pipeline") res, err := devops.ScanBranch(projectName, pipelineName, req.Request) if err != nil { @@ -374,9 +374,9 @@ func ScanBranch(req *restful.Request, resp *restful.Response) { } func RunBranchPipeline(req *restful.Request, resp *restful.Response) { - projectName := req.PathParameter("projectName") - pipelineName := req.PathParameter("pipelineName") - branchName := req.PathParameter("branchName") + projectName := req.PathParameter("devops") + pipelineName := req.PathParameter("pipeline") + branchName := req.PathParameter("branch") res, err := devops.RunBranchPipeline(projectName, pipelineName, branchName, req.Request) if err != nil { @@ -389,8 +389,8 @@ func RunBranchPipeline(req *restful.Request, resp *restful.Response) { } func RunPipeline(req *restful.Request, resp *restful.Response) { - projectName := req.PathParameter("projectName") - pipelineName := req.PathParameter("pipelineName") + projectName := req.PathParameter("devops") + pipelineName := req.PathParameter("pipeline") res, err := devops.RunPipeline(projectName, pipelineName, req.Request) if err != nil { @@ -402,39 +402,6 @@ func RunPipeline(req *restful.Request, resp *restful.Response) { resp.Write(res) } -func GetBranchStepsStatus(req *restful.Request, resp *restful.Response) { - projectName := req.PathParameter("projectName") - pipelineName := req.PathParameter("pipelineName") - branchName := req.PathParameter("branchName") - runId := req.PathParameter("runId") - nodeId := req.PathParameter("nodeId") - - res, err := devops.GetBranchStepsStatus(projectName, pipelineName, branchName, runId, nodeId, req.Request) - if err != nil { - parseErr(err, resp) - return - } - - resp.Header().Set(restful.HEADER_ContentType, restful.MIME_JSON) - resp.Write(res) -} - -func GetStepsStatus(req *restful.Request, resp *restful.Response) { - projectName := req.PathParameter("projectName") - pipelineName := req.PathParameter("pipelineName") - runId := req.PathParameter("runId") - nodeId := req.PathParameter("nodeId") - - res, err := devops.GetStepsStatus(projectName, pipelineName, runId, nodeId, req.Request) - if err != nil { - parseErr(err, resp) - return - } - - resp.Header().Set(restful.HEADER_ContentType, restful.MIME_JSON) - resp.Write(res) -} - func GetCrumb(req *restful.Request, resp *restful.Response) { res, err := devops.GetCrumb(req.Request) if err != nil { @@ -482,9 +449,9 @@ func CheckCron(req *restful.Request, resp *restful.Response) { } func GetPipelineRun(req *restful.Request, resp *restful.Response) { - projectName := req.PathParameter("projectName") - pipelineName := req.PathParameter("pipelineName") - runId := req.PathParameter("runId") + projectName := req.PathParameter("devops") + pipelineName := req.PathParameter("pipeline") + runId := req.PathParameter("run") res, err := devops.GetPipelineRun(projectName, pipelineName, runId, req.Request) if err != nil { @@ -497,9 +464,9 @@ func GetPipelineRun(req *restful.Request, resp *restful.Response) { } func GetBranchPipeline(req *restful.Request, resp *restful.Response) { - projectName := req.PathParameter("projectName") - pipelineName := req.PathParameter("pipelineName") - branchName := req.PathParameter("branchName") + projectName := req.PathParameter("devops") + pipelineName := req.PathParameter("pipeline") + branchName := req.PathParameter("branch") res, err := devops.GetBranchPipeline(projectName, pipelineName, branchName, req.Request) if err != nil { @@ -512,9 +479,9 @@ func GetBranchPipeline(req *restful.Request, resp *restful.Response) { } func GetPipelineRunNodes(req *restful.Request, resp *restful.Response) { - projectName := req.PathParameter("projectName") - pipelineName := req.PathParameter("pipelineName") - runId := req.PathParameter("runId") + projectName := req.PathParameter("devops") + pipelineName := req.PathParameter("pipeline") + runId := req.PathParameter("run") res, err := devops.GetPipelineRunNodes(projectName, pipelineName, runId, req.Request) if err != nil { @@ -526,11 +493,11 @@ func GetPipelineRunNodes(req *restful.Request, resp *restful.Response) { } func GetBranchNodeSteps(req *restful.Request, resp *restful.Response) { - projectName := req.PathParameter("projectName") - pipelineName := req.PathParameter("pipelineName") - branchName := req.PathParameter("branchName") - runId := req.PathParameter("runId") - nodeId := req.PathParameter("nodeId") + projectName := req.PathParameter("devops") + pipelineName := req.PathParameter("pipeline") + branchName := req.PathParameter("branch") + runId := req.PathParameter("run") + nodeId := req.PathParameter("node") res, err := devops.GetBranchNodeSteps(projectName, pipelineName, branchName, runId, nodeId, req.Request) if err != nil { @@ -542,10 +509,10 @@ func GetBranchNodeSteps(req *restful.Request, resp *restful.Response) { } func GetNodeSteps(req *restful.Request, resp *restful.Response) { - projectName := req.PathParameter("projectName") - pipelineName := req.PathParameter("pipelineName") - runId := req.PathParameter("runId") - nodeId := req.PathParameter("nodeId") + projectName := req.PathParameter("devops") + pipelineName := req.PathParameter("pipeline") + runId := req.PathParameter("run") + nodeId := req.PathParameter("node") res, err := devops.GetNodeSteps(projectName, pipelineName, runId, nodeId, req.Request) if err != nil { @@ -603,10 +570,10 @@ func GithubWebhook(req *restful.Request, resp *restful.Response) { } func GetBranchNodesDetail(req *restful.Request, resp *restful.Response) { - projectName := req.PathParameter("projectName") - pipelineName := req.PathParameter("pipelineName") - branchName := req.PathParameter("branchName") - runId := req.PathParameter("runId") + projectName := req.PathParameter("devops") + pipelineName := req.PathParameter("pipeline") + branchName := req.PathParameter("branch") + runId := req.PathParameter("run") res, err := devops.GetBranchNodesDetail(projectName, pipelineName, branchName, runId, req.Request) if err != nil { @@ -617,9 +584,9 @@ func GetBranchNodesDetail(req *restful.Request, resp *restful.Response) { } func GetNodesDetail(req *restful.Request, resp *restful.Response) { - projectName := req.PathParameter("projectName") - pipelineName := req.PathParameter("pipelineName") - runId := req.PathParameter("runId") + projectName := req.PathParameter("devops") + pipelineName := req.PathParameter("pipeline") + runId := req.PathParameter("run") res, err := devops.GetNodesDetail(projectName, pipelineName, runId, req.Request) if err != nil { diff --git a/pkg/apiserver/iam/am.go b/pkg/apiserver/iam/am.go index 51aa7b4b668922e1a139138d8782351c6b238029..21699c72c1ab329c7ffb4fb16c98b8a70cf5238d 100644 --- a/pkg/apiserver/iam/am.go +++ b/pkg/apiserver/iam/am.go @@ -116,7 +116,7 @@ func ListNamespaceUsers(req *restful.Request, resp *restful.Response) { func ListUserRoles(req *restful.Request, resp *restful.Response) { - username := req.PathParameter("username") + username := req.PathParameter("user") roles, err := iam.GetUserRoles("", username) diff --git a/pkg/apiserver/iam/auth.go b/pkg/apiserver/iam/auth.go index 49245654e701804a47d5c4a6e00a4c38a3b02e55..2a0cde34973158054e9fd624f41be10781e8cee5 100644 --- a/pkg/apiserver/iam/auth.go +++ b/pkg/apiserver/iam/auth.go @@ -55,7 +55,7 @@ const ( KindTokenReview = "TokenReview" ) -func LoginHandler(req *restful.Request, resp *restful.Response) { +func Login(req *restful.Request, resp *restful.Response) { var loginRequest LoginRequest err := req.ReadEntity(&loginRequest) @@ -70,6 +70,10 @@ func LoginHandler(req *restful.Request, resp *restful.Response) { token, err := iam.Login(loginRequest.Username, loginRequest.Password, ip) if err != nil { + if serviceError, ok := err.(restful.ServiceError); ok { + resp.WriteHeaderAndEntity(serviceError.Code, errors.New(serviceError.Message)) + return + } resp.WriteHeaderAndEntity(http.StatusUnauthorized, errors.Wrap(err)) return } diff --git a/pkg/apiserver/iam/groups.go b/pkg/apiserver/iam/groups.go index cd0cce07bfe5fa4bdec3e894b99dd44ba3d8e43a..9b978ce6cb5a10c29efeb6108e11934c7ab9ec01 100644 --- a/pkg/apiserver/iam/groups.go +++ b/pkg/apiserver/iam/groups.go @@ -61,7 +61,7 @@ func CreateGroup(req *restful.Request, resp *restful.Response) { } func DeleteGroup(req *restful.Request, resp *restful.Response) { - path := req.PathParameter("path") + path := req.PathParameter("group") if path == "" { resp.WriteHeaderAndEntity(http.StatusBadRequest, errors.Wrap(fmt.Errorf("group path must not be null"))) @@ -84,7 +84,7 @@ func DeleteGroup(req *restful.Request, resp *restful.Response) { } func UpdateGroup(req *restful.Request, resp *restful.Response) { - groupPathInPath := req.PathParameter("path") + groupPathInPath := req.PathParameter("group") var group models.Group @@ -108,7 +108,7 @@ func UpdateGroup(req *restful.Request, resp *restful.Response) { func DescribeGroup(req *restful.Request, resp *restful.Response) { - path := req.PathParameter("path") + path := req.PathParameter("group") group, err := iam.DescribeGroup(path) @@ -127,7 +127,7 @@ func DescribeGroup(req *restful.Request, resp *restful.Response) { func ListGroupUsers(req *restful.Request, resp *restful.Response) { - path := req.PathParameter("path") + path := req.PathParameter("group") group, err := iam.DescribeGroup(path) diff --git a/pkg/apiserver/iam/im.go b/pkg/apiserver/iam/im.go index 2a2ef4007ad53fe324f6dd93d9ad59da1981d503..aa39cc02f5aaaf77835e2a774add89b569ef260a 100644 --- a/pkg/apiserver/iam/im.go +++ b/pkg/apiserver/iam/im.go @@ -77,7 +77,7 @@ func CreateUser(req *restful.Request, resp *restful.Response) { } func DeleteUser(req *restful.Request, resp *restful.Response) { - username := req.PathParameter("username") + username := req.PathParameter("user") operator := req.HeaderParameter(constants.UserNameHeader) @@ -98,7 +98,7 @@ func DeleteUser(req *restful.Request, resp *restful.Response) { func UpdateUser(req *restful.Request, resp *restful.Response) { - usernameInPath := req.PathParameter("username") + usernameInPath := req.PathParameter("user") usernameInHeader := req.HeaderParameter(constants.UserNameHeader) var user models.User @@ -161,8 +161,8 @@ func isUserManager(username string) (bool, error) { return false, nil } -func UserLoginLog(req *restful.Request, resp *restful.Response) { - username := req.PathParameter("username") +func UserLoginLogs(req *restful.Request, resp *restful.Response) { + username := req.PathParameter("user") logs, err := iam.LoginLog(username) if err != nil { @@ -187,7 +187,7 @@ func UserLoginLog(req *restful.Request, resp *restful.Response) { func DescribeUser(req *restful.Request, resp *restful.Response) { - username := req.PathParameter("username") + username := req.PathParameter("user") user, err := iam.DescribeUser(username) diff --git a/pkg/apiserver/iam/workspaces.go b/pkg/apiserver/iam/workspaces.go index b850b4dcbd27b9da63f4f3d28389e591e19318d8..be0f46194e3e03bc4b7b8698c93f6257e00895a6 100644 --- a/pkg/apiserver/iam/workspaces.go +++ b/pkg/apiserver/iam/workspaces.go @@ -77,7 +77,7 @@ func DescribeWorkspaceRole(req *restful.Request, resp *restful.Response) { func DescribeWorkspaceUser(req *restful.Request, resp *restful.Response) { workspace := req.PathParameter("workspace") - username := req.PathParameter("username") + username := req.PathParameter("member") workspaceRole, err := iam.GetUserWorkspaceRole(workspace, username) @@ -132,7 +132,7 @@ func InviteUser(req *restful.Request, resp *restful.Response) { func RemoveUser(req *restful.Request, resp *restful.Response) { workspace := req.PathParameter("workspace") - username := req.PathParameter("username") + username := req.PathParameter("member") err := workspaces.RemoveUser(workspace, username) if err != nil { diff --git a/pkg/apiserver/resources/application.go b/pkg/apiserver/resources/application.go index ea705c4b067a93703bc6909397c43cd5aa81f126..77b10c2f7cec3dd316f6bd0369f77e1297e14dc8 100644 --- a/pkg/apiserver/resources/application.go +++ b/pkg/apiserver/resources/application.go @@ -117,7 +117,7 @@ func ListNamespacedApplication(req *restful.Request, resp *restful.Response) { } func DescribeApplication(req *restful.Request, resp *restful.Response) { - clusterId := req.PathParameter("cluster_id") + clusterId := req.PathParameter("application") namespaceName := req.PathParameter("namespace") app, err := applications.GetApp(clusterId) if err != nil { @@ -166,7 +166,7 @@ func DeployApplication(req *restful.Request, resp *restful.Response) { } func DeleteApplication(req *restful.Request, resp *restful.Response) { - clusterId := req.PathParameter("cluster_id") + clusterId := req.PathParameter("application") namespaceName := req.PathParameter("namespace") app, err := applications.GetApp(clusterId) if err != nil { diff --git a/pkg/apiserver/resources/user.go b/pkg/apiserver/resources/user.go index 03b376322ea3b4ab5b0672ace1bebaa673637cc2..5e8bf2945360577a38e8fb9b17b4bc05dbf8bc29 100644 --- a/pkg/apiserver/resources/user.go +++ b/pkg/apiserver/resources/user.go @@ -29,7 +29,7 @@ import ( func GetKubectl(req *restful.Request, resp *restful.Response) { - user := req.PathParameter("username") + user := req.PathParameter("user") kubectlPod, err := kubectl.GetKubectlPod(user) @@ -43,7 +43,7 @@ func GetKubectl(req *restful.Request, resp *restful.Response) { func GetKubeconfig(req *restful.Request, resp *restful.Response) { - user := req.PathParameter("username") + user := req.PathParameter("user") kubectlConfig, err := kubeconfig.GetKubeConfig(user) diff --git a/pkg/apiserver/tenant/tenant.go b/pkg/apiserver/tenant/tenant.go index 99355bfdf69a87149b152ab780b5cc2869cb6108..488c94cdd2c84410e8c389fc1d6efddad65b6abc 100644 --- a/pkg/apiserver/tenant/tenant.go +++ b/pkg/apiserver/tenant/tenant.go @@ -107,7 +107,7 @@ func ListNamespacesByUsername(req *restful.Request, resp *restful.Response) { func ListNamespaces(req *restful.Request, resp *restful.Response) { workspace := req.PathParameter("workspace") - username := req.PathParameter("username") + username := req.PathParameter("member") // /workspaces/{workspace}/members/{username}/namespaces if username == "" { // /workspaces/{workspace}/namespaces @@ -218,7 +218,7 @@ func ListDevopsProjectsByUsername(req *restful.Request, resp *restful.Response) func ListDevopsProjects(req *restful.Request, resp *restful.Response) { workspace := req.PathParameter("workspace") - username := req.PathParameter(constants.UserNameHeader) + username := req.PathParameter("member") if username == "" { username = req.HeaderParameter(constants.UserNameHeader) } @@ -245,7 +245,7 @@ func ListDevopsProjects(req *restful.Request, resp *restful.Response) { } func DeleteDevopsProject(req *restful.Request, resp *restful.Response) { - projectId := req.PathParameter("id") + projectId := req.PathParameter("devops") workspaceName := req.PathParameter("workspace") username := req.HeaderParameter(constants.UserNameHeader) diff --git a/pkg/apiserver/workloadstatuses/workloadstatuses.go b/pkg/apiserver/workloadstatuses/workloadstatuses.go index 934441283979c056839de65a1af2976bd0422157..75e8f8fe436ff393444290fb4338251aa408f6e8 100644 --- a/pkg/apiserver/workloadstatuses/workloadstatuses.go +++ b/pkg/apiserver/workloadstatuses/workloadstatuses.go @@ -26,7 +26,7 @@ import ( "kubesphere.io/kubesphere/pkg/models/status" ) -func GetClusterResourceStatus(req *restful.Request, resp *restful.Response) { +func GetClusterAbnormalWorkloads(req *restful.Request, resp *restful.Response) { res, err := status.GetClusterResourceStatus() if err != nil { resp.WriteHeaderAndEntity(http.StatusInternalServerError, errors.Wrap(err)) @@ -35,7 +35,7 @@ func GetClusterResourceStatus(req *restful.Request, resp *restful.Response) { resp.WriteAsJson(res) } -func GetNamespacesResourceStatus(req *restful.Request, resp *restful.Response) { +func GetNamespacedAbnormalWorkloads(req *restful.Request, resp *restful.Response) { res, err := status.GetNamespacesResourceStatus(req.PathParameter("namespace")) if err != nil { resp.WriteHeaderAndEntity(http.StatusInternalServerError, errors.Wrap(err)) diff --git a/pkg/controller/namespace/namespace_controller.go b/pkg/controller/namespace/namespace_controller.go index 81917aa447a0e0d09f91ff39f6204894ddd142ad..b9035d658b1bb63de4e1bc588d2baf49b0c8ceed 100644 --- a/pkg/controller/namespace/namespace_controller.go +++ b/pkg/controller/namespace/namespace_controller.go @@ -60,7 +60,7 @@ var ( defaultRoles = []rbac.Role{ {ObjectMeta: metav1.ObjectMeta{Name: "admin", Annotations: map[string]string{constants.DescriptionAnnotationKey: adminDescription, constants.CreatorAnnotationKey: constants.System}}, Rules: []rbac.PolicyRule{{Verbs: []string{"*"}, APIGroups: []string{"*"}, Resources: []string{"*"}}}}, {ObjectMeta: metav1.ObjectMeta{Name: "operator", Annotations: map[string]string{constants.DescriptionAnnotationKey: operatorDescription, constants.CreatorAnnotationKey: constants.System}}, Rules: []rbac.PolicyRule{{Verbs: []string{"get", "list", "watch"}, APIGroups: []string{"*"}, Resources: []string{"*"}}, - {Verbs: []string{"*"}, APIGroups: []string{"", "apps", "extensions", "batch", "logging.kubesphere.io", "monitoring.kubesphere.io", "iam.kubesphere.io", "resources.kubesphere.io", "autoscaling", "alerting.kubesphere.io", "app.k8s.io", "servicemesh.kubesphere.io"}, Resources: []string{"*"}}}}, + {Verbs: []string{"*"}, APIGroups: []string{"", "apps", "extensions", "batch", "logging.kubesphere.io", "monitoring.kubesphere.io", "iam.kubesphere.io", "resources.kubesphere.io", "autoscaling", "alerting.kubesphere.io", "app.k8s.io", "servicemesh.kubesphere.io", "operations.kubesphere.io"}, Resources: []string{"*"}}}}, {ObjectMeta: metav1.ObjectMeta{Name: "viewer", Annotations: map[string]string{constants.DescriptionAnnotationKey: viewerDescription, constants.CreatorAnnotationKey: constants.System}}, Rules: []rbac.PolicyRule{{Verbs: []string{"get", "list", "watch"}, APIGroups: []string{"*"}, Resources: []string{"*"}}}}, } ) diff --git a/pkg/models/applications/applications.go b/pkg/models/applications/applications.go index c90a00cdf306374d3747a6bb1b2e34b949f44cfd..80fb6352832a1364c0f47458deda1cd191b98659 100644 --- a/pkg/models/applications/applications.go +++ b/pkg/models/applications/applications.go @@ -45,8 +45,8 @@ type Application struct { Version string `json:"version" description:"application version"` VersionId string `json:"version_id" description:"application version id"` Status string `json:"status" description:"application status"` - UpdateTime time.Time `json:"updateTime" description:"update time"` - CreateTime time.Time `json:"createTime" description:"create name"` + UpdateTime time.Time `json:"updateTime" description:"the last time this application was updated"` + CreateTime time.Time `json:"createTime" description:"application creation time"` App string `json:"app" description:"application template name"` AppId string `json:"app_id" description:"application template id"` Description string `json:"description,omitempty" description:"application description"` @@ -148,6 +148,11 @@ func getWorkLoads(namespace string, clusterRoles []openpitrix.ClusterRole) (*wor item, err := informers.SharedInformerFactory().Apps().V1().Deployments().Lister().Deployments(namespace).Get(name) if err != nil { + // app not ready + if errors.IsNotFound(err) { + continue + } + glog.Error(err) return nil, err } @@ -159,6 +164,11 @@ func getWorkLoads(namespace string, clusterRoles []openpitrix.ClusterRole) (*wor name := strings.Split(workLoadName, openpitrix.DaemonSuffix)[0] item, err := informers.SharedInformerFactory().Apps().V1().DaemonSets().Lister().DaemonSets(namespace).Get(name) if err != nil { + // app not ready + if errors.IsNotFound(err) { + continue + } + glog.Error(err) return nil, err } works.Daemonsets = append(works.Daemonsets, *item) @@ -169,6 +179,11 @@ func getWorkLoads(namespace string, clusterRoles []openpitrix.ClusterRole) (*wor name := strings.Split(workLoadName, openpitrix.StateSuffix)[0] item, err := informers.SharedInformerFactory().Apps().V1().StatefulSets().Lister().StatefulSets(namespace).Get(name) if err != nil { + // app not ready + if errors.IsNotFound(err) { + continue + } + glog.Error(err) return nil, err } works.Statefulsets = append(works.Statefulsets, *item) diff --git a/pkg/models/devops/devops.go b/pkg/models/devops/devops.go index bad0c3f8721e55ed07d58318e78ac1918acdf57a..308e86cc893b88b6a72ad7bdde8f7a678a503157 100644 --- a/pkg/models/devops/devops.go +++ b/pkg/models/devops/devops.go @@ -138,6 +138,7 @@ func Validate(scmId string, req *http.Request) ([]byte, error) { baseUrl := fmt.Sprintf(jenkins.Server+ValidateUrl, scmId) log.Info("Jenkins-url: " + baseUrl) + req.Method = http.MethodPut resBody, err := sendJenkinsRequest(baseUrl, req) if err != nil { log.Error(err) @@ -177,6 +178,7 @@ func StopBranchPipeline(projectName, pipelineName, branchName, runId string, req baseUrl := fmt.Sprintf(jenkins.Server+StopBranchPipelineUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId) log.Info("Jenkins-url: " + baseUrl) + req.Method = http.MethodPut res, err := sendJenkinsRequest(baseUrl, req) if err != nil { log.Error(err) @@ -190,6 +192,7 @@ func StopPipeline(projectName, pipelineName, runId string, req *http.Request) ([ baseUrl := fmt.Sprintf(jenkins.Server+StopPipelineUrl+req.URL.RawQuery, projectName, pipelineName, runId) log.Info("Jenkins-url: " + baseUrl) + req.Method = http.MethodPut res, err := sendJenkinsRequest(baseUrl, req) if err != nil { log.Error(err) @@ -368,32 +371,6 @@ func RunPipeline(projectName, pipelineName string, req *http.Request) ([]byte, e return res, err } -func GetBranchStepsStatus(projectName, pipelineName, branchName, runId, nodeId string, req *http.Request) ([]byte, error) { - baseUrl := fmt.Sprintf(jenkins.Server+GetBranchStepsStatusUrl+req.URL.RawQuery, projectName, pipelineName, branchName, runId, nodeId) - log.Info("Jenkins-url: " + baseUrl) - - res, err := sendJenkinsRequest(baseUrl, req) - if err != nil { - log.Error(err) - return nil, err - } - - return res, err -} - -func GetStepsStatus(projectName, pipelineName, runId, nodeId string, req *http.Request) ([]byte, error) { - baseUrl := fmt.Sprintf(jenkins.Server+GetStepsStatusUrl+req.URL.RawQuery, projectName, pipelineName, runId, nodeId) - log.Info("Jenkins-url: " + baseUrl) - - res, err := sendJenkinsRequest(baseUrl, req) - if err != nil { - log.Error(err) - return nil, err - } - - return res, err -} - func GetCrumb(req *http.Request) ([]byte, error) { baseUrl := fmt.Sprintf(jenkins.Server + GetCrumbUrl) log.Info("Jenkins-url: " + baseUrl) diff --git a/pkg/models/devops/urlconfig.go b/pkg/models/devops/urlconfig.go index 05a9355eb2c39c34d296d3c8fb25e5ff0effa0f0..5255040c3d721b292fb4cad46b81179338c946bc 100644 --- a/pkg/models/devops/urlconfig.go +++ b/pkg/models/devops/urlconfig.go @@ -40,10 +40,6 @@ const ( ReplayPipelineUrl = "/blue/rest/organizations/jenkins/pipelines/%s/pipelines/%s/runs/%s/replay/" GetBranchArtifactsUrl = "/blue/rest/organizations/jenkins/pipelines/%s/pipelines/%s/branches/%s/runs/%s/artifacts/?" GetArtifactsUrl = "/blue/rest/organizations/jenkins/pipelines/%s/pipelines/%s/runs/%s/artifacts/?" - GetBranchStepsStatusUrl = "/blue/rest/organizations/jenkins/pipelines/%s/pipelines/%s/branches/%s/runs/%s/nodes/%s/steps/?" - - GetStepsStatusUrl = "/blue/rest/organizations/jenkins/pipelines/%s/pipelines/%s/runs/%s/nodes/%s/steps/?" - CheckBranchPipelineUrl = "/blue/rest/organizations/jenkins/pipelines/%s/pipelines/%s/branches/%s/runs/%s/nodes/%s/steps/%s/" CheckPipelineUrl = "/blue/rest/organizations/jenkins/pipelines/%s/pipelines/%s/runs/%s/nodes/%s/steps/%s/" GetBranchNodeStepsUrl = "/blue/rest/organizations/jenkins/pipelines/%s/pipelines/%s/branches/%s/runs/%s/nodes/%s/steps/?" diff --git a/pkg/models/iam/im.go b/pkg/models/iam/im.go index 0ab9cae4ee977832a42309af105cbe5d37c6da6a..bbe9e49b05633b2b29c94e5fdb0da1a7eeee6daf 100644 --- a/pkg/models/iam/im.go +++ b/pkg/models/iam/im.go @@ -56,10 +56,12 @@ import ( ) var ( - adminEmail string - adminPassword string - tokenExpireTime time.Duration - initUsers []initUser + adminEmail string + adminPassword string + tokenExpireTime time.Duration + maxAuthFailed int + authTimeInterval time.Duration + initUsers []initUser ) type initUser struct { @@ -68,14 +70,17 @@ type initUser struct { } const ( - userInitFile = "/etc/ks-iam/users.json" + userInitFile = "/etc/ks-iam/users.json" + authRateLimitRegex = `(\d+)/(\d+[s|m|h])` + defaultMaxAuthFailed = 5 + defaultAuthTimeInterval = 30 * time.Minute ) -func Init(email, password string, t time.Duration) error { +func Init(email, password string, expireTime time.Duration, authRateLimit string) error { adminEmail = email adminPassword = password - tokenExpireTime = t - + tokenExpireTime = expireTime + maxAuthFailed, authTimeInterval = parseAuthRateLimit(authRateLimit) conn, err := ldapclient.Client() if err != nil { @@ -101,6 +106,23 @@ func Init(email, password string, t time.Duration) error { return nil } +func parseAuthRateLimit(authRateLimit string) (int, time.Duration) { + regex := regexp.MustCompile(authRateLimitRegex) + groups := regex.FindStringSubmatch(authRateLimit) + + maxCount := defaultMaxAuthFailed + timeInterval := defaultAuthTimeInterval + + if len(groups) == 3 { + maxCount, _ = strconv.Atoi(groups[1]) + timeInterval, _ = time.ParseDuration(groups[2]) + } else { + glog.Warning("invalid auth rate limit", authRateLimit) + } + + return maxCount, timeInterval +} + func checkAndCreateDefaultGroup(conn ldap.Client) error { groupSearchRequest := ldap.NewSearchRequest( @@ -203,9 +225,23 @@ func createGroupsBaseDN(conn ldap.Client) error { // User login func Login(username string, password string, ip string) (*models.Token, error) { + redisClient := redis.Client() + + records, err := redisClient.Keys(fmt.Sprintf("kubesphere:authfailed:%s:*", username)).Result() + + if err != nil { + glog.Error(err) + return nil, err + } + + if len(records) >= maxAuthFailed { + return nil, restful.NewError(http.StatusTooManyRequests, "auth rate limit exceeded") + } + conn, err := ldapclient.Client() if err != nil { + glog.Error(err) return nil, err } @@ -237,7 +273,13 @@ func Login(username string, password string, ip string) (*models.Token, error) { err = conn.Bind(dn, password) if err != nil { - glog.Errorln("auth error", username, err) + glog.Infoln("auth failed", username, err) + + if ldap.IsErrorWithCode(err, ldap.LDAPResultInvalidCredentials) { + loginFailedRecord := fmt.Sprintf("kubesphere:authfailed:%s:%d", username, time.Now().UnixNano()) + redisClient.Set(loginFailedRecord, "", authTimeInterval) + } + return nil, err } @@ -876,6 +918,17 @@ func UpdateUser(user *models.User) (*models.User, error) { return nil, err } + // clear auth failed record + if user.Password != "" { + redisClient := redis.Client() + + records, err := redisClient.Keys(fmt.Sprintf("kubesphere:authfailed:%s:*", user.Username)).Result() + + if err == nil { + redisClient.Del(records...) + } + } + return GetUserInfo(user.Username) } func DeleteGroup(path string) error { diff --git a/pkg/models/kubeconfig/kubeconfig.go b/pkg/models/kubeconfig/kubeconfig.go index cef159e230c99a0953552e6b2776ab912efde69c..2c052a501d2daa1b0139ae945b8f4e5c2ca5244b 100644 --- a/pkg/models/kubeconfig/kubeconfig.go +++ b/pkg/models/kubeconfig/kubeconfig.go @@ -217,7 +217,7 @@ func createKubeConfig(username string) (string, error) { return "", err } base64ServerCa := base64.StdEncoding.EncodeToString(serverCa) - tmpClusterInfo := clusterInfo{CertificateAuthorityData: base64ServerCa, Server: k8s.KubeConfig.Host} + tmpClusterInfo := clusterInfo{CertificateAuthorityData: base64ServerCa, Server: k8s.MasterURL} tmpCluster := cluster{Cluster: tmpClusterInfo, Name: clusterName} tmpKubeConfig.Clusters = append(tmpKubeConfig.Clusters, tmpCluster) diff --git a/pkg/models/metrics/metricsruleconst.go b/pkg/models/metrics/metricsruleconst.go index 449d2f2bc92993b47e49430e3c125a546220e808..d14a2aeb1158e540e3f9d89a20d60172da9f8d41 100644 --- a/pkg/models/metrics/metricsruleconst.go +++ b/pkg/models/metrics/metricsruleconst.go @@ -400,10 +400,10 @@ var RulePromQLTmplMap = MetricMap{ "cluster_disk_read_throughput": "sum(node:data_volume_throughput_bytes_read:sum)", "cluster_disk_write_throughput": "sum(node:data_volume_throughput_bytes_written:sum)", - "cluster_disk_size_usage": `sum(max(node_filesystem_size_bytes{device=~"/dev/[vsh]d.+", job="node-exporter"} - node_filesystem_avail_bytes{device=~"/dev/[vsh]d.+", job="node-exporter"}) by (device, instance))`, + "cluster_disk_size_usage": `sum(max(node_filesystem_size_bytes{device=~"/dev/.*", job="node-exporter"} - node_filesystem_avail_bytes{device=~"/dev/.*", job="node-exporter"}) by (device, instance))`, "cluster_disk_size_utilisation": `cluster:disk_utilization:ratio`, - "cluster_disk_size_capacity": `sum(max(node_filesystem_size_bytes{device=~"/dev/[vsh]d.+", job="node-exporter"}) by (device, instance))`, - "cluster_disk_size_available": `sum(max(node_filesystem_avail_bytes{device=~"/dev/[vsh]d.+", job="node-exporter"}) by (device, instance))`, + "cluster_disk_size_capacity": `sum(max(node_filesystem_size_bytes{device=~"/dev/.*", job="node-exporter"}) by (device, instance))`, + "cluster_disk_size_available": `sum(max(node_filesystem_avail_bytes{device=~"/dev/.*", job="node-exporter"}) by (device, instance))`, "cluster_disk_inode_total": `sum(node:node_inodes_total:)`, "cluster_disk_inode_usage": `sum(node:node_inodes_total:) - sum(node:node_inodes_free:)`, @@ -481,9 +481,9 @@ var RulePromQLTmplMap = MetricMap{ "node_disk_read_throughput": "node:data_volume_throughput_bytes_read:sum", "node_disk_write_throughput": "node:data_volume_throughput_bytes_written:sum", - "node_disk_size_capacity": `sum(max(node_filesystem_size_bytes{device=~"/dev/[vsh]d.+", job="node-exporter"} * on (namespace, pod) group_left(node) node_namespace_pod:kube_pod_info:$1) by (device, node)) by (node)`, + "node_disk_size_capacity": `sum(max(node_filesystem_size_bytes{device=~"/dev/.*", job="node-exporter"} * on (namespace, pod) group_left(node) node_namespace_pod:kube_pod_info:$1) by (device, node)) by (node)`, "node_disk_size_available": `node:disk_space_available:$1`, - "node_disk_size_usage": `sum(max((node_filesystem_size_bytes{device=~"/dev/[vsh]d.+", job="node-exporter"} - node_filesystem_avail_bytes{device=~"/dev/[vsh]d.+", job="node-exporter"}) * on (namespace, pod) group_left(node) node_namespace_pod:kube_pod_info:$1) by (device, node)) by (node)`, + "node_disk_size_usage": `sum(max((node_filesystem_size_bytes{device=~"/dev/.*", job="node-exporter"} - node_filesystem_avail_bytes{device=~"/dev/.*", job="node-exporter"}) * on (namespace, pod) group_left(node) node_namespace_pod:kube_pod_info:$1) by (device, node)) by (node)`, "node_disk_size_utilisation": `node:disk_space_utilization:ratio$1`, "node_disk_inode_total": `node:node_inodes_total:$1`, diff --git a/pkg/models/resources/nodes.go b/pkg/models/resources/nodes.go index 6daa02c6155c10012054e9559d2f6e3579703bf0..38e607f0bf8d0b3b1698dcae8042c9be87981858 100644 --- a/pkg/models/resources/nodes.go +++ b/pkg/models/resources/nodes.go @@ -18,6 +18,7 @@ package resources import ( + "fmt" "kubesphere.io/kubesphere/pkg/constants" "kubesphere.io/kubesphere/pkg/informers" "kubesphere.io/kubesphere/pkg/params" @@ -45,6 +46,11 @@ func (*nodeSearcher) match(match map[string]string, item *v1.Node) bool { if !sliceutil.HasString(names, item.Name) { return false } + case Role: + labelKey := fmt.Sprintf("node-role.kubernetes.io/%s", v) + if _, ok := item.Labels[labelKey]; !ok { + return false + } case Keyword: if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) { return false diff --git a/pkg/models/resources/resources.go b/pkg/models/resources/resources.go index 428ee70fbab519e7581658fba6f02312712ab28f..4017cced5bf75108b2be5eab3d5ece76a3cb8658 100644 --- a/pkg/models/resources/resources.go +++ b/pkg/models/resources/resources.go @@ -61,6 +61,7 @@ const ( Label = "label" OwnerKind = "ownerKind" OwnerName = "ownerName" + Role = "role" CreateTime = "createTime" UpdateTime = "updateTime" LastScheduleTime = "lastScheduleTime" diff --git a/pkg/simple/client/k8s/k8sclient.go b/pkg/simple/client/k8s/k8sclient.go index 62f8a56da105a254aa9e8eaa542963b2c0bebfa6..399233707d0800f3ed6f48db645526623b8ea17c 100644 --- a/pkg/simple/client/k8s/k8sclient.go +++ b/pkg/simple/client/k8s/k8sclient.go @@ -34,12 +34,12 @@ var ( k8sClient *kubernetes.Clientset k8sClientOnce sync.Once KubeConfig *rest.Config - masterURL string + MasterURL string ) func init() { flag.StringVar(&kubeConfigFile, "kubeconfig", "", "path to kubeconfig file") - flag.StringVar(&masterURL, "master-url", "", "kube-apiserver url, only needed when out of cluster") + flag.StringVar(&MasterURL, "master-url", "", "kube-apiserver url, only needed when out of cluster") } func Client() *kubernetes.Clientset { @@ -63,7 +63,7 @@ func Client() *kubernetes.Clientset { func Config() (kubeConfig *rest.Config, err error) { if _, err = os.Stat(kubeConfigFile); err == nil { - kubeConfig, err = clientcmd.BuildConfigFromFlags(masterURL, kubeConfigFile) + kubeConfig, err = clientcmd.BuildConfigFromFlags(MasterURL, kubeConfigFile) } else { kubeConfig, err = rest.InClusterConfig() } diff --git a/pkg/simple/client/prometheus/prometheusclient.go b/pkg/simple/client/prometheus/prometheusclient.go index 4ed4b52575021450582fce31ec3e23e21cb5b69e..6f8fabbd682b532e764ed0c1dd6ca5b963e5d29d 100644 --- a/pkg/simple/client/prometheus/prometheusclient.go +++ b/pkg/simple/client/prometheus/prometheusclient.go @@ -114,7 +114,7 @@ func ParseMonitoringRequestParams(request *restful.Request) *MonitoringRequestPa nsName := strings.Trim(request.PathParameter("namespace"), " ") podName := strings.Trim(request.PathParameter("pod"), " ") containerName := strings.Trim(request.PathParameter("container"), " ") - workloadKind := strings.Trim(request.PathParameter("workload_kind"), " ") + workloadKind := strings.Trim(request.PathParameter("kind"), " ") componentName := strings.Trim(request.PathParameter("component"), " ") var requestParams = MonitoringRequestParams{