diff --git a/Makefile b/Makefile index 6d7b410ff..0de4b1910 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,7 @@ -GOBIN ?= ${GOPATH}/bin +GOPATH ?= $(HOME)/go +GOBIN ?= $(GOPATH)/bin +GOIMPORTS = $(GOBIN)/goimports +CONTROLLERGEN = $(GOBIN)/controller-gen IMG ?= tackle2-hub:latest HUB_BASE_URL ?= http://localhost:8080 @@ -6,6 +9,8 @@ PKG = ./addon/... \ ./api/... \ ./assessment/... \ ./auth/... \ + ./binding/... \ + ./controller/... \ ./cmd/... \ ./database/... \ ./encryption/... \ @@ -14,41 +19,47 @@ PKG = ./addon/... \ ./metrics/... \ ./migration/... \ ./model/... \ + ./nas/... \ + ./reaper/... \ + ./seed/... \ ./settings/... \ - ./controller/... \ + ./tar/... \ ./task/... \ + ./test/... \ ./tracker/... +PKGDIR = $(subst /...,,$(PKG)) + BUILD = --tags json1 -o bin/hub github.com/konveyor/tackle2-hub/cmd # Build ALL commands. cmd: hub addon -# Run go fmt against code -fmt: - go fmt ${PKG} +# Format the code. +fmt: $(GOIMPORTS) + $(GOIMPORTS) -w $(PKGDIR) # Run go vet against code vet: - go vet ${PKG} + go vet $(PKG) # Build hub hub: generate fmt vet - go build ${BUILD} + go build $(BUILD) # Build image docker-build: - docker build -t ${IMG} . + docker build -t $(IMG) . podman-build: - podman build -t ${IMG} . + podman build -t $(IMG) . # Build manager binary with compiler optimizations disabled debug: generate fmt vet - go build -gcflags=all="-N -l" ${BUILD} + go build -gcflags=all="-N -l" $(BUILD) docker: vet - go build ${BUILD} + go build $(BUILD) # Run against the configured Kubernetes cluster in ~/.kube/config run: fmt vet @@ -58,25 +69,22 @@ run-addon: go run ./hack/cmd/addon/main.go # Generate manifests e.g. CRD, Webhooks -manifests: controller-gen - controller-gen ${CRD_OPTIONS} \ +manifests: $(CONTROLLERGEN) + $(CONTROLLERGEN) $(CRD_OPTIONS) \ crd rbac:roleName=manager-role \ paths="./..." output:crd:artifacts:config=generated/crd/bases output:crd:dir=generated/crd # Generate code -generate: controller-gen - controller-gen object:headerFile="./generated/boilerplate" paths="./..." - -# Find or download controller-gen. -controller-gen: - if [ "$(shell which controller-gen)" = "" ]; then \ - set -e ;\ - CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\ - cd $$CONTROLLER_GEN_TMP_DIR ;\ - go mod init tmp ;\ - go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.10.0 ;\ - rm -rf $$CONTROLLER_GEN_TMP_DIR ;\ - fi ;\ +generate: $(CONTROLLERGEN) + $(CONTROLLERGEN) object:headerFile="./generated/boilerplate" paths="./..." + +# Ensure controller-gen installed. +$(CONTROLLERGEN): + go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.10.0 + +# Ensure goimports installed. +$(GOIMPORTS): + go install golang.org/x/tools/cmd/goimports@latest # Build SAMPLE ADDON addon: fmt vet @@ -86,7 +94,7 @@ docs: docs-html docs-openapi3 docs-binding # Build Swagger API spec into ./docs directory docs-swagger: - ${GOBIN}/swag init -g pkg.go --dir api,assessment + $(GOBIN)/swag init -g pkg.go --dir api,assessment # Build OpenAPI 3.0 docs docs-openapi3: docs-swagger @@ -135,7 +143,7 @@ test: # Run Hub REST API tests. test-api: - HUB_BASE_URL=${HUB_BASE_URL} go test -count=1 -p=1 -v ./test/api/... + HUB_BASE_URL=$(HUB_BASE_URL) go test -count=1 -p=1 -v ./test/api/... # Run Hub test suite. test-all: test-unit test-api diff --git a/addon/adapter.go b/addon/adapter.go index d38659426..6f5d8f147 100644 --- a/addon/adapter.go +++ b/addon/adapter.go @@ -21,7 +21,6 @@ var ( Log = logr.WithName("addon") ) -// // Addon An addon adapter configured for a task execution. var Addon *Adapter @@ -35,20 +34,17 @@ func init() { Addon = newAdapter() } -// // Client type Client = binding.Client type Params = binding.Params type Param = binding.Param type Path = binding.Path -// // Error type ResetError = binding.RestError type Conflict = binding.Conflict type NotFound = binding.NotFound -// // Handler type Application = binding.Application type Bucket = binding.Bucket @@ -61,11 +57,9 @@ type Setting = binding.Setting type Tag = binding.Tag type TagCategory = binding.TagCategory -// // Filter type Filter = binding.Filter -// // The Adapter provides hub/addon integration. type Adapter struct { // Task API. @@ -92,12 +86,11 @@ type Adapter struct { client *Client } -// // Run addon. // Reports: -// - Started -// - Succeeded -// - Failed (when addon returns error). +// - Started +// - Succeeded +// - Failed (when addon returns error). func (h *Adapter) Run(addon func() error) { var err error // @@ -136,7 +129,6 @@ func (h *Adapter) Run(addon func() error) { } } -// // newAdapter builds a new Addon Adapter object. func newAdapter() (adapter *Adapter) { richClient := binding.New(Settings.Addon.Hub.URL) diff --git a/addon/error.go b/addon/error.go index 541d019b6..96ee19747 100644 --- a/addon/error.go +++ b/addon/error.go @@ -1,6 +1,5 @@ package addon -// // SoftError A "soft" anticipated error. // Deprecated: type SoftError struct { diff --git a/addon/task.go b/addon/task.go index c71f09c51..0f3a91c64 100644 --- a/addon/task.go +++ b/addon/task.go @@ -3,13 +3,13 @@ package addon import ( "encoding/json" "fmt" + "strings" + "github.com/konveyor/tackle2-hub/api" "github.com/konveyor/tackle2-hub/binding" "github.com/konveyor/tackle2-hub/task" - "strings" ) -// // Task API. type Task struct { richClient *binding.RichClient @@ -19,7 +19,6 @@ type Task struct { report api.TaskReport } -// // Load a task by ID. func (h *Task) Load() { var err error @@ -32,7 +31,6 @@ func (h *Task) Load() { return } -// // Application returns the application associated with the task. func (h *Task) Application() (r *api.Application, err error) { appRef := h.task.Application @@ -44,14 +42,12 @@ func (h *Task) Application() (r *api.Application, err error) { return } -// // Data returns the addon data. func (h *Task) Data() (d map[string]interface{}) { d = h.task.Data.(map[string]interface{}) return } -// // DataWith populates the addon data object. func (h *Task) DataWith(object interface{}) (err error) { b, _ := json.Marshal(h.task.Data) @@ -59,13 +55,11 @@ func (h *Task) DataWith(object interface{}) (err error) { return } -// // Variant returns the task variant. func (h *Task) Variant() string { return h.task.Variant } -// // Started report addon started. func (h *Task) Started() { h.deleteReport() @@ -75,7 +69,6 @@ func (h *Task) Started() { return } -// // Succeeded report addon succeeded. func (h *Task) Succeeded() { h.report.Status = task.Succeeded @@ -85,7 +78,6 @@ func (h *Task) Succeeded() { return } -// // Failed report addon failed. // The reason can be a printf style format. func (h *Task) Failed(reason string, v ...interface{}) { @@ -101,7 +93,6 @@ func (h *Task) Failed(reason string, v ...interface{}) { return } -// // Errorf report addon error. func (h *Task) Errorf(severity, description string, v ...interface{}) { h.Error(api.TaskError{ @@ -110,7 +101,6 @@ func (h *Task) Errorf(severity, description string, v ...interface{}) { }) } -// // Error report addon error. func (h *Task) Error(error ...api.TaskError) { h.report.Status = task.Failed @@ -127,7 +117,6 @@ func (h *Task) Error(error ...api.TaskError) { return } -// // Activity report addon activity. // The description can be a printf style format. func (h *Task) Activity(entry string, v ...interface{}) { @@ -151,7 +140,6 @@ func (h *Task) Activity(entry string, v ...interface{}) { return } -// // Attach ensures the file is attached to the report // associated with the last entry in the activity. func (h *Task) Attach(f *api.File) { @@ -160,7 +148,6 @@ func (h *Task) Attach(f *api.File) { return } -// // AttachAt ensures the file is attached to // the report indexed to the activity. // The activity is a 1-based index. Zero(0) means NOT associated. @@ -191,7 +178,6 @@ func (h *Task) AttachAt(f *api.File, activity int) { return } -// // Total report addon total items. func (h *Task) Total(n int) { h.report.Total = n @@ -203,7 +189,6 @@ func (h *Task) Total(n int) { return } -// // Increment report addon completed (+1) items. func (h *Task) Increment() { h.report.Completed++ @@ -215,7 +200,6 @@ func (h *Task) Increment() { return } -// // Completed report addon completed (N) items. func (h *Task) Completed(n int) { h.report.Completed = n @@ -224,14 +208,12 @@ func (h *Task) Completed(n int) { return } -// // Bucket returns the bucket API. func (h *Task) Bucket() (b *binding.BucketContent) { b = h.richClient.Task.Bucket(h.task.ID) return } -// // Result report addon result. func (h *Task) Result(object interface{}) { h.report.Result = object @@ -240,7 +222,6 @@ func (h *Task) Result(object interface{}) { return } -// // deleteReport deletes the task report. func (h *Task) deleteReport() { params := Params{ @@ -253,7 +234,6 @@ func (h *Task) deleteReport() { } } -// // pushReport create/update the task report. func (h *Task) pushReport() { var err error diff --git a/api/addon.go b/api/addon.go index 19d51f9d5..4f11a88a4 100644 --- a/api/addon.go +++ b/api/addon.go @@ -2,27 +2,25 @@ package api import ( "context" + "net/http" + "github.com/gin-gonic/gin" crd "github.com/konveyor/tackle2-hub/k8s/api/tackle/v1alpha1" "k8s.io/apimachinery/pkg/api/errors" - "net/http" k8s "sigs.k8s.io/controller-runtime/pkg/client" ) -// // Routes const ( AddonsRoot = "/addons" AddonRoot = AddonsRoot + "/:" + Name ) -// // AddonHandler handles addon routes. type AddonHandler struct { BaseHandler } -// // AddRoutes adds routes. func (h AddonHandler) AddRoutes(e *gin.Engine) { routeGroup := e.Group("/") @@ -94,14 +92,12 @@ func (h AddonHandler) List(ctx *gin.Context) { h.Respond(ctx, http.StatusOK, content) } -// // Addon REST resource. type Addon struct { Name string `json:"name"` Image string `json:"image"` } -// // With model. func (r *Addon) With(m *crd.Addon) { r.Name = m.Name diff --git a/api/adoptionplan.go b/api/adoptionplan.go index c36e7d730..9ac005c38 100644 --- a/api/adoptionplan.go +++ b/api/adoptionplan.go @@ -1,14 +1,14 @@ package api import ( + "net/http" + "strings" + "github.com/gin-gonic/gin" "github.com/konveyor/tackle2-hub/model" "gorm.io/gorm/clause" - "net/http" - "strings" ) -// // Effort estimates const ( EffortS = "small" @@ -17,19 +17,15 @@ const ( EffortXL = "extra_large" ) -// // Routes const ( AdoptionPlansRoot = "/reports/adoptionplan" ) -// -// type AdoptionPlanHandler struct { BaseHandler } -// // AddRoutes adds routes. func (h AdoptionPlanHandler) AddRoutes(e *gin.Engine) { routeGroup := e.Group("/") @@ -110,7 +106,6 @@ func (h AdoptionPlanHandler) Graph(ctx *gin.Context) { h.Respond(ctx, http.StatusOK, sorted) } -// // Vertex represents a vertex in the dependency graph. type Vertex struct { ID uint `json:"applicationId" yaml:"applicationId"` @@ -122,7 +117,6 @@ type Vertex struct { PositionX int `json:"positionX" yaml:"positionX"` } -// // NewDependencyGraph creates an empty dependency graph. func NewDependencyGraph() (graph DependencyGraph) { graph.vertices = make(map[uint]*Vertex) @@ -132,7 +126,6 @@ func NewDependencyGraph() (graph DependencyGraph) { return } -// // DependencyGraph is an application dependency graph. type DependencyGraph struct { // all applications @@ -145,27 +138,23 @@ type DependencyGraph struct { costs map[uint]int } -// // AddVertex adds a vertex to the graph. func (r *DependencyGraph) AddVertex(v *Vertex) { r.vertices[v.ID] = v } -// // HasVertex checks for the presence of a vertex in the graph. func (r *DependencyGraph) HasVertex(v uint) (ok bool) { _, ok = r.vertices[v] return } -// // AddEdge adds an edge between two vertices. func (r *DependencyGraph) AddEdge(v, w uint) { r.edges[v] = append(r.edges[v], w) r.incoming[w] = append(r.incoming[w], v) } -// // CalculateCost calculates the total cost to reach a given vertex. // Costs are memoized. func (r *DependencyGraph) CalculateCost(v uint) (cumulativeCost int) { @@ -189,7 +178,6 @@ func (r *DependencyGraph) CalculateCost(v uint) (cumulativeCost int) { return } -// // TopologicalSort sorts the graph such that the vertices // with fewer dependencies are first, and detects cycles. func (r *DependencyGraph) TopologicalSort() (sorted []*Vertex, ok bool) { diff --git a/api/analysis.go b/api/analysis.go index 92efeabb1..b8b5a12be 100644 --- a/api/analysis.go +++ b/api/analysis.go @@ -4,6 +4,13 @@ import ( "bytes" "encoding/json" "errors" + "io" + "net/http" + "os" + "sort" + "strconv" + "strings" + "github.com/gin-gonic/gin" "github.com/gin-gonic/gin/binding" qf "github.com/konveyor/tackle2-hub/api/filter" @@ -13,15 +20,8 @@ import ( "gorm.io/gorm" "gorm.io/gorm/clause" "gorm.io/gorm/logger" - "io" - "net/http" - "os" - "sort" - "strconv" - "strings" ) -// // Routes const ( AnalysesRoot = "/analyses" @@ -54,13 +54,11 @@ const ( DepField = "dependencies" ) -// // AnalysisHandler handles analysis resource routes. type AnalysisHandler struct { BaseHandler } -// // AddRoutes adds routes. func (h AnalysisHandler) AddRoutes(e *gin.Engine) { // Primary @@ -1628,7 +1626,6 @@ func (h AnalysisHandler) DepAppReports(ctx *gin.Context) { h.Respond(ctx, http.StatusOK, resources) } -// // appIDs provides application IDs. // filter: // - application.(id|name) @@ -1673,7 +1670,6 @@ func (h *AnalysisHandler) appIDs(ctx *gin.Context, f qf.Filter) (q *gorm.DB) { return } -// // analysisIDs provides analysis IDs. func (h *AnalysisHandler) analysisIDs(ctx *gin.Context, f qf.Filter) (q *gorm.DB) { q = h.DB(ctx) @@ -1684,10 +1680,10 @@ func (h *AnalysisHandler) analysisIDs(ctx *gin.Context, f qf.Filter) (q *gorm.DB return } -// // issueIDs returns issue filtered issue IDs. // Filter: -// issue.* +// +// issue.* func (h *AnalysisHandler) issueIDs(ctx *gin.Context, f qf.Filter) (q *gorm.DB) { q = h.DB(ctx) q = q.Model(&model.Issue{}) @@ -1720,10 +1716,10 @@ func (h *AnalysisHandler) issueIDs(ctx *gin.Context, f qf.Filter) (q *gorm.DB) { return } -// // depIDs returns issue filtered issue IDs. // Filter: -// techDeps.* +// +// techDeps.* func (h *AnalysisHandler) depIDs(ctx *gin.Context, f qf.Filter) (q *gorm.DB) { q = h.DB(ctx) q = q.Model(&model.TechDependency{}) @@ -1756,7 +1752,6 @@ func (h *AnalysisHandler) depIDs(ctx *gin.Context, f qf.Filter) (q *gorm.DB) { return } -// // archive // - Set the 'archived' flag. // - Set the 'summary' field with archived issues. @@ -1818,7 +1813,6 @@ func (h *AnalysisHandler) archive(ctx *gin.Context) (err error) { return } -// // Analysis REST resource. type Analysis struct { Resource `yaml:",inline"` @@ -1829,7 +1823,6 @@ type Analysis struct { Summary []ArchivedIssue `json:"summary,omitempty" yaml:",omitempty" swaggertype:"object"` } -// // With updates the resource with the model. func (r *Analysis) With(m *model.Analysis) { r.Resource.With(&m.Model) @@ -1856,7 +1849,6 @@ func (r *Analysis) With(m *model.Analysis) { } } -// // Model builds a model. func (r *Analysis) Model() (m *model.Analysis) { m = &model.Analysis{} @@ -1878,7 +1870,6 @@ func (r *Analysis) Model() (m *model.Analysis) { return } -// // Issue REST resource. type Issue struct { Resource `yaml:",inline"` @@ -1894,7 +1885,6 @@ type Issue struct { Labels []string `json:"labels"` } -// // With updates the resource with the model. func (r *Issue) With(m *model.Issue) { r.Resource.With(&m.Model) @@ -1923,7 +1913,6 @@ func (r *Issue) With(m *model.Issue) { r.Effort = m.Effort } -// // Model builds a model. func (r *Issue) Model() (m *model.Issue) { m = &model.Issue{} @@ -1946,7 +1935,6 @@ func (r *Issue) Model() (m *model.Issue) { return } -// // TechDependency REST resource. type TechDependency struct { Resource `yaml:",inline"` @@ -1958,7 +1946,6 @@ type TechDependency struct { SHA string `json:"sha,omitempty" yaml:",omitempty"` } -// // With updates the resource with the model. func (r *TechDependency) With(m *model.TechDependency) { r.Resource.With(&m.Model) @@ -1972,7 +1959,6 @@ func (r *TechDependency) With(m *model.TechDependency) { } } -// // Model builds a model. func (r *TechDependency) Model() (m *model.TechDependency) { sort.Strings(r.Labels) @@ -1986,7 +1972,6 @@ func (r *TechDependency) Model() (m *model.TechDependency) { return } -// // Incident REST resource. type Incident struct { Resource `yaml:",inline"` @@ -1997,7 +1982,6 @@ type Incident struct { Facts FactMap `json:"facts"` } -// // With updates the resource with the model. func (r *Incident) With(m *model.Incident) { r.Resource.With(&m.Model) @@ -2010,7 +1994,6 @@ func (r *Incident) With(m *model.Incident) { } } -// // Model builds a model. func (r *Incident) Model() (m *model.Incident) { m = &model.Incident{} @@ -2022,18 +2005,15 @@ func (r *Incident) Model() (m *model.Incident) { return } -// // Link analysis report link. type Link struct { URL string `json:"url"` Title string `json:"title,omitempty" yaml:",omitempty"` } -// // ArchivedIssue created when issues are archived. type ArchivedIssue model.ArchivedIssue -// // RuleReport REST resource. type RuleReport struct { RuleSet string `json:"ruleset"` @@ -2047,7 +2027,6 @@ type RuleReport struct { Applications int `json:"applications"` } -// // IssueReport REST resource. type IssueReport struct { ID uint `json:"id"` @@ -2062,7 +2041,6 @@ type IssueReport struct { Files int `json:"files"` } -// // IssueAppReport REST resource. type IssueAppReport struct { ID uint `json:"id"` @@ -2081,7 +2059,6 @@ type IssueAppReport struct { } `json:"issue"` } -// // FileReport REST resource. type FileReport struct { IssueID uint `json:"issueId" yaml:"issueId"` @@ -2090,7 +2067,6 @@ type FileReport struct { Effort int `json:"effort"` } -// // DepReport REST resource. type DepReport struct { Provider string `json:"provider"` @@ -2099,7 +2075,6 @@ type DepReport struct { Applications int `json:"applications"` } -// // DepAppReport REST resource. type DepAppReport struct { ID uint `json:"id"` @@ -2117,18 +2092,15 @@ type DepAppReport struct { } `json:"dependency"` } -// // FactMap map. type FactMap map[string]interface{} -// // AnalysisWriter used to create a file containing an analysis. type AnalysisWriter struct { encoder ctx *gin.Context } -// // db returns a db client. func (r *AnalysisWriter) db() (db *gorm.DB) { rtx := WithContext(r.ctx) @@ -2136,7 +2108,6 @@ func (r *AnalysisWriter) db() (db *gorm.DB) { return } -// // Create an analysis file and returns the path. func (r *AnalysisWriter) Create(id uint) (path string, err error) { ext := ".json" @@ -2162,7 +2133,6 @@ func (r *AnalysisWriter) Create(id uint) (path string, err error) { return } -// // Write the analysis file. func (r *AnalysisWriter) Write(id uint, output io.Writer) (err error) { m := &model.Analysis{} @@ -2191,7 +2161,6 @@ func (r *AnalysisWriter) Write(id uint, output io.Writer) (err error) { return } -// // newEncoder returns an encoder. func (r *AnalysisWriter) newEncoder(output io.Writer) (encoder encoder, err error) { accepted := r.ctx.NegotiateFormat(BindMIMEs...) @@ -2209,7 +2178,6 @@ func (r *AnalysisWriter) newEncoder(output io.Writer) (encoder encoder, err erro return } -// // addIssues writes issues. func (r *AnalysisWriter) addIssues(m *model.Analysis) (err error) { r.field("issues") @@ -2238,7 +2206,6 @@ func (r *AnalysisWriter) addIssues(m *model.Analysis) (err error) { return } -// // addDeps writes dependencies. func (r *AnalysisWriter) addDeps(m *model.Analysis) (err error) { r.field("dependencies") @@ -2266,14 +2233,12 @@ func (r *AnalysisWriter) addDeps(m *model.Analysis) (err error) { return } -// // ReportWriter analysis report writer. type ReportWriter struct { encoder ctx *gin.Context } -// // db returns a db client. func (r *ReportWriter) db() (db *gorm.DB) { rtx := WithContext(r.ctx) @@ -2281,7 +2246,6 @@ func (r *ReportWriter) db() (db *gorm.DB) { return } -// // Write builds and streams the analysis report. func (r *ReportWriter) Write(id uint) { reportDir := Settings.Analysis.ReportPath @@ -2316,7 +2280,6 @@ func (r *ReportWriter) Write(id uint) { return } -// // buildOutput creates the report output.js file. func (r *ReportWriter) buildOutput(id uint) (path string, err error) { m := &model.Analysis{} @@ -2361,7 +2324,6 @@ func (r *ReportWriter) buildOutput(id uint) (path string, err error) { return } -// // addTags writes tags. func (r *ReportWriter) addTags(m *model.Analysis) (err error) { r.field("tags") diff --git a/api/api_test.go b/api/api_test.go index 09a314a32..cb19399ec 100644 --- a/api/api_test.go +++ b/api/api_test.go @@ -1,10 +1,11 @@ package api import ( - "github.com/gin-gonic/gin" - "github.com/onsi/gomega" "net/http" "testing" + + "github.com/gin-gonic/gin" + "github.com/onsi/gomega" ) func TestAccepted(t *testing.T) { diff --git a/api/application.go b/api/application.go index 5de64271c..1e3df78e3 100644 --- a/api/application.go +++ b/api/application.go @@ -13,7 +13,6 @@ import ( "gorm.io/gorm/clause" ) -// // Routes const ( ApplicationsRoot = "/applications" @@ -29,26 +28,22 @@ const ( AppAssessmentRoot = AppAssessmentsRoot + "/:" + ID2 ) -// // Params const ( Source = "source" ) -// // Tag Sources const ( SourceAssessment = "assessment" SourceArchetype = "archetype" ) -// // ApplicationHandler handles application resource routes. type ApplicationHandler struct { BucketOwner } -// // AddRoutes adds routes. func (h ApplicationHandler) AddRoutes(e *gin.Engine) { routeGroup := e.Group("/") @@ -959,7 +954,7 @@ func (h ApplicationHandler) StakeholdersUpdate(ctx *gin.Context) { func (h ApplicationHandler) AssessmentList(ctx *gin.Context) { m := &model.Application{} id := h.pk(ctx) - db := h.preLoad(h.DB(ctx), clause.Associations, "Assessments.Stakeholders", "Assessments.StakeholderGroups") + db := h.preLoad(h.DB(ctx), clause.Associations, "Assessments.Stakeholders", "Assessments.StakeholderGroups", "Assessments.Questionnaire") db = db.Omit("Analyses") result := db.First(m, id) if result.Error != nil { @@ -1066,7 +1061,6 @@ func (h ApplicationHandler) AssessmentCreate(ctx *gin.Context) { h.Respond(ctx, http.StatusCreated, r) } -// // Application REST resource. type Application struct { Resource `yaml:",inline"` @@ -1091,7 +1085,6 @@ type Application struct { Effort int `json:"effort"` } -// // With updates the resource using the model. func (r *Application) With(m *model.Application, tags []model.ApplicationTag) { r.Resource.With(&m.Model) @@ -1146,7 +1139,6 @@ func (r *Application) With(m *model.Application, tags []model.ApplicationTag) { r.Risk = assessment.RiskUnknown } -// // WithVirtualTags updates the resource with tags derived from assessments. func (r *Application) WithVirtualTags(tags []model.Tag, source string) { for _, t := range tags { @@ -1156,7 +1148,6 @@ func (r *Application) WithVirtualTags(tags []model.Tag, source string) { } } -// // WithResolver uses an ApplicationResolver to update the resource with // values derived from the application's assessments and archetypes. func (r *Application) WithResolver(resolver *assessment.ApplicationResolver) (err error) { @@ -1192,7 +1183,6 @@ func (r *Application) WithResolver(resolver *assessment.ApplicationResolver) (er return } -// // Model builds a model. func (r *Application) Model() (m *model.Application) { m = &model.Application{ @@ -1245,7 +1235,6 @@ func (r *Application) Model() (m *model.Application) { return } -// // Repository REST nested resource. type Repository struct { Kind string `json:"kind"` @@ -1255,7 +1244,6 @@ type Repository struct { Path string `json:"path"` } -// // Fact REST nested resource. type Fact struct { Key string `json:"key"` @@ -1277,20 +1265,21 @@ func (r *Fact) Model() (m *model.Fact) { return } -// // FactKey is a fact source and fact name separated by a colon. -// Example: 'analysis:languages' +// +// Example: 'analysis:languages' // // A FactKey can be used to identify an anonymous fact. -// Example: 'languages' or ':languages' +// +// Example: 'languages' or ':languages' // // A FactKey can also be used to identify just a source. This use must include the trailing // colon to distinguish it from an anonymous fact. This is used when listing or replacing // all facts that belong to a source. -// Example: 'analysis:" +// +// Example: 'analysis:" type FactKey string -// // Qualify qualifies the name with the source. func (r *FactKey) Qualify(source string) { *r = FactKey( @@ -1299,7 +1288,6 @@ func (r *FactKey) Qualify(source string) { ":")) } -// // Source returns the source portion of a fact key. func (r FactKey) Source() (source string) { s, _, found := strings.Cut(string(r), ":") @@ -1309,7 +1297,6 @@ func (r FactKey) Source() (source string) { return } -// // Name returns the name portion of a fact key. func (r FactKey) Name() (name string) { _, n, found := strings.Cut(string(r), ":") @@ -1321,7 +1308,6 @@ func (r FactKey) Name() (name string) { return } -// // Stakeholders REST subresource. type Stakeholders struct { Owner *Ref `json:"owner"` diff --git a/api/archetype.go b/api/archetype.go index c1c6dea91..e2efd0670 100644 --- a/api/archetype.go +++ b/api/archetype.go @@ -10,7 +10,6 @@ import ( "gorm.io/gorm/clause" ) -// // Routes const ( ArchetypesRoot = "/archetypes" @@ -18,13 +17,11 @@ const ( ArchetypeAssessmentsRoot = ArchetypeRoot + "/assessments" ) -// // ArchetypeHandler handles Archetype resource routes. type ArchetypeHandler struct { BaseHandler } -// // AddRoutes adds routes. func (h ArchetypeHandler) AddRoutes(e *gin.Engine) { routeGroup := e.Group("/") @@ -254,7 +251,7 @@ func (h ArchetypeHandler) Update(ctx *gin.Context) { func (h ArchetypeHandler) AssessmentList(ctx *gin.Context) { m := &model.Archetype{} id := h.pk(ctx) - db := h.preLoad(h.DB(ctx), clause.Associations, "Assessments.Stakeholders", "Assessments.StakeholderGroups") + db := h.preLoad(h.DB(ctx), clause.Associations, "Assessments.Stakeholders", "Assessments.StakeholderGroups", "Assessments.Questionnaire") result := db.First(m, id) if result.Error != nil { _ = ctx.Error(result.Error) @@ -335,7 +332,6 @@ func (h ArchetypeHandler) AssessmentCreate(ctx *gin.Context) { h.Respond(ctx, http.StatusCreated, r) } -// // Archetype REST resource. type Archetype struct { Resource `yaml:",inline"` @@ -354,7 +350,6 @@ type Archetype struct { Review *Ref `json:"review"` } -// // With updates the resource with the model. func (r *Archetype) With(m *model.Archetype) { r.Resource.With(&m.Model) @@ -393,7 +388,6 @@ func (r *Archetype) With(m *model.Archetype) { r.Risk = assessment.RiskUnknown } -// // WithResolver uses an ArchetypeResolver to update the resource with // values derived from the archetype's assessments. func (r *Archetype) WithResolver(resolver *assessment.ArchetypeResolver) (err error) { @@ -416,7 +410,6 @@ func (r *Archetype) WithResolver(resolver *assessment.ArchetypeResolver) (err er return } -// // Model builds a model from the resource. func (r *Archetype) Model() (m *model.Archetype) { m = &model.Archetype{ diff --git a/api/assessment.go b/api/assessment.go index 4f34de7d9..d024637eb 100644 --- a/api/assessment.go +++ b/api/assessment.go @@ -10,20 +10,17 @@ import ( "gorm.io/gorm/clause" ) -// // Routes const ( AssessmentsRoot = "/assessments" AssessmentRoot = AssessmentsRoot + "/:" + ID ) -// // AssessmentHandler handles Assessment resource routes. type AssessmentHandler struct { BaseHandler } -// // AddRoutes adds routes. func (h AssessmentHandler) AddRoutes(e *gin.Engine) { routeGroup := e.Group("/") @@ -148,7 +145,6 @@ func (h AssessmentHandler) Update(ctx *gin.Context) { h.Status(ctx, http.StatusNoContent) } -// // Assessment REST resource. type Assessment struct { Resource `yaml:",inline"` @@ -164,9 +160,9 @@ type Assessment struct { Status string `json:"status"` Thresholds assessment.Thresholds `json:"thresholds"` RiskMessages assessment.RiskMessages `json:"riskMessages" yaml:"riskMessages"` + Required bool `json:"required"` } -// // With updates the resource with the model. func (r *Assessment) With(m *model.Assessment) { r.Resource.With(&m.Model) @@ -187,6 +183,7 @@ func (r *Assessment) With(m *model.Assessment) { } a := assessment.Assessment{} a.With(m) + r.Required = a.Questionnaire.Required r.Risk = a.Risk() r.Confidence = a.Confidence() r.RiskMessages = a.RiskMessages @@ -195,7 +192,6 @@ func (r *Assessment) With(m *model.Assessment) { r.Status = a.Status() } -// // Model builds a model. func (r *Assessment) Model() (m *model.Assessment) { m = &model.Assessment{} diff --git a/api/auth.go b/api/auth.go index 8956813a5..5876143fc 100644 --- a/api/auth.go +++ b/api/auth.go @@ -1,12 +1,12 @@ package api import ( + "net/http" + "github.com/gin-gonic/gin" "github.com/konveyor/tackle2-hub/auth" - "net/http" ) -// // Routes const ( AuthRoot = "/auth" @@ -14,13 +14,11 @@ const ( AuthRefreshRoot = AuthRoot + "/refresh" ) -// // AuthHandler handles auth routes. type AuthHandler struct { BaseHandler } -// // AddRoutes adds routes. func (h AuthHandler) AddRoutes(e *gin.Engine) { e.POST(AuthLoginRoot, h.Login) @@ -87,7 +85,6 @@ func (h AuthHandler) Refresh(ctx *gin.Context) { h.Respond(ctx, http.StatusCreated, r) } -// // Login REST resource. type Login struct { User string `json:"user"` @@ -97,7 +94,6 @@ type Login struct { Expiry int `json:"expiry"` } -// // Required enforces that the user (identified by a token) has // been granted the necessary scope to access a resource. func Required(scope string) func(*gin.Context) { diff --git a/api/base.go b/api/base.go index d40512cb3..073cdda82 100644 --- a/api/base.go +++ b/api/base.go @@ -6,6 +6,11 @@ import ( "encoding/json" "errors" "fmt" + "io" + "strconv" + "strings" + "time" + "github.com/gin-gonic/gin" "github.com/gin-gonic/gin/binding" liberr "github.com/jortel/go-utils/error" @@ -16,11 +21,7 @@ import ( "github.com/konveyor/tackle2-hub/model" "gopkg.in/yaml.v2" "gorm.io/gorm" - "io" "sigs.k8s.io/controller-runtime/pkg/client" - "strconv" - "strings" - "time" ) var Log = logr.WithName("api") @@ -30,11 +31,9 @@ const ( MaxCount = 50000 ) -// // BaseHandler base handler. type BaseHandler struct{} -// // DB return db client associated with the context. func (h *BaseHandler) DB(ctx *gin.Context) (db *gorm.DB) { rtx := WithContext(ctx) @@ -42,7 +41,6 @@ func (h *BaseHandler) DB(ctx *gin.Context) (db *gorm.DB) { return } -// // Client returns k8s client from the context. func (h *BaseHandler) Client(ctx *gin.Context) (client client.Client) { rtx := WithContext(ctx) @@ -50,7 +48,6 @@ func (h *BaseHandler) Client(ctx *gin.Context) (client client.Client) { return } -// // WithCount report count. // Sets the X-Total header for pagination. // Returns an error when count exceeds the limited and @@ -78,7 +75,6 @@ func (h *BaseHandler) WithCount(ctx *gin.Context, count int64) (err error) { return } -// // preLoad update DB to pre-load fields. func (h *BaseHandler) preLoad(db *gorm.DB, fields ...string) (tx *gorm.DB) { tx = db @@ -89,14 +85,12 @@ func (h *BaseHandler) preLoad(db *gorm.DB, fields ...string) (tx *gorm.DB) { return } -// // fields builds a map of fields. func (h *BaseHandler) fields(m interface{}) (mp map[string]interface{}) { mp = reflect.Fields(m) return } -// // pk returns the PK (ID) parameter. func (h *BaseHandler) pk(ctx *gin.Context) (id uint) { s := ctx.Param(ID) @@ -105,11 +99,10 @@ func (h *BaseHandler) pk(ctx *gin.Context) (id uint) { return } -// // modBody updates the body using the `mod` function. -// 1. read the body. -// 2. mod() -// 3. write body. +// 1. read the body. +// 2. mod() +// 3. write body. func (h *BaseHandler) modBody( ctx *gin.Context, r interface{}, @@ -133,7 +126,6 @@ func (h *BaseHandler) modBody( return } -// // CurrentUser gets username from Keycloak auth token. func (h *BaseHandler) CurrentUser(ctx *gin.Context) (user string) { rtx := WithContext(ctx) @@ -145,7 +137,6 @@ func (h *BaseHandler) CurrentUser(ctx *gin.Context) (user string) { return } -// // HasScope determines if the token has the specified scope. func (h *BaseHandler) HasScope(ctx *gin.Context, scope string) (b bool) { in := auth.BaseScope{} @@ -160,7 +151,6 @@ func (h *BaseHandler) HasScope(ctx *gin.Context, scope string) (b bool) { return } -// // Bind based on Content-Type header. // Opinionated towards json. func (h *BaseHandler) Bind(ctx *gin.Context, r interface{}) (err error) { @@ -180,7 +170,6 @@ func (h *BaseHandler) Bind(ctx *gin.Context, r interface{}) (err error) { return } -// // BindJSON attempts to bind a request body to a struct, assuming that the body is JSON. // Binding is strict: unknown fields in the input will cause binding to fail. func (h *BaseHandler) BindJSON(ctx *gin.Context, r interface{}) (err error) { @@ -199,7 +188,6 @@ func (h *BaseHandler) BindJSON(ctx *gin.Context, r interface{}) (err error) { return } -// // BindYAML attempts to bind a request body to a struct, assuming that the body is YAML. // Binding is strict: unknown fields in the input will cause binding to fail. func (h *BaseHandler) BindYAML(ctx *gin.Context, r interface{}) (err error) { @@ -218,7 +206,6 @@ func (h *BaseHandler) BindYAML(ctx *gin.Context, r interface{}) (err error) { return } -// // Validate that the struct field values obey the binding field tags. func (h *BaseHandler) Validate(r interface{}) (err error) { if binding.Validator == nil { @@ -231,7 +218,6 @@ func (h *BaseHandler) Validate(r interface{}) (err error) { return } -// // Decoder returns a decoder based on encoding. // Opinionated towards json. func (h *BaseHandler) Decoder(ctx *gin.Context, encoding string, r io.Reader) (d Decoder, err error) { @@ -255,21 +241,18 @@ func (h *BaseHandler) Decoder(ctx *gin.Context, encoding string, r io.Reader) (d return } -// // Status sets the status code. func (h *BaseHandler) Status(ctx *gin.Context, code int) { rtx := WithContext(ctx) rtx.Status(code) } -// // Respond sets the response. func (h *BaseHandler) Respond(ctx *gin.Context, code int, r interface{}) { rtx := WithContext(ctx) rtx.Respond(code, r) } -// // Accepted determines if the mime is accepted. // Wildcards ignored. func (h *BaseHandler) Accepted(ctx *gin.Context, mimes ...string) (b bool) { @@ -287,7 +270,6 @@ func (h *BaseHandler) Accepted(ctx *gin.Context, mimes ...string) (b bool) { return } -// // Attachment sets the Content-Disposition header. func (h *BaseHandler) Attachment(ctx *gin.Context, name string) { attachment := fmt.Sprintf("attachment; filename=\"%s\"", name) @@ -296,7 +278,6 @@ func (h *BaseHandler) Attachment(ctx *gin.Context, name string) { attachment) } -// // REST resource. type Resource struct { ID uint `json:"id,omitempty" yaml:"id,omitempty"` @@ -305,7 +286,6 @@ type Resource struct { CreateTime time.Time `json:"createTime" yaml:"createTime,omitempty"` } -// // With updates the resource with the model. func (r *Resource) With(m *model.Model) { r.ID = m.ID @@ -314,7 +294,6 @@ func (r *Resource) With(m *model.Model) { r.CreateTime = m.CreateTime } -// // ref with id and named model. func (r *Resource) ref(id uint, m interface{}) (ref Ref) { ref.ID = id @@ -322,7 +301,6 @@ func (r *Resource) ref(id uint, m interface{}) (ref Ref) { return } -// // refPtr with id and named model. func (r *Resource) refPtr(id *uint, m interface{}) (ref *Ref) { if id == nil { @@ -334,7 +312,6 @@ func (r *Resource) refPtr(id *uint, m interface{}) (ref *Ref) { return } -// // idPtr extracts ref ID. func (r *Resource) idPtr(ref *Ref) (id *uint) { if ref != nil { @@ -343,14 +320,12 @@ func (r *Resource) idPtr(ref *Ref) (id *uint) { return } -// // nameOf model. func (r *Resource) nameOf(m interface{}) (name string) { name = reflect.NameOf(m) return } -// // Ref represents a FK. // Contains the PK and (name) natural key. // The name is optional and read-only. @@ -359,14 +334,12 @@ type Ref struct { Name string `json:"name,omitempty"` } -// // With id and named model. func (r *Ref) With(id uint, name string) { r.ID = id r.Name = name } -// // TagRef represents a reference to a Tag. // Contains the tag ID, name, tag source. type TagRef struct { @@ -376,7 +349,6 @@ type TagRef struct { Virtual bool `json:"virtual,omitempty" yaml:"virtual,omitempty"` } -// // With id and named model. func (r *TagRef) With(id uint, name string, source string, virtual bool) { r.ID = id @@ -385,14 +357,12 @@ func (r *TagRef) With(id uint, name string, source string, virtual bool) { r.Virtual = virtual } -// // Page provides pagination. type Page struct { Offset int Limit int } -// // With context. func (p *Page) With(ctx *gin.Context) { s := ctx.Query("offset") @@ -406,7 +376,6 @@ func (p *Page) With(ctx *gin.Context) { return } -// // Paginated returns a paginated DB. func (p *Page) Paginated(in *gorm.DB) (out *gorm.DB) { out = in @@ -419,17 +388,14 @@ func (p *Page) Paginated(in *gorm.DB) (out *gorm.DB) { return } -// // Sort provides sorting. type Sort = sort.Sort -// // Decoder binding decoder. type Decoder interface { Decode(r interface{}) (err error) } -// // Cursor Paginated rows iterator. type Cursor struct { Page @@ -439,7 +405,6 @@ type Cursor struct { Error error } -// // Next returns true when has next row. func (r *Cursor) Next(m interface{}) (next bool) { if r.Error != nil { @@ -467,7 +432,6 @@ func (r *Cursor) Next(m interface{}) (next bool) { return } -// // With configures the cursor. func (r *Cursor) With(db *gorm.DB, p Page) { r.DB = db.Offset(p.Offset) @@ -476,14 +440,12 @@ func (r *Cursor) With(db *gorm.DB, p Page) { r.Page = p } -// // Count returns the count adjusted for offset. func (r *Cursor) Count() (n int64) { n = int64(r.Offset) + r.Index return n } -// // Close the cursor. func (r *Cursor) Close() { if r.Rows != nil { @@ -491,7 +453,6 @@ func (r *Cursor) Close() { } } -// // pageLimited returns true when page Limit defined and exceeded. func (r *Cursor) pageLimited() (b bool) { if r.Limit < 1 { @@ -501,7 +462,6 @@ func (r *Cursor) pageLimited() (b bool) { return } -// // StrMap returns a map[string]any. // The YAML decoder can produce map[any]any which is not valid for json. // Converts map[any]any to map[string]any as needed. diff --git a/api/batch.go b/api/batch.go index ccdc1098e..c569655f0 100644 --- a/api/batch.go +++ b/api/batch.go @@ -3,12 +3,12 @@ package api import ( "bytes" "encoding/json" - "github.com/gin-gonic/gin" "io" "net/http" + + "github.com/gin-gonic/gin" ) -// // Routes const ( BatchRoot = "/batch" @@ -16,13 +16,11 @@ const ( BatchTagsRoot = BatchRoot + TagsRoot ) -// // BatchHandler handles batch resource creation routes. type BatchHandler struct { BaseHandler } -// // AddRoutes adds routes. func (h BatchHandler) AddRoutes(e *gin.Engine) { routeGroup := e.Group("/") diff --git a/api/bucket.go b/api/bucket.go index bb3c36456..56d5e1e13 100644 --- a/api/bucket.go +++ b/api/bucket.go @@ -1,19 +1,19 @@ package api import ( - "github.com/gin-gonic/gin" - "github.com/gin-gonic/gin/binding" - "github.com/konveyor/tackle2-hub/model" - "github.com/konveyor/tackle2-hub/nas" - "github.com/konveyor/tackle2-hub/tar" "io" "net/http" "os" pathlib "path" "time" + + "github.com/gin-gonic/gin" + "github.com/gin-gonic/gin/binding" + "github.com/konveyor/tackle2-hub/model" + "github.com/konveyor/tackle2-hub/nas" + "github.com/konveyor/tackle2-hub/tar" ) -// // Routes const ( BucketsRoot = "/buckets" @@ -21,13 +21,11 @@ const ( BucketContentRoot = BucketRoot + "/*" + Wildcard ) -// // BucketHandler handles bucket routes. type BucketHandler struct { BucketOwner } -// // AddRoutes adds routes. func (h BucketHandler) AddRoutes(e *gin.Engine) { routeGroup := e.Group("/") @@ -192,7 +190,6 @@ func (h BucketHandler) BucketDelete(ctx *gin.Context) { h.bucketDelete(ctx, h.pk(ctx)) } -// // Bucket REST resource. type Bucket struct { Resource `yaml:",inline"` @@ -200,7 +197,6 @@ type Bucket struct { Expiration *time.Time `json:"expiration,omitempty"` } -// // With updates the resource with the model. func (r *Bucket) With(m *model.Bucket) { r.Resource.With(&m.Model) @@ -212,13 +208,15 @@ type BucketOwner struct { BaseHandler } -// // bucketGet reads bucket content. // When path is DIRECTORY: -// Accept=text/html return body is index.html. -// Else streams tarball. +// +// Accept=text/html return body is index.html. +// Else streams tarball. +// // When path is FILE: -// Streams FILE content. +// +// Streams FILE content. func (h *BucketOwner) bucketGet(ctx *gin.Context, id uint) { var err error m := &model.Bucket{} @@ -246,7 +244,6 @@ func (h *BucketOwner) bucketGet(ctx *gin.Context, id uint) { } } -// // bucketPut write a file to the bucket. // The `Directory` header determines how the uploaded file is to be handled. // When `Directory`=Expand, the file (TARBALL) is extracted into the bucket. @@ -271,7 +268,6 @@ func (h *BucketOwner) bucketPut(ctx *gin.Context, id uint) { h.Status(ctx, http.StatusNoContent) } -// // bucketDelete content from the bucket. func (h *BucketOwner) bucketDelete(ctx *gin.Context, id uint) { m := &model.Bucket{} @@ -290,7 +286,6 @@ func (h *BucketOwner) bucketDelete(ctx *gin.Context, id uint) { h.Status(ctx, http.StatusNoContent) } -// // putDir write a directory into bucket. func (h *BucketOwner) putDir(ctx *gin.Context, output string) (err error) { file, err := ctx.FormFile(FileField) @@ -316,7 +311,6 @@ func (h *BucketOwner) putDir(ctx *gin.Context, output string) (err error) { return } -// // getDir reads a directory from the bucket. func (h *BucketOwner) getDir(ctx *gin.Context, input string, filter tar.Filter) { tarWriter := tar.NewWriter(ctx.Writer) @@ -336,7 +330,6 @@ func (h *BucketOwner) getDir(ctx *gin.Context, input string, filter tar.Filter) return } -// // getFile reads a file from the bucket. func (h *BucketOwner) getFile(ctx *gin.Context, m *model.Bucket) { rPath := ctx.Param(Wildcard) @@ -344,7 +337,6 @@ func (h *BucketOwner) getFile(ctx *gin.Context, m *model.Bucket) { ctx.File(path) } -// // putFile writes a file to the bucket. func (h *BucketOwner) putFile(ctx *gin.Context, m *model.Bucket) (err error) { path := pathlib.Join(m.Path, ctx.Param(Wildcard)) diff --git a/api/businessservice.go b/api/businessservice.go index b715dd40e..41caf95b5 100644 --- a/api/businessservice.go +++ b/api/businessservice.go @@ -1,26 +1,24 @@ package api import ( + "net/http" + "github.com/gin-gonic/gin" "github.com/konveyor/tackle2-hub/model" "gorm.io/gorm/clause" - "net/http" ) -// // Routes const ( BusinessServicesRoot = "/businessservices" BusinessServiceRoot = BusinessServicesRoot + "/:" + ID ) -// // BusinessServiceHandler handles business-service routes. type BusinessServiceHandler struct { BaseHandler } -// // AddRoutes adds routes. func (h BusinessServiceHandler) AddRoutes(e *gin.Engine) { routeGroup := e.Group("/") @@ -164,7 +162,6 @@ func (h BusinessServiceHandler) Update(ctx *gin.Context) { h.Status(ctx, http.StatusNoContent) } -// // BusinessService REST resource. type BusinessService struct { Resource `yaml:",inline"` @@ -173,7 +170,6 @@ type BusinessService struct { Stakeholder *Ref `json:"owner"` } -// // With updates the resource with the model. func (r *BusinessService) With(m *model.BusinessService) { r.Resource.With(&m.Model) @@ -182,7 +178,6 @@ func (r *BusinessService) With(m *model.BusinessService) { r.Stakeholder = r.refPtr(m.StakeholderID, m.Stakeholder) } -// // Model builds a model. func (r *BusinessService) Model() (m *model.BusinessService) { m = &model.BusinessService{ diff --git a/api/cache.go b/api/cache.go index 3ade7b329..ed36b61a3 100644 --- a/api/cache.go +++ b/api/cache.go @@ -1,30 +1,28 @@ package api import ( - "github.com/gin-gonic/gin" - liberr "github.com/jortel/go-utils/error" - "github.com/konveyor/tackle2-hub/nas" "net/http" "os" "os/exec" pathlib "path" "strings" + + "github.com/gin-gonic/gin" + liberr "github.com/jortel/go-utils/error" + "github.com/konveyor/tackle2-hub/nas" ) -// // Routes const ( CacheRoot = "/cache" CacheDirRoot = CacheRoot + "/*" + Wildcard ) -// // CacheHandler handles cache routes. type CacheHandler struct { BaseHandler } -// // AddRoutes adds routes. func (h CacheHandler) AddRoutes(e *gin.Engine) { routeGroup := e.Group("/") @@ -91,7 +89,6 @@ func (h CacheHandler) Delete(ctx *gin.Context) { h.Status(ctx, http.StatusNoContent) } -// // cache builds the resource. func (h *CacheHandler) cache(dir string) (cache *Cache, err error) { cache = &Cache{} @@ -143,7 +140,6 @@ func (h *CacheHandler) cache(dir string) (cache *Cache, err error) { return } -// // Cache REST resource. type Cache struct { Path string `json:"path"` diff --git a/api/context.go b/api/context.go index 1f0a7a595..0a144c7cc 100644 --- a/api/context.go +++ b/api/context.go @@ -1,14 +1,14 @@ package api import ( + "net/http" + "github.com/gin-gonic/gin" "github.com/konveyor/tackle2-hub/auth" "gorm.io/gorm" - "net/http" "sigs.k8s.io/controller-runtime/pkg/client" ) -// // Context custom settings. type Context struct { *gin.Context @@ -24,14 +24,12 @@ type Context struct { Response Response } -// // Response values. type Response struct { Status int Body interface{} } -// // Status sets the values to respond to the request with. func (r *Context) Status(status int) { r.Response = Response{ @@ -40,7 +38,6 @@ func (r *Context) Status(status int) { } } -// // Respond sets the values to respond to the request with. func (r *Context) Respond(status int, body interface{}) { r.Response = Response{ @@ -49,7 +46,6 @@ func (r *Context) Respond(status int, body interface{}) { } } -// // WithContext is a rich context. func WithContext(ctx *gin.Context) (n *Context) { key := "RichContext" @@ -64,7 +60,6 @@ func WithContext(ctx *gin.Context) (n *Context) { return } -// // Transaction handler. func Transaction(ctx *gin.Context) { switch ctx.Request.Method { @@ -90,7 +85,6 @@ func Transaction(ctx *gin.Context) { } } -// // Render renders the response based on the Accept: header. // Opinionated towards json. func Render() gin.HandlerFunc { diff --git a/api/dependency.go b/api/dependency.go index 220e9157e..ec53269e9 100644 --- a/api/dependency.go +++ b/api/dependency.go @@ -8,20 +8,17 @@ import ( "gorm.io/gorm/clause" ) -// // Routes const ( DependenciesRoot = "/dependencies" DependencyRoot = DependenciesRoot + "/:" + ID ) -// // DependencyHandler handles application dependency routes. type DependencyHandler struct { BaseHandler } -// // AddRoutes adds routes. func (h DependencyHandler) AddRoutes(e *gin.Engine) { routeGroup := e.Group("/") @@ -56,7 +53,6 @@ func (h DependencyHandler) Get(ctx *gin.Context) { h.Respond(ctx, http.StatusOK, r) } -// // List godoc // @summary List all dependencies. // @description List all dependencies. @@ -145,7 +141,6 @@ func (h DependencyHandler) Delete(ctx *gin.Context) { h.Status(ctx, http.StatusNoContent) } -// // Dependency REST resource. type Dependency struct { Resource `yaml:",inline"` @@ -153,7 +148,6 @@ type Dependency struct { From Ref `json:"from"` } -// // With updates the resource using the model. func (r *Dependency) With(m *model.Dependency) { r.Resource.With(&m.Model) diff --git a/api/error.go b/api/error.go index f6e7c6024..2425c2344 100644 --- a/api/error.go +++ b/api/error.go @@ -2,6 +2,9 @@ package api import ( "errors" + "net/http" + "os" + "github.com/gin-gonic/gin" "github.com/go-playground/validator/v10" "github.com/konveyor/tackle2-hub/api/filter" @@ -9,11 +12,8 @@ import ( "github.com/konveyor/tackle2-hub/model" "github.com/mattn/go-sqlite3" "gorm.io/gorm" - "net/http" - "os" ) -// // BadRequestError reports bad request errors. type BadRequestError struct { Reason string @@ -28,7 +28,6 @@ func (r *BadRequestError) Is(err error) (matched bool) { return } -// // BatchError reports errors stemming from batch operations. type BatchError struct { Message string @@ -49,7 +48,6 @@ func (r BatchError) Is(err error) (matched bool) { return } -// // TrackerError reports an error stemming from the Hub being unable // to communicate with an external issue tracker. type TrackerError struct { @@ -65,7 +63,6 @@ func (r *TrackerError) Is(err error) (matched bool) { return } -// // Forbidden reports auth errors. type Forbidden struct { Reason string @@ -80,7 +77,6 @@ func (r *Forbidden) Is(err error) (matched bool) { return } -// // ErrorHandler handles error conditions from lower handlers. func ErrorHandler() gin.HandlerFunc { return func(ctx *gin.Context) { diff --git a/api/file.go b/api/file.go index 6f907f793..827cc8a68 100644 --- a/api/file.go +++ b/api/file.go @@ -1,30 +1,28 @@ package api import ( - "github.com/gin-gonic/gin" - "github.com/konveyor/tackle2-hub/model" "io" "mime" "net/http" "os" pathlib "path" "time" + + "github.com/gin-gonic/gin" + "github.com/konveyor/tackle2-hub/model" ) -// // Routes const ( FilesRoot = "/files" FileRoot = FilesRoot + "/:" + ID ) -// // FileHandler handles file routes. type FileHandler struct { BaseHandler } -// // AddRoutes adds routes. func (h FileHandler) AddRoutes(e *gin.Engine) { routeGroup := e.Group("/") @@ -242,7 +240,6 @@ func (h FileHandler) Delete(ctx *gin.Context) { h.Status(ctx, http.StatusNoContent) } -// // File REST resource. type File struct { Resource `yaml:",inline"` @@ -251,7 +248,6 @@ type File struct { Expiration *time.Time `json:"expiration,omitempty"` } -// // With updates the resource with the model. func (r *File) With(m *model.File) { r.Resource.With(&m.Model) diff --git a/api/filter/error.go b/api/filter/error.go index 69887e227..105a2756b 100644 --- a/api/filter/error.go +++ b/api/filter/error.go @@ -2,7 +2,6 @@ package filter import "fmt" -// // Error reports bad request errors. type Error struct { Reason string @@ -17,7 +16,6 @@ func (r *Error) Is(err error) (matched bool) { return } -// // Errorf build error. func Errorf(s string, v ...interface{}) (err error) { err = &Error{fmt.Sprintf(s, v...)} diff --git a/api/filter/filter.go b/api/filter/filter.go index 181df8c6a..94d1fcdf9 100644 --- a/api/filter/filter.go +++ b/api/filter/filter.go @@ -1,17 +1,17 @@ package filter import ( - "github.com/gin-gonic/gin" - "gorm.io/gorm" "strconv" "strings" + + "github.com/gin-gonic/gin" + "gorm.io/gorm" ) const ( QueryParam = "filter" ) -// // New filter. func New(ctx *gin.Context, assertions []Assert) (f Filter, err error) { p := Parser{} @@ -26,13 +26,11 @@ func New(ctx *gin.Context, assertions []Assert) (f Filter, err error) { return } -// // Filter is a collection of predicates. type Filter struct { predicates []Predicate } -// // Validate - func (f *Filter) Validate(assertions []Assert) (err error) { if len(assertions) == 0 { @@ -65,7 +63,6 @@ func (f *Filter) Validate(assertions []Assert) (err error) { return } -// // Field returns a field. func (f *Filter) Field(name string) (field Field, found bool) { fields := f.Fields(name) @@ -76,7 +73,6 @@ func (f *Filter) Field(name string) (field Field, found bool) { return } -// // Fields returns fields. func (f *Filter) Fields(name string) (fields []Field) { name = strings.ToLower(name) @@ -89,7 +85,6 @@ func (f *Filter) Fields(name string) (fields []Field) { return } -// // Resource returns a filter scoped to resource. func (f *Filter) Resource(r string) (filter Filter) { r = strings.ToLower(r) @@ -107,7 +102,6 @@ func (f *Filter) Resource(r string) (filter Filter) { return } -// // Where applies (root) fields to the where clause. func (f *Filter) Where(in *gorm.DB, selector ...string) (out *gorm.DB) { out = in @@ -121,7 +115,6 @@ func (f *Filter) Where(in *gorm.DB, selector ...string) (out *gorm.DB) { return } -// // With return filter with selected predicates. func (f *Filter) With(selector ...string) (out Filter) { fs := FieldSelector(selector) @@ -134,7 +127,6 @@ func (f *Filter) With(selector ...string) (out Filter) { return } -// // Delete specified fields. func (f *Filter) Delete(name string) (found bool) { var wanted []Predicate @@ -149,13 +141,11 @@ func (f *Filter) Delete(name string) (found bool) { return } -// // Empty returns true when the filter has no predicates. func (f *Filter) Empty() bool { return len(f.predicates) == 0 } -// // FieldSelector fields. // fields with '+' prefix are included. // fields with '-' prefix are excluded. @@ -163,7 +153,6 @@ func (f *Filter) Empty() bool { // An empty selector includes ALL. type FieldSelector []string -// // Match fields by qualified name. func (r FieldSelector) Match(f *Field) (m bool) { if f.Resource() != "" { @@ -200,20 +189,17 @@ func (r FieldSelector) Match(f *Field) (m bool) { return } -// // Field predicate. type Field struct { Predicate } -// // Name returns the field name. func (f *Field) Name() (s string) { _, s = f.split() return } -// // As returns the renamed field. func (f *Field) As(s string) (named Field) { named = Field{f.Predicate} @@ -221,14 +207,12 @@ func (f *Field) As(s string) (named Field) { return } -// // Resource returns the field resource. func (f *Field) Resource() (s string) { s, _ = f.split() return } -// // Where updates the where clause. func (f *Field) Where(in *gorm.DB) (out *gorm.DB) { sql, values := f.SQL() @@ -236,7 +220,6 @@ func (f *Field) Where(in *gorm.DB) (out *gorm.DB) { return } -// // SQL builds SQL. // Returns statement and values (for ?). func (f *Field) SQL() (s string, vList []interface{}) { @@ -301,7 +284,6 @@ func (f *Field) SQL() (s string, vList []interface{}) { return } -// // Expand flattens a multi-value field and returns a Field for each value. func (f *Field) Expand() (expanded []Field) { for _, v := range f.Value.ByKind(LITERAL, STRING) { @@ -317,7 +299,6 @@ func (f *Field) Expand() (expanded []Field) { return } -// // split field name. // format: resource.name // The resource may be "" (anonymous). @@ -333,7 +314,6 @@ func (f *Field) split() (relation string, name string) { return } -// // operator returns SQL operator. func (f *Field) operator() (s string) { switch len(f.Value) { @@ -352,7 +332,6 @@ func (f *Field) operator() (s string) { return } -// // Assert - type Assert struct { Field string @@ -360,7 +339,6 @@ type Assert struct { And bool } -// // assert validation. func (r *Assert) assert(p *Predicate) (err error) { name := p.Field.Value @@ -381,7 +359,6 @@ func (r *Assert) assert(p *Predicate) (err error) { return } -// // AsValue returns the real value. func AsValue(t Token) (object interface{}) { v := t.Value diff --git a/api/filter/filter_test.go b/api/filter/filter_test.go index 09def2252..03ecad85e 100644 --- a/api/filter/filter_test.go +++ b/api/filter/filter_test.go @@ -1,8 +1,9 @@ package filter import ( - "github.com/onsi/gomega" "testing" + + "github.com/onsi/gomega" ) func TestLexer(t *testing.T) { diff --git a/api/filter/lexer.go b/api/filter/lexer.go index 5091c7e54..8aafef5f0 100644 --- a/api/filter/lexer.go +++ b/api/filter/lexer.go @@ -25,14 +25,12 @@ const ( OPERATOR = 0x03 ) -// // Lexer token reader. type Lexer struct { tokens []Token index int } -// // With builds with the specified filter. func (r *Lexer) With(filter string) (err error) { reader := Reader{input: filter} @@ -100,7 +98,6 @@ func (r *Lexer) With(filter string) (err error) { return } -// // next returns the next token. func (r *Lexer) next() (token Token, next bool) { if r.index < len(r.tokens) { @@ -111,7 +108,6 @@ func (r *Lexer) next() (token Token, next bool) { return } -// // Put rewinds the lexer by 1 token. func (r *Lexer) put() { if r.index > 0 { @@ -119,21 +115,18 @@ func (r *Lexer) put() { } } -// // Token scanned token. type Token struct { Kind byte Value string } -// // Reader scan the input. type Reader struct { input string index int } -// // Next character. // Returns 0 at EOF. func (r *Reader) next() (ch byte) { @@ -144,7 +137,6 @@ func (r *Reader) next() (ch byte) { return } -// // Put rewinds one character. func (r *Reader) put() { if r.index > 0 { @@ -152,13 +144,11 @@ func (r *Reader) put() { } } -// // Quoted string token reader. type Quoted struct { *Reader } -// // Read token. func (q *Quoted) Read() (token Token, err error) { lastCh := byte(0) @@ -185,13 +175,11 @@ func (q *Quoted) Read() (token Token, err error) { return } -// // Operator token reader. type Operator struct { *Reader } -// // Read token. func (q *Operator) Read() (token Token, err error) { var bfr []byte diff --git a/api/filter/parser.go b/api/filter/parser.go index 9f2fb5def..5bde583ef 100644 --- a/api/filter/parser.go +++ b/api/filter/parser.go @@ -2,12 +2,10 @@ package filter import "math" -// // Parser used to parse the filter. type Parser struct { } -// // Filter parses the filter and builds a Filter. func (r *Parser) Filter(filter string) (f Filter, err error) { if filter == "" { @@ -67,7 +65,6 @@ func (r *Parser) Filter(filter string) (f Filter, err error) { return } -// // Predicate filter predicate. type Predicate struct { Unused Token @@ -76,11 +73,9 @@ type Predicate struct { Value Value } -// // Value term value. type Value []Token -// // ByKind returns values by kind. func (r Value) ByKind(kind ...byte) (matched []Token) { for _, t := range r { @@ -93,7 +88,6 @@ func (r Value) ByKind(kind ...byte) (matched []Token) { return } -// // Operator returns true when contains the specified operator. func (r *Value) Operator(operator byte) (matched bool) { operators := r.ByKind(OPERATOR) @@ -103,14 +97,12 @@ func (r *Value) Operator(operator byte) (matched bool) { return } -// // List construct. // Example: (red|blue|green) type List struct { *Lexer } -// // Build the value. func (r *List) Build() (v Value, err error) { for { @@ -145,7 +137,6 @@ func (r *List) Build() (v Value, err error) { return } -// // validate the result. func (r *List) validate(v Value) (err error) { lastOp := byte(0) diff --git a/api/group.go b/api/group.go index 5d0438ed0..4e92337b3 100644 --- a/api/group.go +++ b/api/group.go @@ -1,26 +1,24 @@ package api import ( + "net/http" + "github.com/gin-gonic/gin" "github.com/konveyor/tackle2-hub/model" "gorm.io/gorm/clause" - "net/http" ) -// // Routes const ( StakeholderGroupsRoot = "/stakeholdergroups" StakeholderGroupRoot = StakeholderGroupsRoot + "/:" + ID ) -// // StakeholderGroupHandler handles stakeholder group routes. type StakeholderGroupHandler struct { BaseHandler } -// // AddRoutes adds routes. func (h StakeholderGroupHandler) AddRoutes(e *gin.Engine) { routeGroup := e.Group("/") @@ -176,7 +174,6 @@ func (h StakeholderGroupHandler) Update(ctx *gin.Context) { h.Status(ctx, http.StatusNoContent) } -// // StakeholderGroup REST resource. type StakeholderGroup struct { Resource `yaml:",inline"` @@ -186,7 +183,6 @@ type StakeholderGroup struct { MigrationWaves []Ref `json:"migrationWaves" yaml:"migrationWaves"` } -// // With updates the resource with the model. func (r *StakeholderGroup) With(m *model.StakeholderGroup) { r.Resource.With(&m.Model) @@ -206,7 +202,6 @@ func (r *StakeholderGroup) With(m *model.StakeholderGroup) { } } -// // Model builds a model. func (r *StakeholderGroup) Model() (m *model.StakeholderGroup) { m = &model.StakeholderGroup{ diff --git a/api/identity.go b/api/identity.go index f429f484b..39cfd1e2f 100644 --- a/api/identity.go +++ b/api/identity.go @@ -1,27 +1,25 @@ package api import ( - "github.com/gin-gonic/gin" - "github.com/konveyor/tackle2-hub/model" "net/http" "strconv" + + "github.com/gin-gonic/gin" + "github.com/konveyor/tackle2-hub/model" ) -// // Routes const ( IdentitiesRoot = "/identities" IdentityRoot = IdentitiesRoot + "/:" + ID ) -// // Params. const ( Decrypted = "decrypted" AppId = "application" ) -// // IdentityHandler handles identity resource routes. type IdentityHandler struct { BaseHandler @@ -211,7 +209,6 @@ func (h IdentityHandler) Update(ctx *gin.Context) { h.Status(ctx, http.StatusNoContent) } -// // Set `decrypted` in the context. // Results in 403 when the token does not have the required scope. func (h *IdentityHandler) setDecrypted(ctx *gin.Context) { @@ -228,7 +225,6 @@ func (h *IdentityHandler) setDecrypted(ctx *gin.Context) { return } -// // Identity REST resource. type Identity struct { Resource `yaml:",inline"` @@ -241,7 +237,6 @@ type Identity struct { Settings string `json:"settings"` } -// // With updates the resource with the model. func (r *Identity) With(m *model.Identity) { r.Resource.With(&m.Model) @@ -254,7 +249,6 @@ func (r *Identity) With(m *model.Identity) { r.Settings = m.Settings } -// // Model builds a model. func (r *Identity) Model() (m *model.Identity) { m = &model.Identity{ diff --git a/api/import.go b/api/import.go index 3b8fe19a0..53a6d445d 100644 --- a/api/import.go +++ b/api/import.go @@ -3,15 +3,15 @@ package api import ( "bytes" "encoding/csv" - "github.com/gin-gonic/gin" - "github.com/konveyor/tackle2-hub/model" "io" "net/http" "strconv" "time" + + "github.com/gin-gonic/gin" + "github.com/konveyor/tackle2-hub/model" ) -// // Record types const ( RecordTypeApplication = "1" @@ -22,14 +22,12 @@ const ( ExpectedFieldCount = 17 ) -// // Import Statuses const ( InProgress = "In Progress" Completed = "Completed" ) -// // Routes const ( SummariesRoot = "/importsummaries" @@ -40,13 +38,11 @@ const ( ImportRoot = ImportsRoot + "/:" + ID ) -// // ImportHandler handles import routes. type ImportHandler struct { BaseHandler } -// // AddRoutes adds routes. func (h ImportHandler) AddRoutes(e *gin.Engine) { routeGroup := e.Group("/") @@ -63,7 +59,6 @@ func (h ImportHandler) AddRoutes(e *gin.Engine) { routeGroup.POST(UploadRoot, h.UploadCSV) } -// // GetImport godoc // @summary Get an import by ID. // @description Get an import by ID. @@ -84,7 +79,6 @@ func (h ImportHandler) GetImport(ctx *gin.Context) { h.Respond(ctx, http.StatusOK, m.AsMap()) } -// // ListImports godoc // @summary List imports. // @description List imports. @@ -119,7 +113,6 @@ func (h ImportHandler) ListImports(ctx *gin.Context) { h.Respond(ctx, http.StatusOK, resources) } -// // DeleteImport godoc // @summary Delete an import. // @description Delete an import. This leaves any created application or dependency. @@ -138,7 +131,6 @@ func (h ImportHandler) DeleteImport(ctx *gin.Context) { h.Status(ctx, http.StatusNoContent) } -// // GetSummary godoc // @summary Get an import summary by ID. // @description Get an import by ID. @@ -159,7 +151,6 @@ func (h ImportHandler) GetSummary(ctx *gin.Context) { h.Respond(ctx, http.StatusOK, m) } -// // ListSummaries godoc // @summary List import summaries. // @description List import summaries. @@ -185,7 +176,6 @@ func (h ImportHandler) ListSummaries(ctx *gin.Context) { h.Respond(ctx, http.StatusOK, resources) } -// // DeleteSummary godoc // @summary Delete an import summary and associated import records. // @description Delete an import summary and associated import records. @@ -204,7 +194,6 @@ func (h ImportHandler) DeleteSummary(ctx *gin.Context) { h.Status(ctx, http.StatusNoContent) } -// // UploadCSV godoc // @summary Upload a CSV containing applications and dependencies to import. // @description Upload a CSV containing applications and dependencies to import. @@ -301,7 +290,6 @@ func (h ImportHandler) UploadCSV(ctx *gin.Context) { h.Respond(ctx, http.StatusCreated, summary) } -// // DownloadCSV godoc // @summary Export the source CSV for a particular import summary. // @description Export the source CSV for a particular import summary. @@ -322,13 +310,14 @@ func (h ImportHandler) DownloadCSV(ctx *gin.Context) { ctx.Data(http.StatusOK, "text/csv", m.Content) } -// // CSV upload supports two types of records in the same file: application imports, and dependencies. // A dependency row must consist of the following columns: // // Col 1: Record Type 1 -- This will always contain a "2" for a dependency // Col 2: Application Name -- The name of the application that has the dependency relationship. -// This application must exist. +// +// This application must exist. +// // Col 6: Dependency -- The name of the application on the other side of the dependency relationship. // Col 7: Dependency Direction -- Whether this is a "northbound" or "southbound" dependency. // @@ -350,7 +339,6 @@ func (h ImportHandler) dependencyFromRow(fileName string, row []string) (app mod return } -// // CSV upload supports two types of records in the same file: application imports, and dependencies. // An application row must consist of the following columns: // @@ -359,7 +347,9 @@ func (h ImportHandler) dependencyFromRow(fileName string, row []string) (app mod // Col 3: Description -- A short description of the application. // Col 4: Comments -- Additional comments on the application. // Col 5: Business Service -- The name of the business service this Application should belong to. -// This business service must already exist. +// +// This business service must already exist. +// // Col 6: Dependency -- Optional dependency to another Application (by name) // Col 7: Dependency direction -- Either northbound or southbound // @@ -418,11 +408,9 @@ func (h ImportHandler) applicationFromRow(fileName string, row []string) (app mo return } -// // Import REST resource. type Import map[string]interface{} -// // ImportSummary REST resource. type ImportSummary struct { Resource `yaml:",inline"` @@ -434,7 +422,6 @@ type ImportSummary struct { CreateEntities bool `json:"createEntities" yaml:"createEntities"` } -// // With updates the resource with the model. func (r *ImportSummary) With(m *model.ImportSummary) { r.Resource.With(&m.Model) diff --git a/api/jobfunction.go b/api/jobfunction.go index 6458b75ab..82e615956 100644 --- a/api/jobfunction.go +++ b/api/jobfunction.go @@ -1,26 +1,24 @@ package api import ( + "net/http" + "github.com/gin-gonic/gin" "github.com/konveyor/tackle2-hub/model" "gorm.io/gorm/clause" - "net/http" ) -// // Routes const ( JobFunctionsRoot = "/jobfunctions" JobFunctionRoot = JobFunctionsRoot + "/:" + ID ) -// // JobFunctionHandler handles job-function routes. type JobFunctionHandler struct { BaseHandler } -// // AddRoutes adds routes. func (h JobFunctionHandler) AddRoutes(e *gin.Engine) { routeGroup := e.Group("/") @@ -164,7 +162,6 @@ func (h JobFunctionHandler) Update(ctx *gin.Context) { h.Status(ctx, http.StatusNoContent) } -// // JobFunction REST resource. type JobFunction struct { Resource `yaml:",inline"` @@ -172,7 +169,6 @@ type JobFunction struct { Stakeholders []Ref `json:"stakeholders"` } -// // With updates the resource with the model. func (r *JobFunction) With(m *model.JobFunction) { r.Resource.With(&m.Model) @@ -184,7 +180,6 @@ func (r *JobFunction) With(m *model.JobFunction) { } } -// // Model builds a model. func (r *JobFunction) Model() (m *model.JobFunction) { m = &model.JobFunction{ diff --git a/api/metric.go b/api/metric.go index 4774b68b6..eb576b027 100644 --- a/api/metric.go +++ b/api/metric.go @@ -1,8 +1,9 @@ package api import ( - "github.com/prometheus/client_golang/prometheus/promhttp" "net/http" + + "github.com/prometheus/client_golang/prometheus/promhttp" ) // MetricsHandler godoc diff --git a/api/migrationwave.go b/api/migrationwave.go index a2290d8bc..24835e5e9 100644 --- a/api/migrationwave.go +++ b/api/migrationwave.go @@ -1,27 +1,25 @@ package api import ( + "net/http" + "time" + "github.com/gin-gonic/gin" "github.com/konveyor/tackle2-hub/model" "gorm.io/gorm/clause" - "net/http" - "time" ) -// // Routes const ( MigrationWavesRoot = "/migrationwaves" MigrationWaveRoot = MigrationWavesRoot + "/:" + ID ) -// // MigrationWaveHandler handles Migration Wave resource routes. type MigrationWaveHandler struct { BaseHandler } -// // AddRoutes adds routes. func (h MigrationWaveHandler) AddRoutes(e *gin.Engine) { routeGroup := e.Group("/") @@ -180,7 +178,6 @@ func (h MigrationWaveHandler) Delete(ctx *gin.Context) { h.Status(ctx, http.StatusNoContent) } -// // MigrationWave REST Resource type MigrationWave struct { Resource `yaml:",inline"` @@ -192,7 +189,6 @@ type MigrationWave struct { StakeholderGroups []Ref `json:"stakeholderGroups" yaml:"stakeholderGroups"` } -// // With updates the resource using the model. func (r *MigrationWave) With(m *model.MigrationWave) { r.Resource.With(&m.Model) @@ -219,7 +215,6 @@ func (r *MigrationWave) With(m *model.MigrationWave) { } } -// // Model builds a model. func (r *MigrationWave) Model() (m *model.MigrationWave) { m = &model.MigrationWave{ diff --git a/api/pkg.go b/api/pkg.go index f1a0a0cb8..36f78c052 100644 --- a/api/pkg.go +++ b/api/pkg.go @@ -23,7 +23,6 @@ var ( log = logr.WithName("api") ) -// // Params const ( ID = "id" @@ -35,7 +34,6 @@ const ( FileField = "file" ) -// // Headers const ( Accept = "Accept" @@ -46,25 +44,21 @@ const ( Total = "X-Total" ) -// // MIME Types. const ( MIMEOCTETSTREAM = "application/octet-stream" TAR = "application/x-tar" ) -// // BindMIMEs supported binding MIME types. var BindMIMEs = []string{binding.MIMEJSON, binding.MIMEYAML} -// // Header Values const ( DirectoryArchive = "archive" DirectoryExpand = "expand" ) -// // All builds all handlers. func All() []Handler { return []Handler{ @@ -103,7 +97,6 @@ func All() []Handler { } } -// // Handler API. type Handler interface { AddRoutes(e *gin.Engine) diff --git a/api/proxy.go b/api/proxy.go index 4c5ffdd57..72f3dd67b 100644 --- a/api/proxy.go +++ b/api/proxy.go @@ -2,13 +2,13 @@ package api import ( "encoding/json" + "net/http" + "github.com/gin-gonic/gin" "github.com/konveyor/tackle2-hub/model" "gorm.io/gorm/clause" - "net/http" ) -// // Routes const ( ProxiesRoot = "/proxies" @@ -19,7 +19,6 @@ const ( Kind = "kind" ) -// // ProxyHandler handles proxy resource routes. type ProxyHandler struct { BaseHandler @@ -171,7 +170,6 @@ func (h ProxyHandler) Update(ctx *gin.Context) { h.Status(ctx, http.StatusNoContent) } -// // Proxy REST resource. type Proxy struct { Resource `yaml:",inline"` @@ -183,7 +181,6 @@ type Proxy struct { Identity *Ref `json:"identity"` } -// // With updates the resource with the model. func (r *Proxy) With(m *model.Proxy) { r.Resource.With(&m.Model) @@ -198,7 +195,6 @@ func (r *Proxy) With(m *model.Proxy) { } } -// // Model builds a model. func (r *Proxy) Model() (m *model.Proxy) { m = &model.Proxy{ diff --git a/api/reflect/fields.go b/api/reflect/fields.go index 2d3de7877..f89c21764 100644 --- a/api/reflect/fields.go +++ b/api/reflect/fields.go @@ -5,7 +5,6 @@ import ( "time" ) -// // Fields returns a map of fields. func Fields(m interface{}) (mp map[string]interface{}) { var inspect func(r interface{}) @@ -61,7 +60,6 @@ func Fields(m interface{}) (mp map[string]interface{}) { return } -// // NameOf returns the name of a model. func NameOf(m interface{}) (name string) { mt := reflect.TypeOf(m) diff --git a/api/review.go b/api/review.go index 80cc3a1f8..85fbbdcb8 100644 --- a/api/review.go +++ b/api/review.go @@ -1,13 +1,13 @@ package api import ( + "net/http" + "github.com/gin-gonic/gin" "github.com/konveyor/tackle2-hub/model" "gorm.io/gorm/clause" - "net/http" ) -// // Routes const ( ReviewsRoot = "/reviews" @@ -15,13 +15,11 @@ const ( CopyRoot = ReviewsRoot + "/copy" ) -// // ReviewHandler handles review routes. type ReviewHandler struct { BaseHandler } -// // AddRoutes adds routes. func (h ReviewHandler) AddRoutes(e *gin.Engine) { routeGroup := e.Group("/") @@ -221,7 +219,6 @@ func (h ReviewHandler) CopyReview(ctx *gin.Context) { h.Status(ctx, http.StatusNoContent) } -// // Review REST resource. type Review struct { Resource `yaml:",inline"` @@ -246,7 +243,6 @@ func (r *Review) With(m *model.Review) { r.Archetype = r.refPtr(m.ArchetypeID, m.Archetype) } -// // Model builds a model. func (r *Review) Model() (m *model.Review) { m = &model.Review{ @@ -265,7 +261,6 @@ func (r *Review) Model() (m *model.Review) { return } -// // CopyRequest REST resource. type CopyRequest struct { SourceReview uint `json:"sourceReview" binding:"required"` diff --git a/api/ruleset.go b/api/ruleset.go index 051b843a0..95bfabb58 100644 --- a/api/ruleset.go +++ b/api/ruleset.go @@ -2,22 +2,21 @@ package api import ( "encoding/json" + "net/http" + "github.com/gin-gonic/gin" qf "github.com/konveyor/tackle2-hub/api/filter" "github.com/konveyor/tackle2-hub/model" "gorm.io/gorm" "gorm.io/gorm/clause" - "net/http" ) -// // Routes const ( RuleSetsRoot = "/rulesets" RuleSetRoot = RuleSetsRoot + "/:" + ID ) -// // RuleSetHandler handles ruleset resource routes. type RuleSetHandler struct { BaseHandler @@ -202,7 +201,6 @@ func (h *RuleSetHandler) ruleSetIDs(ctx *gin.Context, f qf.Filter) (q *gorm.DB) return } -// // create the ruleset. func (h *RuleSetHandler) create(ctx *gin.Context, r *RuleSet) (err error) { m := r.Model() @@ -222,7 +220,6 @@ func (h *RuleSetHandler) create(ctx *gin.Context, r *RuleSet) (err error) { return } -// // update the ruleset. func (h *RuleSetHandler) update(ctx *gin.Context, r *RuleSet) (err error) { m := &model.RuleSet{} @@ -279,7 +276,6 @@ func (h *RuleSetHandler) update(ctx *gin.Context, r *RuleSet) (err error) { return } -// // delete the ruleset. func (h *RuleSetHandler) delete(ctx *gin.Context, id uint) (err error) { ruleset := &model.RuleSet{} @@ -298,7 +294,6 @@ func (h *RuleSetHandler) delete(ctx *gin.Context, id uint) (err error) { return } -// // RuleSet REST resource. type RuleSet struct { Resource `yaml:",inline"` @@ -311,7 +306,6 @@ type RuleSet struct { DependsOn []Ref `json:"dependsOn" yaml:"dependsOn"` } -// // With updates the resource with the model. func (r *RuleSet) With(m *model.RuleSet) { r.Resource.With(&m.Model) @@ -336,7 +330,6 @@ func (r *RuleSet) With(m *model.RuleSet) { } } -// // Model builds a model. func (r *RuleSet) Model() (m *model.RuleSet) { m = &model.RuleSet{ @@ -365,7 +358,6 @@ func (r *RuleSet) Model() (m *model.RuleSet) { return } -// // HasRule - determine if the ruleset is referenced. func (r *RuleSet) HasRule(id uint) (b bool) { for _, ruleset := range r.Rules { @@ -377,7 +369,6 @@ func (r *RuleSet) HasRule(id uint) (b bool) { return } -// // Rule - REST Resource. type Rule struct { Resource `yaml:",inline"` @@ -387,7 +378,6 @@ type Rule struct { File *Ref `json:"file,omitempty"` } -// // With updates the resource with the model. func (r *Rule) With(m *model.Rule) { r.Resource.With(&m.Model) @@ -396,7 +386,6 @@ func (r *Rule) With(m *model.Rule) { r.File = r.refPtr(m.FileID, m.File) } -// // Model builds a model. func (r *Rule) Model() (m *model.Rule) { m = &model.Rule{} diff --git a/api/schema.go b/api/schema.go index 6ce04048a..3c02423f1 100644 --- a/api/schema.go +++ b/api/schema.go @@ -1,11 +1,11 @@ package api import ( - "github.com/gin-gonic/gin" "net/http" + + "github.com/gin-gonic/gin" ) -// // SchemaHandler providers schema (route) handler. type SchemaHandler struct { BaseHandler @@ -15,7 +15,6 @@ type SchemaHandler struct { Version string } -// // AddRoutes Adds routes. func (h *SchemaHandler) AddRoutes(r *gin.Engine) { h.router = r diff --git a/api/setting.go b/api/setting.go index f21f5bb82..ab35709c2 100644 --- a/api/setting.go +++ b/api/setting.go @@ -3,26 +3,24 @@ package api import ( "encoding/json" "fmt" - "github.com/gin-gonic/gin" - "github.com/konveyor/tackle2-hub/model" "net/http" "strings" + + "github.com/gin-gonic/gin" + "github.com/konveyor/tackle2-hub/model" ) -// // Routes const ( SettingsRoot = "/settings" SettingRoot = SettingsRoot + "/:" + Key ) -// // SettingHandler handles setting routes. type SettingHandler struct { BaseHandler } -// // AddRoutes add routes. func (h SettingHandler) AddRoutes(e *gin.Engine) { routeGroup := e.Group("/") @@ -229,7 +227,6 @@ func (h SettingHandler) Delete(ctx *gin.Context) { h.Status(ctx, http.StatusNoContent) } -// // Setting REST Resource type Setting struct { Key string `json:"key"` diff --git a/api/sort/error.go b/api/sort/error.go index 8288edeac..15fd4c724 100644 --- a/api/sort/error.go +++ b/api/sort/error.go @@ -2,7 +2,6 @@ package sort import "fmt" -// // SortError reports sorting error. type SortError struct { field string diff --git a/api/sort/sort.go b/api/sort/sort.go index a76fe76de..08d93e81b 100644 --- a/api/sort/sort.go +++ b/api/sort/sort.go @@ -1,27 +1,25 @@ package sort import ( + "strings" + "github.com/gin-gonic/gin" "github.com/konveyor/tackle2-hub/api/reflect" "gorm.io/gorm" - "strings" ) -// // Clause sort clause. type Clause struct { direction string name string } -// // Sort provides sorting. type Sort struct { fields map[string]interface{} clauses []Clause } -// // With context. func (r *Sort) With(ctx *gin.Context, m interface{}) (err error) { param := ctx.Query("sort") @@ -66,7 +64,6 @@ func (r *Sort) With(ctx *gin.Context, m interface{}) (err error) { return } -// // Sorted returns sorted DB. func (r *Sort) Sorted(in *gorm.DB) (out *gorm.DB) { out = in @@ -81,7 +78,6 @@ func (r *Sort) Sorted(in *gorm.DB) (out *gorm.DB) { return } -// // inspect object and return fields. func (r *Sort) inspect(m interface{}) (fields map[string]interface{}) { fields = reflect.Fields(m) diff --git a/api/stakeholder.go b/api/stakeholder.go index 12b707c5c..4cb659310 100644 --- a/api/stakeholder.go +++ b/api/stakeholder.go @@ -1,26 +1,24 @@ package api import ( + "net/http" + "github.com/gin-gonic/gin" "github.com/konveyor/tackle2-hub/model" "gorm.io/gorm/clause" - "net/http" ) -// // Routes const ( StakeholdersRoot = "/stakeholders" StakeholderRoot = StakeholdersRoot + "/:" + ID ) -// // StakeholderHandler handles stakeholder routes. type StakeholderHandler struct { BaseHandler } -// // AddRoutes adds routes. func (h StakeholderHandler) AddRoutes(e *gin.Engine) { routeGroup := e.Group("/") @@ -187,7 +185,6 @@ func (h StakeholderHandler) Update(ctx *gin.Context) { h.Status(ctx, http.StatusNoContent) } -// // Stakeholder REST resource. type Stakeholder struct { Resource `yaml:",inline"` @@ -201,7 +198,6 @@ type Stakeholder struct { MigrationWaves []Ref `json:"migrationWaves" yaml:"migrationWaves"` } -// // With updates the resource with the model. func (r *Stakeholder) With(m *model.Stakeholder) { r.Resource.With(&m.Model) @@ -240,7 +236,6 @@ func (r *Stakeholder) With(m *model.Stakeholder) { } } -// // Model builds a model. func (r *Stakeholder) Model() (m *model.Stakeholder) { m = &model.Stakeholder{ diff --git a/api/tag.go b/api/tag.go index fff043fde..17d472444 100644 --- a/api/tag.go +++ b/api/tag.go @@ -1,26 +1,24 @@ package api import ( + "net/http" + "github.com/gin-gonic/gin" "github.com/konveyor/tackle2-hub/model" "gorm.io/gorm/clause" - "net/http" ) -// // Routes const ( TagsRoot = "/tags" TagRoot = TagsRoot + "/:" + ID ) -// // TagHandler handles tag routes. type TagHandler struct { BaseHandler } -// // AddRoutes adds routes. func (h TagHandler) AddRoutes(e *gin.Engine) { routeGroup := e.Group("/") @@ -164,7 +162,6 @@ func (h TagHandler) Update(ctx *gin.Context) { h.Status(ctx, http.StatusNoContent) } -// // Tag REST resource. type Tag struct { Resource `yaml:",inline"` @@ -172,7 +169,6 @@ type Tag struct { Category Ref `json:"category" binding:"required"` } -// // With updates the resource with the model. func (r *Tag) With(m *model.Tag) { r.Resource.With(&m.Model) @@ -180,7 +176,6 @@ func (r *Tag) With(m *model.Tag) { r.Category = r.ref(m.CategoryID, &m.Category) } -// // Model builds a model. func (r *Tag) Model() (m *model.Tag) { m = &model.Tag{ diff --git a/api/tagcategory.go b/api/tagcategory.go index 03bd7be08..8ae7799b2 100644 --- a/api/tagcategory.go +++ b/api/tagcategory.go @@ -1,13 +1,13 @@ package api import ( + "net/http" + "github.com/gin-gonic/gin" "github.com/konveyor/tackle2-hub/model" "gorm.io/gorm/clause" - "net/http" ) -// // Routes const ( TagCategoriesRoot = "/tagcategories" @@ -15,13 +15,11 @@ const ( TagCategoryTagsRoot = TagCategoryRoot + "/tags" ) -// // TagCategoryHandler handles the tag-type route. type TagCategoryHandler struct { BaseHandler } -// // AddRoutes adds routes. func (h TagCategoryHandler) AddRoutes(e *gin.Engine) { routeGroup := e.Group("/") @@ -209,7 +207,6 @@ func (h TagCategoryHandler) TagList(ctx *gin.Context) { ctx.JSON(http.StatusOK, resources) } -// // TagCategory REST resource. type TagCategory struct { Resource `yaml:",inline"` @@ -220,7 +217,6 @@ type TagCategory struct { Tags []Ref `json:"tags"` } -// // With updates the resource with the model. func (r *TagCategory) With(m *model.TagCategory) { r.Resource.With(&m.Model) @@ -236,7 +232,6 @@ func (r *TagCategory) With(m *model.TagCategory) { } } -// // Model builds a model. func (r *TagCategory) Model() (m *model.TagCategory) { m = &model.TagCategory{ diff --git a/api/target.go b/api/target.go index c99ea4ab0..efccc4d10 100644 --- a/api/target.go +++ b/api/target.go @@ -4,22 +4,21 @@ import ( "encoding/json" "errors" "fmt" + "net/http" + "github.com/gin-gonic/gin" uuid2 "github.com/google/uuid" "github.com/konveyor/tackle2-hub/model" "gorm.io/gorm" "gorm.io/gorm/clause" - "net/http" ) -// // Routes const ( TargetsRoot = "/targets" TargetRoot = TargetsRoot + "/:" + ID ) -// // TargetHandler handles Target resource routes. type TargetHandler struct { BaseHandler @@ -235,7 +234,6 @@ func (h TargetHandler) Update(ctx *gin.Context) { h.Status(ctx, http.StatusNoContent) } -// // Target REST resource. type Target struct { Resource `yaml:",inline"` @@ -254,7 +252,6 @@ type Label struct { Label string `json:"label"` } -// // With updates the resource with the model. func (r *Target) With(m *model.Target) { r.Resource.With(&m.Model) @@ -275,7 +272,6 @@ func (r *Target) With(m *model.Target) { _ = json.Unmarshal(m.Labels, &r.Labels) } -// // Model builds a model. func (r *Target) Model() (m *model.Target) { m = &model.Target{ diff --git a/api/task.go b/api/task.go index ea986f556..ef20cef6e 100644 --- a/api/task.go +++ b/api/task.go @@ -2,22 +2,22 @@ package api import ( "encoding/json" + "io/ioutil" + "net/http" + "sort" + "strconv" + "strings" + "time" + "github.com/gin-gonic/gin" "github.com/konveyor/tackle2-hub/model" tasking "github.com/konveyor/tackle2-hub/task" "gorm.io/gorm" "gorm.io/gorm/clause" - "io/ioutil" k8serr "k8s.io/apimachinery/pkg/api/errors" "k8s.io/utils/strings/slices" - "net/http" - "sort" - "strconv" - "strings" - "time" ) -// // Routes const ( TasksRoot = "/tasks" @@ -33,13 +33,11 @@ const ( LocatorParam = "locator" ) -// // TaskHandler handles task routes. type TaskHandler struct { BucketOwner } -// // AddRoutes adds routes. func (h TaskHandler) AddRoutes(e *gin.Engine) { routeGroup := e.Group("/") @@ -482,7 +480,6 @@ func (h TaskHandler) DeleteReport(ctx *gin.Context) { h.Status(ctx, http.StatusNoContent) } -// // Fields omitted by: // - Create // - Update. @@ -501,7 +498,6 @@ func (h *TaskHandler) omitted(db *gorm.DB) (out *gorm.DB) { return } -// // TTL time-to-live. type TTL struct { Created int `json:"created,omitempty"` @@ -512,14 +508,12 @@ type TTL struct { Failed int `json:"failed,omitempty"` } -// // TaskError used in Task.Errors. type TaskError struct { Severity string `json:"severity"` Description string `json:"description"` } -// // Task REST resource. type Task struct { Resource `yaml:",inline"` @@ -546,7 +540,6 @@ type Task struct { Attached []Attachment `json:"attached" yaml:",omitempty"` } -// // With updates the resource with the model. func (r *Task) With(m *model.Task) { r.Resource.With(&m.Model) @@ -588,7 +581,6 @@ func (r *Task) With(m *model.Task) { } } -// // Model builds a model. func (r *Task) Model() (m *model.Task) { m = &model.Task{ @@ -609,7 +601,6 @@ func (r *Task) Model() (m *model.Task) { return } -// // injectFiles inject attached files into the activity. func (r *Task) injectFiles(db *gorm.DB) (err error) { sort.Slice( @@ -649,7 +640,6 @@ func (r *Task) injectFiles(db *gorm.DB) (err error) { return } -// // TaskReport REST resource. type TaskReport struct { Resource `yaml:",inline"` @@ -663,7 +653,6 @@ type TaskReport struct { TaskID uint `json:"task"` } -// // With updates the resource with the model. func (r *TaskReport) With(m *model.TaskReport) { r.Resource.With(&m.Model) @@ -685,7 +674,6 @@ func (r *TaskReport) With(m *model.TaskReport) { } } -// // Model builds a model. func (r *TaskReport) Model() (m *model.TaskReport) { if r.Activity == nil { @@ -714,7 +702,6 @@ func (r *TaskReport) Model() (m *model.TaskReport) { return } -// // Attachment associates Files with a TaskReport. type Attachment struct { // Ref references an attached File. diff --git a/api/taskgroup.go b/api/taskgroup.go index c494743bd..04d936b5d 100644 --- a/api/taskgroup.go +++ b/api/taskgroup.go @@ -2,15 +2,15 @@ package api import ( "encoding/json" + "net/http" + "github.com/gin-gonic/gin" "github.com/konveyor/tackle2-hub/model" tasking "github.com/konveyor/tackle2-hub/task" "gorm.io/gorm/clause" k8serr "k8s.io/apimachinery/pkg/api/errors" - "net/http" ) -// // Routes const ( TaskGroupsRoot = "/taskgroups" @@ -20,13 +20,11 @@ const ( TaskGroupSubmitRoot = TaskGroupRoot + "/submit" ) -// // TaskGroupHandler handles task group routes. type TaskGroupHandler struct { BucketOwner } -// // AddRoutes adds routes. func (h TaskGroupHandler) AddRoutes(e *gin.Engine) { routeGroup := e.Group("/") @@ -354,7 +352,6 @@ func (h TaskGroupHandler) BucketDelete(ctx *gin.Context) { h.bucketDelete(ctx, *m.BucketID) } -// // TaskGroup REST resource. type TaskGroup struct { Resource `yaml:",inline"` @@ -366,7 +363,6 @@ type TaskGroup struct { Tasks []Task `json:"tasks"` } -// // With updates the resource with the model. func (r *TaskGroup) With(m *model.TaskGroup) { r.Resource.With(&m.Model) @@ -390,7 +386,6 @@ func (r *TaskGroup) With(m *model.TaskGroup) { } } -// // Model builds a model. func (r *TaskGroup) Model() (m *model.TaskGroup) { m = &model.TaskGroup{ diff --git a/api/ticket.go b/api/ticket.go index 4ec664bc1..d42617b02 100644 --- a/api/ticket.go +++ b/api/ticket.go @@ -2,11 +2,12 @@ package api import ( "encoding/json" + "net/http" + "time" + "github.com/gin-gonic/gin" "github.com/konveyor/tackle2-hub/model" "gorm.io/gorm/clause" - "net/http" - "time" ) // Routes diff --git a/api/tracker.go b/api/tracker.go index fa62013c4..650607bac 100644 --- a/api/tracker.go +++ b/api/tracker.go @@ -1,13 +1,14 @@ package api import ( + "net/http" + "strconv" + "time" + "github.com/gin-gonic/gin" "github.com/konveyor/tackle2-hub/model" "github.com/konveyor/tackle2-hub/tracker" "gorm.io/gorm/clause" - "net/http" - "strconv" - "time" ) // Routes @@ -350,28 +351,24 @@ func (r *Tracker) Model() (m *model.Tracker) { return } -// // Project API Resource type Project struct { ID string `json:"id"` Name string `json:"name"` } -// // With updates the resource with the model. func (r *Project) With(i *tracker.Project) { r.ID = i.ID r.Name = i.Name } -// // IssueType API Resource type IssueType struct { ID string `json:"id"` Name string `json:"name"` } -// // With updates the resource with the model. func (r *IssueType) With(i *tracker.IssueType) { r.ID = i.ID diff --git a/assessment/application.go b/assessment/application.go index 3600ea475..2335222e9 100644 --- a/assessment/application.go +++ b/assessment/application.go @@ -4,14 +4,12 @@ import ( "github.com/konveyor/tackle2-hub/model" ) -// // Application represents an Application with its assessments. type Application struct { *model.Application Assessments []Assessment } -// // With updates the Application with the db model and deserializes its assessments. func (r *Application) With(m *model.Application) { r.Application = m @@ -23,7 +21,6 @@ func (r *Application) With(m *model.Application) { } } -// // NewApplicationResolver creates a new ApplicationResolver from an application and other shared resolvers. func NewApplicationResolver(m *model.Application, tags *TagResolver, membership *MembershipResolver, questionnaire *QuestionnaireResolver) (a *ApplicationResolver) { a = &ApplicationResolver{ @@ -38,7 +35,6 @@ func NewApplicationResolver(m *model.Application, tags *TagResolver, membership return } -// // ApplicationResolver wraps an Application model // with archetype and assessment resolution behavior. type ApplicationResolver struct { @@ -49,7 +45,6 @@ type ApplicationResolver struct { questionnaireResolver *QuestionnaireResolver } -// // Archetypes returns the list of archetypes the application is a member of. func (r *ApplicationResolver) Archetypes() (archetypes []Archetype, err error) { if len(r.archetypes) > 0 { @@ -61,7 +56,6 @@ func (r *ApplicationResolver) Archetypes() (archetypes []Archetype, err error) { return } -// // ArchetypeTags returns the list of tags that the application should inherit from the archetypes it is a member of, // including any tags that would be inherited due to answers given to the archetypes' assessments. func (r *ApplicationResolver) ArchetypeTags() (tags []model.Tag, err error) { @@ -95,7 +89,6 @@ func (r *ApplicationResolver) ArchetypeTags() (tags []model.Tag, err error) { return } -// // RequiredAssessments returns the slice of assessments that are for required questionnaires. func (r *ApplicationResolver) RequiredAssessments() (required []Assessment) { for _, a := range r.application.Assessments { @@ -106,7 +99,6 @@ func (r *ApplicationResolver) RequiredAssessments() (required []Assessment) { return } -// // AssessmentTags returns the list of tags that the application should inherit from the answers given // to its assessments. func (r *ApplicationResolver) AssessmentTags() (tags []model.Tag) { @@ -123,7 +115,6 @@ func (r *ApplicationResolver) AssessmentTags() (tags []model.Tag) { return } -// // Risk returns the overall risk level for the application based on its or its archetypes' assessments. func (r *ApplicationResolver) Risk() (risk string, err error) { var assessments []Assessment @@ -148,7 +139,6 @@ func (r *ApplicationResolver) Risk() (risk string, err error) { return } -// // Confidence returns the application's overall assessment confidence score. func (r *ApplicationResolver) Confidence() (confidence int, err error) { var assessments []Assessment @@ -173,7 +163,6 @@ func (r *ApplicationResolver) Confidence() (confidence int, err error) { return } -// // Assessed returns whether the application has been fully assessed. func (r *ApplicationResolver) Assessed() (assessed bool, err error) { // if the application has any of its own assessments, only consider them for diff --git a/assessment/archetype.go b/assessment/archetype.go index 6ad51f245..cc905f1c7 100644 --- a/assessment/archetype.go +++ b/assessment/archetype.go @@ -2,14 +2,12 @@ package assessment import "github.com/konveyor/tackle2-hub/model" -// // Archetype represents an Archetype with its assessments. type Archetype struct { *model.Archetype Assessments []Assessment } -// // With updates the Archetype with the db model and deserializes its assessments. func (r *Archetype) With(m *model.Archetype) { r.Archetype = m @@ -21,7 +19,6 @@ func (r *Archetype) With(m *model.Archetype) { } } -// // NewArchetypeResolver creates a new ArchetypeResolver. func NewArchetypeResolver(m *model.Archetype, tags *TagResolver, membership *MembershipResolver, questionnaire *QuestionnaireResolver) (a *ArchetypeResolver) { a = &ArchetypeResolver{ @@ -35,7 +32,6 @@ func NewArchetypeResolver(m *model.Archetype, tags *TagResolver, membership *Mem return } -// // ArchetypeResolver wraps an Archetype model // with assessment-related functionality. type ArchetypeResolver struct { @@ -45,7 +41,6 @@ type ArchetypeResolver struct { questionnaire *QuestionnaireResolver } -// // AssessmentTags returns the list of tags that the archetype should // inherit from the answers given to its assessments. func (r *ArchetypeResolver) AssessmentTags() (tags []model.Tag) { @@ -65,7 +60,6 @@ func (r *ArchetypeResolver) AssessmentTags() (tags []model.Tag) { return } -// // RequiredAssessments returns the slice of assessments that are for required questionnaires. func (r *ArchetypeResolver) RequiredAssessments() (required []Assessment) { for _, a := range r.archetype.Assessments { @@ -76,21 +70,18 @@ func (r *ArchetypeResolver) RequiredAssessments() (required []Assessment) { return } -// // Risk returns the overall risk level for the archetypes' assessments. func (r *ArchetypeResolver) Risk() (risk string) { risk = Risk(r.RequiredAssessments()) return } -// // Confidence returns the archetype's overall assessment confidence score. func (r *ArchetypeResolver) Confidence() (confidence int) { confidence = Confidence(r.RequiredAssessments()) return } -// // Assessed returns whether the archetype has been fully assessed. func (r *ArchetypeResolver) Assessed() (assessed bool) { if r.questionnaire == nil { @@ -100,7 +91,6 @@ func (r *ArchetypeResolver) Assessed() (assessed bool) { return } -// // Applications returns the archetype's member applications. func (r *ArchetypeResolver) Applications() (applications []Application, err error) { if r.membership == nil { diff --git a/assessment/assessment.go b/assessment/assessment.go index 43fdef1d6..ceb37a8ec 100644 --- a/assessment/assessment.go +++ b/assessment/assessment.go @@ -7,7 +7,6 @@ import ( "github.com/konveyor/tackle2-hub/model" ) -// // Assessment represents a deserialized Assessment. type Assessment struct { *model.Assessment @@ -16,7 +15,6 @@ type Assessment struct { RiskMessages RiskMessages `json:"riskMessages"` } -// // With updates the Assessment with the db model and deserializes its fields. func (r *Assessment) With(m *model.Assessment) { r.Assessment = m @@ -25,7 +23,6 @@ func (r *Assessment) With(m *model.Assessment) { _ = json.Unmarshal(m.RiskMessages, &r.RiskMessages) } -// // Status returns the started status of the assessment. func (r *Assessment) Status() string { if r.Complete() { @@ -37,7 +34,6 @@ func (r *Assessment) Status() string { } } -// // Complete returns whether all sections have been completed. func (r *Assessment) Complete() bool { for _, s := range r.Sections { @@ -48,7 +44,6 @@ func (r *Assessment) Complete() bool { return true } -// // Started returns whether any sections have been started. func (r *Assessment) Started() bool { for _, s := range r.Sections { @@ -59,7 +54,6 @@ func (r *Assessment) Started() bool { return false } -// // Risk calculates the risk level (red, yellow, green, unknown) for the application. func (r *Assessment) Risk() string { var total uint @@ -85,7 +79,6 @@ func (r *Assessment) Risk() string { return RiskGreen } -// // Confidence calculates a confidence score based on the answers to an assessment's questions. // The algorithm is a reimplementation of the calculation done by Pathfinder. func (r *Assessment) Confidence() (score int) { @@ -125,7 +118,6 @@ func (r *Assessment) Confidence() (score int) { return } -// // Section represents a group of questions in a questionnaire. type Section struct { Order *uint `json:"order" yaml:"order" binding:"required"` @@ -134,7 +126,6 @@ type Section struct { Comment string `json:"comment,omitempty" yaml:"comment,omitempty"` } -// // Complete returns whether all questions in the section have been answered. func (r *Section) Complete() bool { for _, q := range r.Questions { @@ -145,7 +136,6 @@ func (r *Section) Complete() bool { return true } -// // Started returns whether any questions in the section have been answered. func (r *Section) Started() bool { for _, q := range r.Questions { @@ -156,7 +146,6 @@ func (r *Section) Started() bool { return false } -// // Risks returns a slice of the risks of each of its questions. func (r *Section) Risks() []string { risks := []string{} @@ -166,7 +155,6 @@ func (r *Section) Risks() []string { return risks } -// // Tags returns all the tags that should be applied based on how // the questions in the section have been answered. func (r *Section) Tags() (tags []CategorizedTag) { @@ -176,7 +164,6 @@ func (r *Section) Tags() (tags []CategorizedTag) { return } -// // Question represents a question in a questionnaire. type Question struct { Order *uint `json:"order" yaml:"order" binding:"required"` @@ -187,7 +174,6 @@ type Question struct { Answers []Answer `json:"answers" yaml:"answers" binding:"min=1,dive"` } -// // Risk returns the risk level for the question based on how it has been answered. func (r *Question) Risk() string { for _, a := range r.Answers { @@ -198,7 +184,6 @@ func (r *Question) Risk() string { return RiskUnknown } -// // Answered returns whether the question has had an answer selected. func (r *Question) Answered() bool { for _, a := range r.Answers { @@ -209,7 +194,6 @@ func (r *Question) Answered() bool { return false } -// // Tags returns any tags to be applied based on how the question is answered. func (r *Question) Tags() (tags []CategorizedTag) { for _, answer := range r.Answers { @@ -221,7 +205,6 @@ func (r *Question) Tags() (tags []CategorizedTag) { return } -// // Answer represents an answer to a question in a questionnaire. type Answer struct { Order *uint `json:"order" yaml:"order" binding:"required"` @@ -235,14 +218,12 @@ type Answer struct { AutoAnswered bool `json:"autoAnswered,omitempty" yaml:"autoAnswered,omitempty"` } -// // CategorizedTag represents a human-readable pair of category and tag. type CategorizedTag struct { Category string `json:"category" yaml:"category"` Tag string `json:"tag" yaml:"tag"` } -// // RiskMessages contains messages to display for each risk level. type RiskMessages struct { Red string `json:"red" yaml:"red"` @@ -251,7 +232,6 @@ type RiskMessages struct { Unknown string `json:"unknown" yaml:"unknown"` } -// // Thresholds contains the threshold values for determining risk for the questionnaire. type Thresholds struct { Red uint `json:"red" yaml:"red"` diff --git a/assessment/assessment_test.go b/assessment/assessment_test.go index f63c7d537..fc8cbf4db 100644 --- a/assessment/assessment_test.go +++ b/assessment/assessment_test.go @@ -1,9 +1,10 @@ package assessment import ( + "testing" + "github.com/konveyor/tackle2-hub/model" "github.com/onsi/gomega" - "testing" ) func TestPrepareSections(t *testing.T) { diff --git a/assessment/membership.go b/assessment/membership.go index 88a37131d..b6180c5f3 100644 --- a/assessment/membership.go +++ b/assessment/membership.go @@ -7,7 +7,6 @@ import ( "gorm.io/gorm/clause" ) -// // NewMembershipResolver builds a MembershipResolver. func NewMembershipResolver(db *gorm.DB) (m *MembershipResolver) { m = &MembershipResolver{db: db} @@ -16,7 +15,6 @@ func NewMembershipResolver(db *gorm.DB) (m *MembershipResolver) { return } -// // MembershipResolver resolves archetype membership. type MembershipResolver struct { db *gorm.DB @@ -26,7 +24,6 @@ type MembershipResolver struct { membersCached bool } -// // Applications returns the list of applications that are members of the given archetype. func (r *MembershipResolver) Applications(m Archetype) (applications []Application, err error) { err = r.cacheArchetypeMembers() @@ -39,7 +36,6 @@ func (r *MembershipResolver) Applications(m Archetype) (applications []Applicati return } -// // Archetypes returns the list of archetypes that the application is a member of. func (r *MembershipResolver) Archetypes(app Application) (archetypes []Archetype, err error) { err = r.cacheArchetypes() diff --git a/assessment/pkg.go b/assessment/pkg.go index 0f9951780..18671e4c0 100644 --- a/assessment/pkg.go +++ b/assessment/pkg.go @@ -2,10 +2,10 @@ package assessment import ( "encoding/json" + "github.com/konveyor/tackle2-hub/model" ) -// // Assessment risk const ( RiskUnknown = "unknown" @@ -14,7 +14,6 @@ const ( RiskGreen = "green" ) -// // Assessment status const ( StatusEmpty = "empty" @@ -22,21 +21,18 @@ const ( StatusComplete = "complete" ) -// // Confidence adjustment const ( AdjusterRed = 0.5 AdjusterYellow = 0.98 ) -// // Confidence multiplier. const ( MultiplierRed = 0.6 MultiplierYellow = 0.95 ) -// // Risk weights const ( WeightRed = 1 @@ -45,7 +41,6 @@ const ( WeightUnknown = 70 ) -// // Risk returns the single highest risk score for a group of assessments. func Risk(assessments []Assessment) (risk string) { risk = RiskUnknown @@ -85,7 +80,6 @@ func Risk(assessments []Assessment) (risk string) { return } -// // Confidence returns a total confidence score for a group of assessments. func Confidence(assessments []Assessment) (confidence int) { if len(assessments) == 0 { @@ -98,7 +92,6 @@ func Confidence(assessments []Assessment) (confidence int) { return } -// // PrepareForApplication prepares the sections of an assessment by including, excluding, // or auto-answering questions based on a set of tags. func PrepareForApplication(tagResolver *TagResolver, application *model.Application, assessment *model.Assessment) { @@ -115,7 +108,6 @@ func PrepareForApplication(tagResolver *TagResolver, application *model.Applicat return } -// // PrepareForArchetype prepares the sections of an assessment by including, excluding, // or auto-answering questions based on a set of tags. func PrepareForArchetype(tagResolver *TagResolver, archetype *model.Archetype, assessment *model.Assessment) { diff --git a/assessment/questionnaire.go b/assessment/questionnaire.go index d615d0262..905520c9e 100644 --- a/assessment/questionnaire.go +++ b/assessment/questionnaire.go @@ -6,7 +6,6 @@ import ( "gorm.io/gorm" ) -// // NewQuestionnaireResolver builds a QuestionnaireResolver. func NewQuestionnaireResolver(db *gorm.DB) (a *QuestionnaireResolver, err error) { a = &QuestionnaireResolver{db: db} @@ -15,7 +14,6 @@ func NewQuestionnaireResolver(db *gorm.DB) (a *QuestionnaireResolver, err error) return } -// // QuestionnaireResolver resolves questionnaire logic. type QuestionnaireResolver struct { db *gorm.DB @@ -41,13 +39,11 @@ func (r *QuestionnaireResolver) cacheQuestionnaires() (err error) { return } -// // Required returns whether a questionnaire is required. func (r *QuestionnaireResolver) Required(id uint) (required bool) { return r.requiredQuestionnaires.Contains(id) } -// // Assessed returns whether a slice contains a completed assessment for each of the required // questionnaires. func (r *QuestionnaireResolver) Assessed(assessments []Assessment) (assessed bool) { diff --git a/assessment/set.go b/assessment/set.go index 5a49ee930..0de4f357a 100644 --- a/assessment/set.go +++ b/assessment/set.go @@ -1,6 +1,5 @@ package assessment -// // NewSet builds a new Set. func NewSet() (s Set) { s = Set{} @@ -8,20 +7,17 @@ func NewSet() (s Set) { return } -// // Set is an unordered collection of uints // with no duplicate elements. type Set struct { members map[uint]bool } -// // Size returns the number of members in the set. func (r Set) Size() int { return len(r.members) } -// // Add a member to the set. func (r Set) Add(members ...uint) { for _, member := range members { @@ -29,13 +25,11 @@ func (r Set) Add(members ...uint) { } } -// // Contains returns whether an element is a member of the set. func (r Set) Contains(element uint) bool { return r.members[element] } -// // Superset tests whether every element of other is in the set. func (r Set) Superset(other Set, strict bool) bool { if strict && r.Size() <= other.Size() { @@ -49,13 +43,11 @@ func (r Set) Superset(other Set, strict bool) bool { return true } -// // Subset tests whether every element of this set is in the other. func (r Set) Subset(other Set, strict bool) bool { return other.Superset(r, strict) } -// // Intersects tests whether this set and the other have at least one element in common. func (r Set) Intersects(other Set) bool { for m := range r.members { @@ -66,7 +58,6 @@ func (r Set) Intersects(other Set) bool { return false } -// // Members returns the members of the set as a slice. func (r Set) Members() []uint { members := []uint{} diff --git a/assessment/set_test.go b/assessment/set_test.go index b87df2ac2..1fd856079 100644 --- a/assessment/set_test.go +++ b/assessment/set_test.go @@ -1,8 +1,9 @@ package assessment import ( - "github.com/onsi/gomega" "testing" + + "github.com/onsi/gomega" ) func TestSet_Superset(t *testing.T) { diff --git a/assessment/tag.go b/assessment/tag.go index 798178fad..930ed9b31 100644 --- a/assessment/tag.go +++ b/assessment/tag.go @@ -7,7 +7,6 @@ import ( "gorm.io/gorm/clause" ) -// // NewTagResolver builds a TagResolver. func NewTagResolver(db *gorm.DB) (t *TagResolver, err error) { t = &TagResolver{ @@ -17,21 +16,18 @@ func NewTagResolver(db *gorm.DB) (t *TagResolver, err error) { return } -// // TagResolver resolves CategorizedTags to Tag models. type TagResolver struct { cache map[string]map[string]*model.Tag db *gorm.DB } -// // Resolve a category and tag name to a Tag model. func (r *TagResolver) Resolve(category string, tag string) (t *model.Tag, found bool) { t, found = r.cache[category][tag] return } -// // Assessment returns all the Tag models that should be applied from the assessment. func (r *TagResolver) Assessment(assessment Assessment) (tags []model.Tag) { for _, s := range assessment.Sections { diff --git a/auth/auth_test.go b/auth/auth_test.go index c8458b95f..4420ef146 100644 --- a/auth/auth_test.go +++ b/auth/auth_test.go @@ -1,9 +1,10 @@ package auth import ( + "testing" + "github.com/golang-jwt/jwt/v4" "github.com/onsi/gomega" - "testing" ) type _TestProvider struct { diff --git a/auth/builtin.go b/auth/builtin.go index fb4fca5c7..3a444c9d0 100644 --- a/auth/builtin.go +++ b/auth/builtin.go @@ -1,17 +1,16 @@ package auth import ( + "strings" + "github.com/golang-jwt/jwt/v4" liberr "github.com/jortel/go-utils/error" "gorm.io/gorm" - "strings" ) -// // Validators provide token validation based on claims. var Validators []Validator -// // Validator provides token validation. type Validator interface { // Valid determines if the token is valid. @@ -21,24 +20,20 @@ type Validator interface { Valid(token *jwt.Token, db *gorm.DB) (err error) } -// // NoAuth provider always permits access. type NoAuth struct { } -// // NewToken creates a new signed token. func (r NoAuth) NewToken(user string, scopes []string, claims jwt.MapClaims) (signed string, err error) { return } -// // Authenticate the token func (r *NoAuth) Authenticate(_ *Request) (jwToken *jwt.Token, err error) { return } -// // Scopes decodes a list of scopes from the token. // For the NoAuth provider, this just returns a single // wildcard scope matching everything. @@ -47,31 +42,26 @@ func (r *NoAuth) Scopes(jwToken *jwt.Token) (scopes []Scope) { return } -// // User mocks username for NoAuth func (r *NoAuth) User(jwToken *jwt.Token) (name string) { name = "admin.noauth" return } -// // Login and obtain a token. func (r *NoAuth) Login(user, password string) (token Token, err error) { return } -// // Refresh token. func (r *NoAuth) Refresh(refresh string) (token Token, err error) { return } -// // Builtin auth provider. type Builtin struct { } -// // Authenticate the token func (r *Builtin) Authenticate(request *Request) (jwToken *jwt.Token, err error) { token := strings.Replace(request.Token, "Bearer", "", 1) @@ -154,7 +144,6 @@ func (r *Builtin) Authenticate(request *Request) (jwToken *jwt.Token, err error) return } -// // Scopes returns a list of scopes. func (r *Builtin) Scopes(jwToken *jwt.Token) (scopes []Scope) { claims := jwToken.Claims.(jwt.MapClaims) @@ -168,7 +157,6 @@ func (r *Builtin) Scopes(jwToken *jwt.Token) (scopes []Scope) { return } -// // User returns the user associated with the token. func (r *Builtin) User(jwToken *jwt.Token) (user string) { claims := jwToken.Claims.(jwt.MapClaims) @@ -176,19 +164,16 @@ func (r *Builtin) User(jwToken *jwt.Token) (user string) { return } -// // Login and obtain a token. func (r *Builtin) Login(user, password string) (token Token, err error) { return } -// // Refresh token. func (r *Builtin) Refresh(refresh string) (token Token, err error) { return } -// // NewToken creates a new signed token. func (r *Builtin) NewToken(user string, scopes []string, claims jwt.MapClaims) (signed string, err error) { token := jwt.New(jwt.SigningMethodHS512) diff --git a/auth/keycloak.go b/auth/keycloak.go index 29720fca9..8fcc5482c 100644 --- a/auth/keycloak.go +++ b/auth/keycloak.go @@ -3,14 +3,14 @@ package auth import ( "context" "crypto/tls" + "strings" + "time" + "github.com/Nerzal/gocloak/v10" "github.com/golang-jwt/jwt/v4" liberr "github.com/jortel/go-utils/error" - "strings" - "time" ) -// // NewKeycloak builds a new Keycloak auth provider. func NewKeycloak(host, realm string) (p Provider) { client := gocloak.NewClient(host) @@ -23,7 +23,6 @@ func NewKeycloak(host, realm string) (p Provider) { return } -// // Keycloak auth provider type Keycloak struct { client gocloak.GoCloak @@ -31,13 +30,11 @@ type Keycloak struct { realm string } -// // NewToken creates a new signed token. func (r Keycloak) NewToken(user string, scopes []string, claims jwt.MapClaims) (signed string, err error) { return } -// // Login and obtain a token. func (r *Keycloak) Login(user, password string) (token Token, err error) { jwt, err := r.client.Login( @@ -56,7 +53,6 @@ func (r *Keycloak) Login(user, password string) (token Token, err error) { return } -// // Refresh token. func (r *Keycloak) Refresh(refresh string) (token Token, err error) { jwt, err := r.client.RefreshToken( @@ -74,7 +70,6 @@ func (r *Keycloak) Refresh(refresh string) (token Token, err error) { return } -// // Authenticate the token func (r *Keycloak) Authenticate(request *Request) (jwToken *jwt.Token, err error) { ctx, cancel := context.WithTimeout(context.Background(), time.Second*30) @@ -113,7 +108,6 @@ func (r *Keycloak) Authenticate(request *Request) (jwToken *jwt.Token, err error return } -// // Scopes decodes a list of scopes from the token. func (r *Keycloak) Scopes(jwToken *jwt.Token) (scopes []Scope) { claims := jwToken.Claims.(*jwt.MapClaims) @@ -125,7 +119,6 @@ func (r *Keycloak) Scopes(jwToken *jwt.Token) (scopes []Scope) { return } -// // User resolves token to Keycloak username. func (r *Keycloak) User(jwToken *jwt.Token) (user string) { claims, _ := jwToken.Claims.(*jwt.MapClaims) diff --git a/auth/provider.go b/auth/provider.go index 3b83d6c1b..a2066e9ec 100644 --- a/auth/provider.go +++ b/auth/provider.go @@ -3,9 +3,10 @@ package auth import ( "errors" "fmt" + "strings" + "github.com/golang-jwt/jwt/v4" "github.com/jortel/go-utils/logr" - "strings" ) var ( @@ -22,7 +23,6 @@ func init() { Remote = &NoAuth{} } -// // Provider provides RBAC. type Provider interface { // NewToken creates a signed token. @@ -45,7 +45,6 @@ type Token struct { Expiry int } -// // NotAuthenticated is returned when a token cannot be authenticated. type NotAuthenticated struct { Token string @@ -61,7 +60,6 @@ func (e *NotAuthenticated) Is(err error) (matched bool) { return } -// // NotValid is returned when a token is not valid. type NotValid struct { Reason string @@ -78,7 +76,6 @@ func (e *NotValid) Is(err error) (matched bool) { return } -// // Scope represents an authorization scope. type Scope interface { // Match returns whether the scope is a match. @@ -87,14 +84,12 @@ type Scope interface { String() (s string) } -// // BaseScope provides base behavior. type BaseScope struct { Resource string Method string } -// // With parses a scope and populate fields. // Format: : func (r *BaseScope) With(s string) { @@ -109,7 +104,6 @@ func (r *BaseScope) With(s string) { return } -// // Match returns whether the scope is a match. func (r *BaseScope) Match(resource string, method string) (b bool) { b = (r.Resource == "*" || strings.EqualFold(r.Resource, resource)) && @@ -117,7 +111,6 @@ func (r *BaseScope) Match(resource string, method string) (b bool) { return } -// // String representations of the scope. func (r *BaseScope) String() (s string) { s = strings.Join([]string{r.Resource, r.Method}, ":") diff --git a/auth/reconcile.go b/auth/reconcile.go index 089566609..db27f9c4e 100644 --- a/auth/reconcile.go +++ b/auth/reconcile.go @@ -4,13 +4,13 @@ import ( "context" "crypto/tls" "fmt" - "github.com/Nerzal/gocloak/v10" - liberr "github.com/jortel/go-utils/error" "strings" "time" + + "github.com/Nerzal/gocloak/v10" + liberr "github.com/jortel/go-utils/error" ) -// // NewReconciler builds a new Keycloak realm reconciler. func NewReconciler(host, realm, id, secret, admin, pass, adminRealm string) (r Reconciler) { client := gocloak.NewClient(host) @@ -27,7 +27,6 @@ func NewReconciler(host, realm, id, secret, admin, pass, adminRealm string) (r R return } -// // Keycloak realm reconciler type Reconciler struct { client gocloak.GoCloak @@ -40,7 +39,6 @@ type Reconciler struct { token *gocloak.JWT } -// // Realm is a container for the users, // scopes, and roles that exist in the // hub's keycloak realm. @@ -50,7 +48,6 @@ type Realm struct { Roles map[string]gocloak.Role } -// // Reconcile ensures that the Hub realm // exists and the expected clients, roles, scopes, // and users are present in it. @@ -90,7 +87,6 @@ func (r *Reconciler) Reconcile() (err error) { return } -// // loadRealm loads all the scopes, roles, and users from // the hub keycloak realm and populates a Realm struct. func (r *Reconciler) loadRealm() (realm *Realm, err error) { @@ -111,7 +107,6 @@ func (r *Reconciler) loadRealm() (realm *Realm, err error) { return } -// // ensureRealm ensures that the hub realm exists. func (r *Reconciler) ensureRealm() (err error) { _, err = r.client.GetRealm(context.Background(), r.token.AccessToken, r.realm) @@ -138,7 +133,6 @@ func (r *Reconciler) ensureRealm() (err error) { return } -// // ensureClient ensures that the hub client exists. func (r *Reconciler) ensureClient() (err error) { var found bool @@ -168,7 +162,6 @@ func (r *Reconciler) ensureClient() (err error) { return } -// // ensureUsers ensures that the hub users exist and have the necessary roles. func (r *Reconciler) ensureUsers(realm *Realm) (err error) { users, err := LoadUsers(Settings.Auth.UserPath) @@ -243,7 +236,6 @@ func (r *Reconciler) ensureUsers(realm *Realm) (err error) { return } -// // ensureRoles ensures that hub roles and scopes are present in keycloak by // creating them if they are missing and assigning scope mappings. func (r *Reconciler) ensureRoles(realm *Realm) (err error) { @@ -351,7 +343,6 @@ func (r *Reconciler) ensureRoles(realm *Realm) (err error) { return } -// // getClient returns a keycloak realm client. func (r *Reconciler) getClient(clientId string) (client *gocloak.Client, found bool, err error) { max := 1 @@ -372,7 +363,6 @@ func (r *Reconciler) getClient(clientId string) (client *gocloak.Client, found b return } -// // userMap generates a mapping of usernames to user objects func (r *Reconciler) userMap() (userMap map[string]gocloak.User, err error) { userMap = make(map[string]gocloak.User) @@ -389,7 +379,6 @@ func (r *Reconciler) userMap() (userMap map[string]gocloak.User, err error) { return } -// // realmRoleMap generates a mapping of realm role names to role objects func (r *Reconciler) realmRoleMap() (roleMap map[string]gocloak.Role, err error) { roleMap = make(map[string]gocloak.Role) @@ -408,7 +397,6 @@ func (r *Reconciler) realmRoleMap() (roleMap map[string]gocloak.Role, err error) return } -// // scopeMap generates a mapping of client scope names to scope objects func (r *Reconciler) scopeMap() (scopeMap map[string]gocloak.ClientScope, err error) { scopeMap = make(map[string]gocloak.ClientScope) @@ -427,7 +415,6 @@ func (r *Reconciler) scopeMap() (scopeMap map[string]gocloak.ClientScope, err er return } -// // login logs into the keycloak admin-cli client as the administrator. func (r *Reconciler) login() (err error) { for { diff --git a/auth/request.go b/auth/request.go index a28e9681a..ab8c53150 100644 --- a/auth/request.go +++ b/auth/request.go @@ -2,11 +2,11 @@ package auth import ( "errors" + "github.com/golang-jwt/jwt/v4" "gorm.io/gorm" ) -// // Request auth request. type Request struct { Token string @@ -15,7 +15,6 @@ type Request struct { DB *gorm.DB } -// // Permit the specified request. func (r *Request) Permit() (result Result, err error) { var ( diff --git a/auth/role.go b/auth/role.go index 96e2c45e7..e4b803d5a 100644 --- a/auth/role.go +++ b/auth/role.go @@ -11,7 +11,6 @@ import ( var Settings = &settings.Settings -// // AddonRole defines the addon scopes. var AddonRole = []string{ "applications:get", @@ -33,7 +32,6 @@ var AddonRole = []string{ "rulesets:get", } -// // Role represents a RBAC role which grants // access to particular resources in the hub. type Role struct { @@ -41,14 +39,12 @@ type Role struct { Resources []Resource `yaml:"resources" validate:"required"` } -// // Resource is a set of permissions for a hub resource that a role may have. type Resource struct { Name string `yaml:"name" validate:"required"` Verbs []string `yaml:"verbs" validate:"required,dive,oneof=get post put patch delete"` } -// // User is a hub user which may have Roles. type User struct { // Username @@ -59,7 +55,6 @@ type User struct { Roles []string `yaml:"roles"` } -// // LoadRoles loads a list of Role structs from a yaml file // that is located at the given path. func LoadRoles(path string) (roles []Role, err error) { @@ -84,7 +79,6 @@ func LoadRoles(path string) (roles []Role, err error) { return } -// // LoadUsers loads a list of User structs from a yaml // file that is located at the given path. func LoadUsers(path string) (users []User, err error) { diff --git a/binding/application.go b/binding/application.go index 881d991b0..ff66ffa61 100644 --- a/binding/application.go +++ b/binding/application.go @@ -3,29 +3,27 @@ package binding import ( "bytes" "errors" + "io" + "net/http" + "strconv" + mime "github.com/gin-gonic/gin/binding" liberr "github.com/jortel/go-utils/error" "github.com/konveyor/tackle2-hub/api" "gopkg.in/yaml.v2" - "io" - "net/http" - "strconv" ) -// // Application API. type Application struct { client *Client } -// // Create an Application. func (h *Application) Create(r *api.Application) (err error) { err = h.client.Post(api.ApplicationsRoot, &r) return } -// // Get an Application by ID. func (h *Application) Get(id uint) (r *api.Application, err error) { r = &api.Application{} @@ -34,7 +32,6 @@ func (h *Application) Get(id uint) (r *api.Application, err error) { return } -// // List Applications. func (h *Application) List() (list []api.Application, err error) { list = []api.Application{} @@ -42,7 +39,6 @@ func (h *Application) List() (list []api.Application, err error) { return } -// // Update an Application. func (h *Application) Update(r *api.Application) (err error) { path := Path(api.ApplicationRoot).Inject(Params{api.ID: r.ID}) @@ -50,14 +46,12 @@ func (h *Application) Update(r *api.Application) (err error) { return } -// // Delete an Application. func (h *Application) Delete(id uint) (err error) { err = h.client.Delete(Path(api.ApplicationRoot).Inject(Params{api.ID: id})) return } -// // Bucket returns the bucket API. func (h *Application) Bucket(id uint) (b *BucketContent) { params := Params{ @@ -72,7 +66,6 @@ func (h *Application) Bucket(id uint) (b *BucketContent) { return } -// // FindIdentity by kind. func (h *Application) FindIdentity(id uint, kind string) (r *api.Identity, found bool, err error) { list := []api.Identity{} @@ -101,7 +94,6 @@ func (h *Application) FindIdentity(id uint, kind string) (r *api.Identity, found return } -// // Tags returns the tags API. func (h *Application) Tags(id uint) (tg AppTags) { tg = AppTags{ @@ -111,7 +103,6 @@ func (h *Application) Tags(id uint) (tg AppTags) { return } -// // AppTags sub-resource API. // Provides association management of tags to applications by name. type AppTags struct { @@ -120,13 +111,11 @@ type AppTags struct { source *string } -// // Source sets the source for other operations on the associated tags. func (h *AppTags) Source(name string) { h.source = &name } -// // Replace the associated tags for the source with a new set. // Returns an error if the source is not set. func (h *AppTags) Replace(ids []uint) (err error) { @@ -152,7 +141,6 @@ func (h *AppTags) Replace(ids []uint) (err error) { return } -// // List associated tags. // Returns a list of tag names. func (h *AppTags) List() (list []api.TagRef, err error) { @@ -171,7 +159,6 @@ func (h *AppTags) List() (list []api.TagRef, err error) { return } -// // Add associates a tag with the application. func (h *AppTags) Add(id uint) (err error) { path := Path(api.ApplicationTagsRoot).Inject(Params{api.ID: h.appId}) @@ -183,7 +170,6 @@ func (h *AppTags) Add(id uint) (err error) { return } -// // Ensure ensures tag is associated with the application. func (h *AppTags) Ensure(id uint) (err error) { err = h.Add(id) @@ -193,7 +179,6 @@ func (h *AppTags) Ensure(id uint) (err error) { return } -// // Delete ensures the tag is not associated with the application. func (h *AppTags) Delete(id uint) (err error) { path := Path( @@ -209,7 +194,6 @@ func (h *AppTags) Delete(id uint) (err error) { return } -// // unique ensures unique ids. func (h *AppTags) unique(ids []uint) (u []uint) { mp := map[uint]int{} @@ -222,7 +206,6 @@ func (h *AppTags) unique(ids []uint) (u []uint) { return } -// // Facts returns the tags API. func (h *Application) Facts(id uint) (f AppFacts) { f = AppFacts{ @@ -232,7 +215,6 @@ func (h *Application) Facts(id uint) (f AppFacts) { return } -// // AppFacts sub-resource API. // Provides association management of facts. type AppFacts struct { @@ -241,13 +223,11 @@ type AppFacts struct { source string } -// // Source sets the source for other operations on the facts. func (h *AppFacts) Source(source string) { h.source = source } -// // List facts. func (h *AppFacts) List() (facts api.FactMap, err error) { facts = api.FactMap{} @@ -258,7 +238,6 @@ func (h *AppFacts) List() (facts api.FactMap, err error) { return } -// // Get a fact. func (h *AppFacts) Get(name string, value interface{}) (err error) { key := api.FactKey(name) @@ -272,7 +251,6 @@ func (h *AppFacts) Get(name string, value interface{}) (err error) { return } -// // Set a fact (created as needed). func (h *AppFacts) Set(name string, value interface{}) (err error) { key := api.FactKey(name) @@ -286,7 +264,6 @@ func (h *AppFacts) Set(name string, value interface{}) (err error) { return } -// // Delete a fact. func (h *AppFacts) Delete(name string) (err error) { key := api.FactKey(name) @@ -300,7 +277,6 @@ func (h *AppFacts) Delete(name string) (err error) { return } -// // Replace facts. func (h *AppFacts) Replace(facts api.FactMap) (err error) { key := api.FactKey("") @@ -319,7 +295,6 @@ func (h *Application) Analysis(id uint) (a Analysis) { return } -// // Create an Application Assessment. func (h *Application) CreateAssesment(id uint, r *api.Assessment) (err error) { path := Path(api.AppAssessmentsRoot).Inject(Params{api.ID: id}) @@ -327,7 +302,6 @@ func (h *Application) CreateAssesment(id uint, r *api.Assessment) (err error) { return } -// // Get Application Assessments. func (h *Application) GetAssesments(id uint) (list []api.Assessment, err error) { list = []api.Assessment{} @@ -336,14 +310,12 @@ func (h *Application) GetAssesments(id uint) (list []api.Assessment, err error) return } -// // Analysis API. type Analysis struct { client *Client appId uint } -// // Create an analysis report. func (h *Analysis) Create(r *api.Analysis, encoding string, issues, deps io.Reader) (err error) { path := Path(api.AppAnalysesRoot).Inject(Params{api.ID: h.appId}) diff --git a/binding/archetype.go b/binding/archetype.go index cecaca248..911561eeb 100644 --- a/binding/archetype.go +++ b/binding/archetype.go @@ -4,20 +4,17 @@ import ( "github.com/konveyor/tackle2-hub/api" ) -// // Archetype API. type Archetype struct { client *Client } -// // Create a Archetype. func (h *Archetype) Create(r *api.Archetype) (err error) { err = h.client.Post(api.ArchetypesRoot, &r) return } -// // Get a Archetype by ID. func (h *Archetype) Get(id uint) (r *api.Archetype, err error) { r = &api.Archetype{} @@ -26,7 +23,6 @@ func (h *Archetype) Get(id uint) (r *api.Archetype, err error) { return } -// // List Archetypes. func (h *Archetype) List() (list []api.Archetype, err error) { list = []api.Archetype{} @@ -34,7 +30,6 @@ func (h *Archetype) List() (list []api.Archetype, err error) { return } -// // Update a Archetype. func (h *Archetype) Update(r *api.Archetype) (err error) { path := Path(api.ArchetypeRoot).Inject(Params{api.ID: r.ID}) @@ -42,7 +37,6 @@ func (h *Archetype) Update(r *api.Archetype) (err error) { return } -// // Delete a Archetype. func (h *Archetype) Delete(id uint) (err error) { err = h.client.Delete(Path(api.ArchetypeRoot).Inject(Params{api.ID: id})) diff --git a/binding/assessment.go b/binding/assessment.go index 184d987f7..c8a6637c6 100644 --- a/binding/assessment.go +++ b/binding/assessment.go @@ -4,13 +4,11 @@ import ( "github.com/konveyor/tackle2-hub/api" ) -// // Assessment API. type Assessment struct { client *Client } -// // Get a Assessment by ID. func (h *Assessment) Get(id uint) (r *api.Assessment, err error) { r = &api.Assessment{} @@ -19,7 +17,6 @@ func (h *Assessment) Get(id uint) (r *api.Assessment, err error) { return } -// // List Assessments. func (h *Assessment) List() (list []api.Assessment, err error) { list = []api.Assessment{} @@ -27,7 +24,6 @@ func (h *Assessment) List() (list []api.Assessment, err error) { return } -// // Update a Assessment. func (h *Assessment) Update(r *api.Assessment) (err error) { path := Path(api.AssessmentRoot).Inject(Params{api.ID: r.ID}) @@ -35,7 +31,6 @@ func (h *Assessment) Update(r *api.Assessment) (err error) { return } -// // Delete a Assessment. func (h *Assessment) Delete(id uint) (err error) { err = h.client.Delete(Path(api.AssessmentRoot).Inject(Params{api.ID: id})) diff --git a/binding/bucket.go b/binding/bucket.go index cb096f065..a25043f1c 100644 --- a/binding/bucket.go +++ b/binding/bucket.go @@ -6,20 +6,17 @@ import ( "github.com/konveyor/tackle2-hub/api" ) -// // Bucket API. type Bucket struct { client *Client } -// // Create a Bucket. func (h *Bucket) Create(r *api.Bucket) (err error) { err = h.client.Post(api.BucketsRoot, &r) return } -// // Get a bucket. func (h *Bucket) Get(id uint) (r *api.Bucket, err error) { r = &api.Bucket{} @@ -28,7 +25,6 @@ func (h *Bucket) Get(id uint) (r *api.Bucket, err error) { return } -// // List buckets. func (h *Bucket) List() (list []api.Bucket, err error) { list = []api.Bucket{} @@ -36,14 +32,12 @@ func (h *Bucket) List() (list []api.Bucket, err error) { return } -// // Delete a bucket. func (h *Bucket) Delete(id uint) (err error) { err = h.client.Delete(Path(api.BucketRoot).Inject(Params{api.ID: id})) return } -// // Content returns content API. func (h *Bucket) Content(id uint) (b *BucketContent) { params := Params{ @@ -58,14 +52,12 @@ func (h *Bucket) Content(id uint) (b *BucketContent) { return } -// // BucketContent API. type BucketContent struct { client *Client root string } -// // Get reads from the bucket. // The source (root) is relative to the bucket root. func (h *BucketContent) Get(source, destination string) (err error) { @@ -73,7 +65,6 @@ func (h *BucketContent) Get(source, destination string) (err error) { return } -// // Put writes to the bucket. // The destination (root) is relative to the bucket root. func (h *BucketContent) Put(source, destination string) (err error) { @@ -81,7 +72,6 @@ func (h *BucketContent) Put(source, destination string) (err error) { return } -// // Delete deletes content at the specified root. // The source is relative to the bucket root. func (h *BucketContent) Delete(path string) (err error) { diff --git a/binding/businessservice.go b/binding/businessservice.go index 62a9f8147..812ddb61e 100644 --- a/binding/businessservice.go +++ b/binding/businessservice.go @@ -4,20 +4,17 @@ import ( "github.com/konveyor/tackle2-hub/api" ) -// // BusinessService API. type BusinessService struct { client *Client } -// // Create a BusinessService. func (h *BusinessService) Create(r *api.BusinessService) (err error) { err = h.client.Post(api.BusinessServicesRoot, &r) return } -// // Get a BusinessService by ID. func (h *BusinessService) Get(id uint) (r *api.BusinessService, err error) { r = &api.BusinessService{} @@ -26,7 +23,6 @@ func (h *BusinessService) Get(id uint) (r *api.BusinessService, err error) { return } -// // List BusinessServices. func (h *BusinessService) List() (list []api.BusinessService, err error) { list = []api.BusinessService{} @@ -34,7 +30,6 @@ func (h *BusinessService) List() (list []api.BusinessService, err error) { return } -// // Update a BusinessService. func (h *BusinessService) Update(r *api.BusinessService) (err error) { path := Path(api.BusinessServiceRoot).Inject(Params{api.ID: r.ID}) @@ -42,7 +37,6 @@ func (h *BusinessService) Update(r *api.BusinessService) (err error) { return } -// // Delete a BusinessService. func (h *BusinessService) Delete(id uint) (err error) { err = h.client.Delete(Path(api.BusinessServiceRoot).Inject(Params{api.ID: id})) diff --git a/binding/client.go b/binding/client.go index 3fffccbdd..bd91b8d5a 100644 --- a/binding/client.go +++ b/binding/client.go @@ -5,11 +5,6 @@ import ( "encoding/json" "errors" "fmt" - "github.com/gin-gonic/gin/binding" - liberr "github.com/jortel/go-utils/error" - "github.com/konveyor/tackle2-hub/api" - qf "github.com/konveyor/tackle2-hub/binding/filter" - "github.com/konveyor/tackle2-hub/tar" "io" "mime/multipart" "net" @@ -20,6 +15,12 @@ import ( pathlib "path" "strings" "time" + + "github.com/gin-gonic/gin/binding" + liberr "github.com/jortel/go-utils/error" + "github.com/konveyor/tackle2-hub/api" + qf "github.com/konveyor/tackle2-hub/binding/filter" + "github.com/konveyor/tackle2-hub/tar" ) const ( @@ -27,20 +28,17 @@ const ( RetryDelay = time.Second * 10 ) -// // Param. type Param struct { Key string Value string } -// // Filter type Filter struct { qf.Filter } -// // Param returns a filter parameter. func (r *Filter) Param() (p Param) { p.Key = api.Filter @@ -48,15 +46,12 @@ func (r *Filter) Param() (p Param) { return } -// // Params mapping. type Params map[string]interface{} -// // Path API path. type Path string -// // Inject named parameters. func (s Path) Inject(p Params) (out string) { in := strings.Split(string(s), "/") @@ -73,7 +68,6 @@ func (s Path) Inject(p Params) (out string) { return } -// // NewClient Constructs a new client func NewClient(url string, token api.Login) (client *Client) { client = &Client{ @@ -84,7 +78,6 @@ func NewClient(url string, token api.Login) (client *Client) { return } -// // Client provides a REST client. type Client struct { // baseURL for the nub. @@ -99,19 +92,16 @@ type Client struct { Error error } -// // SetToken sets hub token on client func (r *Client) SetToken(token api.Login) { r.token = token } -// // Reset the client. func (r *Client) Reset() { r.Error = nil } -// // Get a resource. func (r *Client) Get(path string, object interface{}, params ...Param) (err error) { request := func() (request *http.Request, err error) { @@ -158,7 +148,6 @@ func (r *Client) Get(path string, object interface{}, params ...Param) (err erro return } -// // Post a resource. func (r *Client) Post(path string, object interface{}) (err error) { request := func() (request *http.Request, err error) { @@ -203,7 +192,6 @@ func (r *Client) Post(path string, object interface{}) (err error) { return } -// // Put a resource. func (r *Client) Put(path string, object interface{}, params ...Param) (err error) { request := func() (request *http.Request, err error) { @@ -256,7 +244,6 @@ func (r *Client) Put(path string, object interface{}, params ...Param) (err erro return } -// // Delete a resource. func (r *Client) Delete(path string, params ...Param) (err error) { request := func() (request *http.Request, err error) { @@ -293,7 +280,6 @@ func (r *Client) Delete(path string, params ...Param) (err error) { return } -// // BucketGet downloads a file/directory. // The source (path) is relative to the bucket root. func (r *Client) BucketGet(source, destination string) (err error) { @@ -329,7 +315,6 @@ func (r *Client) BucketGet(source, destination string) (err error) { return } -// // BucketPut uploads a file/directory. // The destination (path) is relative to the bucket root. func (r *Client) BucketPut(source, destination string) (err error) { @@ -390,7 +375,6 @@ func (r *Client) BucketPut(source, destination string) (err error) { return } -// // FileGet downloads a file. func (r *Client) FileGet(path, destination string) (err error) { request := func() (request *http.Request, err error) { @@ -421,7 +405,6 @@ func (r *Client) FileGet(path, destination string) (err error) { return } -// // FilePost uploads a file. // Returns the created File resource. func (r *Client) FilePost(path, source string, object interface{}) (err error) { @@ -454,7 +437,6 @@ func (r *Client) FilePost(path, source string, object interface{}) (err error) { return } -// // FilePut uploads a file. // Returns the created File resource. func (r *Client) FilePut(path, source string, object interface{}) (err error) { @@ -487,7 +469,6 @@ func (r *Client) FilePut(path, source string, object interface{}) (err error) { return } -// // FilePatch appends file. // Returns the created File resource. func (r *Client) FilePatch(path string, buffer []byte) (err error) { @@ -501,7 +482,6 @@ func (r *Client) FilePatch(path string, buffer []byte) (err error) { return } -// // FileSend sends file upload from. func (r *Client) FileSend(path, method string, fields []Field, object interface{}) (err error) { request := func() (request *http.Request, err error) { @@ -567,7 +547,6 @@ func (r *Client) FileSend(path, method string, fields []Field, object interface{ return } -// // getDir downloads and expands a directory. func (r *Client) getDir(body io.Reader, output string) (err error) { tarReader := tar.NewReader() @@ -575,7 +554,6 @@ func (r *Client) getDir(body io.Reader, output string) (err error) { return } -// // putDir archive and uploads a directory. func (r *Client) putDir(writer io.Writer, input string) (err error) { tarWriter := tar.NewWriter(writer) @@ -584,7 +562,6 @@ func (r *Client) putDir(writer io.Writer, input string) (err error) { return } -// // getFile downloads plain file. func (r *Client) getFile(body io.Reader, path, output string) (err error) { isDir, err := r.IsDir(output, false) @@ -608,7 +585,6 @@ func (r *Client) getFile(body io.Reader, path, output string) (err error) { return } -// // putFile uploads plain file. func (r *Client) putFile(writer io.Writer, input string) (err error) { file, err := os.Open(input) @@ -623,7 +599,6 @@ func (r *Client) putFile(writer io.Writer, input string) (err error) { return } -// // IsDir determines if the path is a directory. // The `must` specifies if the path must exist. func (r *Client) IsDir(path string, must bool) (b bool, err error) { @@ -644,7 +619,6 @@ func (r *Client) IsDir(path string, must bool) (b bool, err error) { return } -// // Send the request. // Resilient against transient hub availability. func (r *Client) send(rb func() (*http.Request, error)) (response *http.Response, err error) { @@ -712,7 +686,6 @@ func (r *Client) send(rb func() (*http.Request, error)) (response *http.Response return } -// // buildTransport builds transport. func (r *Client) buildTransport() (err error) { if r.transport != nil { @@ -732,7 +705,6 @@ func (r *Client) buildTransport() (err error) { return } -// // Join the URL. func (r *Client) join(path string) (parsedURL *url.URL) { parsedURL, _ = url.Parse(r.baseURL) @@ -740,7 +712,6 @@ func (r *Client) join(path string) (parsedURL *url.URL) { return } -// // restError returns an error based on status. func (r *Client) restError(response *http.Response) (err error) { status := response.StatusCode @@ -764,7 +735,6 @@ func (r *Client) restError(response *http.Response) (err error) { return } -// // Field file upload form field. type Field struct { Name string @@ -773,7 +743,6 @@ type Field struct { Encoding string } -// // Write the field content. // When Reader is not set, the path is opened and copied. func (f *Field) Write(writer io.Writer) (err error) { @@ -792,7 +761,6 @@ func (f *Field) Write(writer io.Writer) (err error) { return } -// // encoding returns MIME. func (f *Field) encoding() (mt string) { if f.Encoding != "" { @@ -810,7 +778,6 @@ func (f *Field) encoding() (mt string) { return } -// // disposition returns content-disposition. func (f *Field) disposition() (d string) { d = fmt.Sprintf(`form-data; name="%s"; filename="%s"`, f.Name, pathlib.Base(f.Path)) diff --git a/binding/dependency.go b/binding/dependency.go index a5b1459fa..b9df2ca79 100644 --- a/binding/dependency.go +++ b/binding/dependency.go @@ -4,21 +4,18 @@ import ( "github.com/konveyor/tackle2-hub/api" ) -// // Dependency API. type Dependency struct { // hub API client. client *Client } -// // Create a Dependency. func (h *Dependency) Create(r *api.Dependency) (err error) { err = h.client.Post(api.DependenciesRoot, &r) return } -// // Get a Dependency by ID. func (h *Dependency) Get(id uint) (r *api.Dependency, err error) { r = &api.Dependency{} @@ -27,7 +24,6 @@ func (h *Dependency) Get(id uint) (r *api.Dependency, err error) { return } -// // List Dependencies. func (h *Dependency) List() (list []api.Dependency, err error) { list = []api.Dependency{} @@ -35,7 +31,6 @@ func (h *Dependency) List() (list []api.Dependency, err error) { return } -// // Delete a Dependency. func (h *Dependency) Delete(id uint) (err error) { err = h.client.Delete(Path(api.DependencyRoot).Inject(Params{api.ID: id})) diff --git a/binding/error.go b/binding/error.go index 12d550ae6..831a8de10 100644 --- a/binding/error.go +++ b/binding/error.go @@ -7,7 +7,6 @@ import ( "strings" ) -// // RestError reports REST errors. type RestError struct { Reason string @@ -52,7 +51,6 @@ func (e *RestError) With(r *http.Response) { e.Reason = s } -// // Conflict reports 409 error. type Conflict struct { RestError @@ -63,7 +61,6 @@ func (e *Conflict) Is(err error) (matched bool) { return } -// // NotFound reports 404 error. type NotFound struct { RestError diff --git a/binding/file.go b/binding/file.go index 6e9f258f1..22bdcb80b 100644 --- a/binding/file.go +++ b/binding/file.go @@ -1,17 +1,16 @@ package binding import ( - "github.com/konveyor/tackle2-hub/api" pathlib "path" + + "github.com/konveyor/tackle2-hub/api" ) -// // File API. type File struct { client *Client } -// // Get downloads a file. func (h *File) Get(id uint, destination string) (err error) { path := Path(api.FileRoot).Inject(Params{api.ID: id}) @@ -33,7 +32,6 @@ func (h *File) Get(id uint, destination string) (err error) { return } -// // Touch creates an empty file. func (h *File) Touch(name string) (r *api.File, err error) { r = &api.File{} @@ -42,7 +40,6 @@ func (h *File) Touch(name string) (r *api.File, err error) { return } -// // Post uploads a file. func (h *File) Post(source string) (r *api.File, err error) { r = &api.File{} @@ -51,7 +48,6 @@ func (h *File) Post(source string) (r *api.File, err error) { return } -// // Put uploads a file. func (h *File) Put(source string) (r *api.File, err error) { r = &api.File{} @@ -60,7 +56,6 @@ func (h *File) Put(source string) (r *api.File, err error) { return } -// // Patch appends a file. func (h *File) Patch(id uint, buffer []byte) (err error) { path := Path(api.FileRoot).Inject(Params{api.ID: id}) @@ -68,7 +63,6 @@ func (h *File) Patch(id uint, buffer []byte) (err error) { return } -// // Delete a file. func (h *File) Delete(id uint) (err error) { path := Path(api.FileRoot).Inject(Params{api.ID: id}) diff --git a/binding/filter/builder.go b/binding/filter/builder.go index 36c5ac66b..180b348bc 100644 --- a/binding/filter/builder.go +++ b/binding/filter/builder.go @@ -12,10 +12,11 @@ filter.And("friend").Eq(Any{"Sam","Ed"}) */ import ( - qf "github.com/konveyor/tackle2-hub/api/filter" "reflect" "strconv" "strings" + + qf "github.com/konveyor/tackle2-hub/api/filter" ) const ( @@ -28,21 +29,17 @@ const ( OR = string(qf.OR) ) -// // Any match any. type Any []interface{} -// // All match all. type All []interface{} -// // Filter builder. type Filter struct { predicates []*Predicate } -// // And adds a predicate. // Example: filter.And("name").Equals("Elmer") func (f *Filter) And(field string) (p *Predicate) { @@ -54,7 +51,6 @@ func (f *Filter) And(field string) (p *Predicate) { return p } -// // String returns string representation. func (f *Filter) String() (s string) { var preds []string @@ -65,7 +61,6 @@ func (f *Filter) String() (s string) { return } -// // Predicate is a filter query predicate. type Predicate struct { field string @@ -73,14 +68,12 @@ type Predicate struct { value string } -// // String returns a string representation of the predicate. func (p *Predicate) String() (s string) { s = p.field + p.operator + p.value return } -// // Eq returns a (=) predicate. func (p *Predicate) Eq(object interface{}) *Predicate { p.operator = EQ @@ -88,7 +81,6 @@ func (p *Predicate) Eq(object interface{}) *Predicate { return p } -// // NotEq returns a (!=) predicate. func (p *Predicate) NotEq(object interface{}) *Predicate { p.operator = NOT + EQ @@ -96,7 +88,6 @@ func (p *Predicate) NotEq(object interface{}) *Predicate { return p } -// // Like returns a (~) predicate. func (p *Predicate) Like(object interface{}) *Predicate { p.operator = LIKE @@ -104,7 +95,6 @@ func (p *Predicate) Like(object interface{}) *Predicate { return p } -// // Gt returns a (>) predicate. func (p *Predicate) Gt(object interface{}) *Predicate { p.operator = GT @@ -112,7 +102,6 @@ func (p *Predicate) Gt(object interface{}) *Predicate { return p } -// // GtEq returns a (>=) predicate. func (p *Predicate) GtEq(object interface{}) *Predicate { p.operator = GT + EQ @@ -120,7 +109,6 @@ func (p *Predicate) GtEq(object interface{}) *Predicate { return p } -// // Lt returns a (<) predicate. func (p *Predicate) Lt(object interface{}) *Predicate { p.operator = LT @@ -128,7 +116,6 @@ func (p *Predicate) Lt(object interface{}) *Predicate { return p } -// // LtEq returns a (<) predicate. func (p *Predicate) LtEq(object interface{}) *Predicate { p.operator = LT + EQ diff --git a/binding/filter/filter_test.go b/binding/filter/filter_test.go index 6c935e5e0..3b37847fe 100644 --- a/binding/filter/filter_test.go +++ b/binding/filter/filter_test.go @@ -1,8 +1,9 @@ package filter import ( - "github.com/onsi/gomega" "testing" + + "github.com/onsi/gomega" ) func TestFilter(t *testing.T) { diff --git a/binding/identity.go b/binding/identity.go index 2fa93c965..e7dcb73c3 100644 --- a/binding/identity.go +++ b/binding/identity.go @@ -4,20 +4,17 @@ import ( "github.com/konveyor/tackle2-hub/api" ) -// // Identity API. type Identity struct { client *Client } -// // Create a Identity. func (h *Identity) Create(r *api.Identity) (err error) { err = h.client.Post(api.IdentitiesRoot, &r) return } -// // Get a decrypted Identity by ID. func (h *Identity) Get(id uint) (r *api.Identity, err error) { r = &api.Identity{} @@ -30,7 +27,6 @@ func (h *Identity) Get(id uint) (r *api.Identity, err error) { return } -// // List decrypted Identities. func (h *Identity) List() (list []api.Identity, err error) { list = []api.Identity{} @@ -42,7 +38,6 @@ func (h *Identity) List() (list []api.Identity, err error) { return } -// // Update a Identity. func (h *Identity) Update(r *api.Identity) (err error) { path := Path(api.IdentityRoot).Inject(Params{api.ID: r.ID}) @@ -50,7 +45,6 @@ func (h *Identity) Update(r *api.Identity) (err error) { return } -// // Delete a Identity. func (h *Identity) Delete(id uint) (err error) { err = h.client.Delete(Path(api.IdentityRoot).Inject(Params{api.ID: id})) diff --git a/binding/jobfunction.go b/binding/jobfunction.go index dee90506d..be1948ee4 100644 --- a/binding/jobfunction.go +++ b/binding/jobfunction.go @@ -4,20 +4,17 @@ import ( "github.com/konveyor/tackle2-hub/api" ) -// // JobFunction API. type JobFunction struct { client *Client } -// // Create a JobFunction. func (h *JobFunction) Create(r *api.JobFunction) (err error) { err = h.client.Post(api.JobFunctionsRoot, &r) return } -// // Get a JobFunction by ID. func (h *JobFunction) Get(id uint) (r *api.JobFunction, err error) { r = &api.JobFunction{} @@ -26,7 +23,6 @@ func (h *JobFunction) Get(id uint) (r *api.JobFunction, err error) { return } -// // List JobFunctions. func (h *JobFunction) List() (list []api.JobFunction, err error) { list = []api.JobFunction{} @@ -34,7 +30,6 @@ func (h *JobFunction) List() (list []api.JobFunction, err error) { return } -// // Update a JobFunction. func (h *JobFunction) Update(r *api.JobFunction) (err error) { path := Path(api.JobFunctionRoot).Inject(Params{api.ID: r.ID}) @@ -42,7 +37,6 @@ func (h *JobFunction) Update(r *api.JobFunction) (err error) { return } -// // Delete a JobFunction. func (h *JobFunction) Delete(id uint) (err error) { err = h.client.Delete(Path(api.JobFunctionRoot).Inject(Params{api.ID: id})) diff --git a/binding/migrationwave.go b/binding/migrationwave.go index abacc3711..9c380d136 100644 --- a/binding/migrationwave.go +++ b/binding/migrationwave.go @@ -4,20 +4,17 @@ import ( "github.com/konveyor/tackle2-hub/api" ) -// // MigrationWave API. type MigrationWave struct { client *Client } -// // Create a MigrationWave. func (h *MigrationWave) Create(r *api.MigrationWave) (err error) { err = h.client.Post(api.MigrationWavesRoot, &r) return } -// // Get a MigrationWave by ID. func (h *MigrationWave) Get(id uint) (r *api.MigrationWave, err error) { r = &api.MigrationWave{} @@ -26,7 +23,6 @@ func (h *MigrationWave) Get(id uint) (r *api.MigrationWave, err error) { return } -// // List MigrationWaves. func (h *MigrationWave) List() (list []api.MigrationWave, err error) { list = []api.MigrationWave{} @@ -34,7 +30,6 @@ func (h *MigrationWave) List() (list []api.MigrationWave, err error) { return } -// // Update a MigrationWave. func (h *MigrationWave) Update(r *api.MigrationWave) (err error) { path := Path(api.MigrationWaveRoot).Inject(Params{api.ID: r.ID}) @@ -42,7 +37,6 @@ func (h *MigrationWave) Update(r *api.MigrationWave) (err error) { return } -// // Delete a MigrationWave. func (h *MigrationWave) Delete(id uint) (err error) { err = h.client.Delete(Path(api.MigrationWaveRoot).Inject(Params{api.ID: id})) diff --git a/binding/proxy.go b/binding/proxy.go index 26ecb18d1..2ed9d1a48 100644 --- a/binding/proxy.go +++ b/binding/proxy.go @@ -4,20 +4,17 @@ import ( "github.com/konveyor/tackle2-hub/api" ) -// // Proxy API. type Proxy struct { client *Client } -// // Create a Proxy. func (h *Proxy) Create(r *api.Proxy) (err error) { err = h.client.Post(api.ProxiesRoot, &r) return } -// // Get a Proxy by ID. func (h *Proxy) Get(id uint) (r *api.Proxy, err error) { r = &api.Proxy{} @@ -26,7 +23,6 @@ func (h *Proxy) Get(id uint) (r *api.Proxy, err error) { return } -// // List Proxies. func (h *Proxy) List() (list []api.Proxy, err error) { list = []api.Proxy{} @@ -34,7 +30,6 @@ func (h *Proxy) List() (list []api.Proxy, err error) { return } -// // Update a Proxy. func (h *Proxy) Update(r *api.Proxy) (err error) { path := Path(api.ProxyRoot).Inject(Params{api.ID: r.ID}) @@ -42,14 +37,12 @@ func (h *Proxy) Update(r *api.Proxy) (err error) { return } -// // Delete a Proxy. func (h *Proxy) Delete(id uint) (err error) { err = h.client.Delete(Path(api.ProxyRoot).Inject(Params{api.ID: id})) return } -// // Find by Kind. // Returns nil when not found. func (h *Proxy) Find(kind string) (r *api.Proxy, err error) { diff --git a/binding/questionnaire.go b/binding/questionnaire.go index 1dd529b8c..932e0c377 100644 --- a/binding/questionnaire.go +++ b/binding/questionnaire.go @@ -4,20 +4,17 @@ import ( "github.com/konveyor/tackle2-hub/api" ) -// // Questionnaire API. type Questionnaire struct { client *Client } -// // Create a Questionnaire. func (h *Questionnaire) Create(r *api.Questionnaire) (err error) { err = h.client.Post(api.QuestionnairesRoot, &r) return } -// // Get a Questionnaire by ID. func (h *Questionnaire) Get(id uint) (r *api.Questionnaire, err error) { r = &api.Questionnaire{} @@ -26,7 +23,6 @@ func (h *Questionnaire) Get(id uint) (r *api.Questionnaire, err error) { return } -// // List Questionnaires. func (h *Questionnaire) List() (list []api.Questionnaire, err error) { list = []api.Questionnaire{} @@ -34,7 +30,6 @@ func (h *Questionnaire) List() (list []api.Questionnaire, err error) { return } -// // Update a Questionnaire. func (h *Questionnaire) Update(r *api.Questionnaire) (err error) { path := Path(api.QuestionnaireRoot).Inject(Params{api.ID: r.ID}) @@ -42,7 +37,6 @@ func (h *Questionnaire) Update(r *api.Questionnaire) (err error) { return } -// // Delete a Questionnaire. func (h *Questionnaire) Delete(id uint) (err error) { err = h.client.Delete(Path(api.QuestionnaireRoot).Inject(Params{api.ID: id})) diff --git a/binding/review.go b/binding/review.go index 775f87c24..37cfd6049 100644 --- a/binding/review.go +++ b/binding/review.go @@ -4,20 +4,17 @@ import ( "github.com/konveyor/tackle2-hub/api" ) -// // Review API. type Review struct { client *Client } -// // Create a Review. func (h *Review) Create(r *api.Review) (err error) { err = h.client.Post(api.ReviewsRoot, &r) return } -// // Get a Review by ID. func (h *Review) Get(id uint) (r *api.Review, err error) { r = &api.Review{} @@ -26,7 +23,6 @@ func (h *Review) Get(id uint) (r *api.Review, err error) { return } -// // List Reviews. func (h *Review) List() (list []api.Review, err error) { list = []api.Review{} @@ -34,7 +30,6 @@ func (h *Review) List() (list []api.Review, err error) { return } -// // Update a Review. func (h *Review) Update(r *api.Review) (err error) { path := Path(api.ReviewRoot).Inject(Params{api.ID: r.ID}) @@ -42,14 +37,12 @@ func (h *Review) Update(r *api.Review) (err error) { return } -// // Delete a Review. func (h *Review) Delete(id uint) (err error) { err = h.client.Delete(Path(api.ReviewRoot).Inject(Params{api.ID: id})) return } -// // Copy a Review. func (h *Review) Copy(reviewID uint, appID uint) (err error) { copyRequest := api.CopyRequest{ diff --git a/binding/richclient.go b/binding/richclient.go index dc6bc697f..7ced1c9c6 100644 --- a/binding/richclient.go +++ b/binding/richclient.go @@ -63,11 +63,11 @@ func New(baseUrl string) (r *RichClient) { Application: Application{ client: client, }, - Archetype: Archetype{ + Archetype: Archetype{ client: client, }, Assessment: Assessment{ - client: client, + client: client, }, Bucket: Bucket{ client: client, @@ -137,7 +137,6 @@ func New(baseUrl string) (r *RichClient) { return } -// // Login set token. func (r *RichClient) Login(user, password string) (err error) { login := api.Login{User: user, Password: password} diff --git a/binding/ruleset.go b/binding/ruleset.go index fef167c74..cc79c0079 100644 --- a/binding/ruleset.go +++ b/binding/ruleset.go @@ -4,20 +4,17 @@ import ( "github.com/konveyor/tackle2-hub/api" ) -// // RuleSet API. type RuleSet struct { client *Client } -// // Create a RuleSet. func (h *RuleSet) Create(r *api.RuleSet) (err error) { err = h.client.Post(api.RuleSetsRoot, &r) return } -// // Get a RuleSet by ID. func (h *RuleSet) Get(id uint) (r *api.RuleSet, err error) { r = &api.RuleSet{} @@ -26,7 +23,6 @@ func (h *RuleSet) Get(id uint) (r *api.RuleSet, err error) { return } -// // List RuleSets. func (h *RuleSet) List() (list []api.RuleSet, err error) { list = []api.RuleSet{} @@ -34,7 +30,6 @@ func (h *RuleSet) List() (list []api.RuleSet, err error) { return } -// // Find RuleSets with filter. func (h *RuleSet) Find(filter Filter) (list []api.RuleSet, err error) { list = []api.RuleSet{} @@ -42,7 +37,6 @@ func (h *RuleSet) Find(filter Filter) (list []api.RuleSet, err error) { return } -// // Update a RuleSet. func (h *RuleSet) Update(r *api.RuleSet) (err error) { path := Path(api.RuleSetRoot).Inject(Params{api.ID: r.ID}) @@ -50,7 +44,6 @@ func (h *RuleSet) Update(r *api.RuleSet) (err error) { return } -// // Delete a RuleSet. func (h *RuleSet) Delete(id uint) (err error) { err = h.client.Delete(Path(api.RuleSetRoot).Inject(Params{api.ID: id})) diff --git a/binding/setting.go b/binding/setting.go index 012f8f0fc..c1359155c 100644 --- a/binding/setting.go +++ b/binding/setting.go @@ -4,13 +4,11 @@ import ( "github.com/konveyor/tackle2-hub/api" ) -// // Setting API. type Setting struct { client *Client } -// // Get a setting by key. func (h *Setting) Get(key string, v interface{}) (err error) { path := Path(api.SettingRoot).Inject(Params{api.Key: key}) @@ -18,35 +16,30 @@ func (h *Setting) Get(key string, v interface{}) (err error) { return } -// // Bool setting value. func (h *Setting) Bool(key string) (b bool, err error) { err = h.Get(key, &b) return } -// // Str setting value. func (h *Setting) Str(key string) (s string, err error) { err = h.Get(key, &s) return } -// // Int setting value. func (h *Setting) Int(key string) (n int, err error) { err = h.Get(key, &n) return } -// // Create a Setting. func (h *Setting) Create(r *api.Setting) (err error) { err = h.client.Post(api.SettingsRoot, &r) return } -// // List Settings. func (h *Setting) List() (list []api.Setting, err error) { list = []api.Setting{} @@ -54,7 +47,6 @@ func (h *Setting) List() (list []api.Setting, err error) { return } -// // Update a Setting. func (h *Setting) Update(r *api.Setting) (err error) { path := Path(api.SettingRoot).Inject(Params{api.Key: r.Key}) @@ -62,7 +54,6 @@ func (h *Setting) Update(r *api.Setting) (err error) { return } -// // Delete a Setting. func (h *Setting) Delete(key string) (err error) { path := Path(api.SettingRoot).Inject(Params{api.Key: key}) diff --git a/binding/stakeholder.go b/binding/stakeholder.go index e4827872b..ffff81e32 100644 --- a/binding/stakeholder.go +++ b/binding/stakeholder.go @@ -4,20 +4,17 @@ import ( "github.com/konveyor/tackle2-hub/api" ) -// // Stakeholder API. type Stakeholder struct { client *Client } -// // Create a Stakeholder. func (h *Stakeholder) Create(r *api.Stakeholder) (err error) { err = h.client.Post(api.StakeholdersRoot, &r) return } -// // Get a Stakeholder by ID. func (h *Stakeholder) Get(id uint) (r *api.Stakeholder, err error) { r = &api.Stakeholder{} @@ -26,7 +23,6 @@ func (h *Stakeholder) Get(id uint) (r *api.Stakeholder, err error) { return } -// // List Stakeholders. func (h *Stakeholder) List() (list []api.Stakeholder, err error) { list = []api.Stakeholder{} @@ -34,7 +30,6 @@ func (h *Stakeholder) List() (list []api.Stakeholder, err error) { return } -// // Update a Stakeholder. func (h *Stakeholder) Update(r *api.Stakeholder) (err error) { path := Path(api.StakeholderRoot).Inject(Params{api.ID: r.ID}) @@ -42,7 +37,6 @@ func (h *Stakeholder) Update(r *api.Stakeholder) (err error) { return } -// // Delete a Stakeholder. func (h *Stakeholder) Delete(id uint) (err error) { err = h.client.Delete(Path(api.StakeholderRoot).Inject(Params{api.ID: id})) diff --git a/binding/stakeholdergroup.go b/binding/stakeholdergroup.go index 0ec3dd17e..128ce623f 100644 --- a/binding/stakeholdergroup.go +++ b/binding/stakeholdergroup.go @@ -4,20 +4,17 @@ import ( "github.com/konveyor/tackle2-hub/api" ) -// // StakeholderGroup API. type StakeholderGroup struct { client *Client } -// // Create a StakeholderGroup. func (h *StakeholderGroup) Create(r *api.StakeholderGroup) (err error) { err = h.client.Post(api.StakeholderGroupsRoot, &r) return } -// // Get a StakeholderGroup by ID. func (h *StakeholderGroup) Get(id uint) (r *api.StakeholderGroup, err error) { r = &api.StakeholderGroup{} @@ -26,7 +23,6 @@ func (h *StakeholderGroup) Get(id uint) (r *api.StakeholderGroup, err error) { return } -// // List StakeholderGroups. func (h *StakeholderGroup) List() (list []api.StakeholderGroup, err error) { list = []api.StakeholderGroup{} @@ -34,7 +30,6 @@ func (h *StakeholderGroup) List() (list []api.StakeholderGroup, err error) { return } -// // Update a StakeholderGroup. func (h *StakeholderGroup) Update(r *api.StakeholderGroup) (err error) { path := Path(api.StakeholderGroupRoot).Inject(Params{api.ID: r.ID}) @@ -42,7 +37,6 @@ func (h *StakeholderGroup) Update(r *api.StakeholderGroup) (err error) { return } -// // Delete a StakeholderGroup. func (h *StakeholderGroup) Delete(id uint) (err error) { err = h.client.Delete(Path(api.StakeholderGroupRoot).Inject(Params{api.ID: id})) diff --git a/binding/tag.go b/binding/tag.go index cf1243fd4..f7f1973d8 100644 --- a/binding/tag.go +++ b/binding/tag.go @@ -4,20 +4,17 @@ import ( "github.com/konveyor/tackle2-hub/api" ) -// // Tag API. type Tag struct { client *Client } -// // Create a Tag. func (h *Tag) Create(r *api.Tag) (err error) { err = h.client.Post(api.TagsRoot, &r) return } -// // Get a Tag by ID. func (h *Tag) Get(id uint) (r *api.Tag, err error) { r = &api.Tag{} @@ -26,7 +23,6 @@ func (h *Tag) Get(id uint) (r *api.Tag, err error) { return } -// // List Tags. func (h *Tag) List() (list []api.Tag, err error) { list = []api.Tag{} @@ -34,7 +30,6 @@ func (h *Tag) List() (list []api.Tag, err error) { return } -// // Update a Tag. func (h *Tag) Update(r *api.Tag) (err error) { path := Path(api.TagRoot).Inject(Params{api.ID: r.ID}) @@ -42,14 +37,12 @@ func (h *Tag) Update(r *api.Tag) (err error) { return } -// // Delete a Tag. func (h *Tag) Delete(id uint) (err error) { err = h.client.Delete(Path(api.TagRoot).Inject(Params{api.ID: id})) return } -// // Find by name and type. func (h *Tag) Find(name string, category uint) (r *api.Tag, found bool, err error) { list := []api.Tag{} @@ -71,7 +64,6 @@ func (h *Tag) Find(name string, category uint) (r *api.Tag, found bool, err erro return } -// // Ensure a tag exists. func (h *Tag) Ensure(wanted *api.Tag) (err error) { tag, found, err := h.Find(wanted.Name, wanted.Category.ID) diff --git a/binding/tagcategory.go b/binding/tagcategory.go index 1aaac65e3..3b06c28e6 100644 --- a/binding/tagcategory.go +++ b/binding/tagcategory.go @@ -4,20 +4,17 @@ import ( "github.com/konveyor/tackle2-hub/api" ) -// // TagCategory API. type TagCategory struct { client *Client } -// // Create a TagCategory. func (h *TagCategory) Create(r *api.TagCategory) (err error) { err = h.client.Post(api.TagCategoriesRoot, &r) return } -// // Get a TagCategory by ID. func (h *TagCategory) Get(id uint) (r *api.TagCategory, err error) { r = &api.TagCategory{} @@ -26,7 +23,6 @@ func (h *TagCategory) Get(id uint) (r *api.TagCategory, err error) { return } -// // List TagCategories. func (h *TagCategory) List() (list []api.TagCategory, err error) { list = []api.TagCategory{} @@ -34,7 +30,6 @@ func (h *TagCategory) List() (list []api.TagCategory, err error) { return } -// // Update a TagCategory. func (h *TagCategory) Update(r *api.TagCategory) (err error) { path := Path(api.TagCategoryRoot).Inject(Params{api.ID: r.ID}) @@ -42,14 +37,12 @@ func (h *TagCategory) Update(r *api.TagCategory) (err error) { return } -// // Delete a TagCategory. func (h *TagCategory) Delete(id uint) (err error) { err = h.client.Delete(Path(api.TagCategoryRoot).Inject(Params{api.ID: id})) return } -// // Find by name. func (h *TagCategory) Find(name string) (r *api.TagCategory, found bool, err error) { list := []api.TagCategory{} @@ -70,7 +63,6 @@ func (h *TagCategory) Find(name string) (r *api.TagCategory, found bool, err err return } -// // Ensure a tag-type exists. func (h *TagCategory) Ensure(wanted *api.TagCategory) (err error) { tp, found, err := h.Find(wanted.Name) diff --git a/binding/target.go b/binding/target.go index 417375a7f..0d2e1c22c 100644 --- a/binding/target.go +++ b/binding/target.go @@ -4,20 +4,17 @@ import ( "github.com/konveyor/tackle2-hub/api" ) -// // Target API. type Target struct { client *Client } -// // Create a Target. func (h *Target) Create(r *api.Target) (err error) { err = h.client.Post(api.TargetsRoot, &r) return } -// // Get a Target by ID. func (h *Target) Get(id uint) (r *api.Target, err error) { r = &api.Target{} @@ -26,7 +23,6 @@ func (h *Target) Get(id uint) (r *api.Target, err error) { return } -// // List Targets. func (h *Target) List() (list []api.Target, err error) { list = []api.Target{} @@ -34,7 +30,6 @@ func (h *Target) List() (list []api.Target, err error) { return } -// // Update a Target. func (h *Target) Update(r *api.Target) (err error) { path := Path(api.TargetRoot).Inject(Params{api.ID: r.ID}) @@ -42,7 +37,6 @@ func (h *Target) Update(r *api.Target) (err error) { return } -// // Delete a Target. func (h *Target) Delete(id uint) (err error) { err = h.client.Delete(Path(api.TargetRoot).Inject(Params{api.ID: id})) diff --git a/binding/task.go b/binding/task.go index adef4590f..8cd08fb0a 100644 --- a/binding/task.go +++ b/binding/task.go @@ -4,20 +4,17 @@ import ( "github.com/konveyor/tackle2-hub/api" ) -// // Task API. type Task struct { client *Client } -// // Create a Task. func (h *Task) Create(r *api.Task) (err error) { err = h.client.Post(api.TasksRoot, &r) return } -// // Get a Task by ID. func (h *Task) Get(id uint) (r *api.Task, err error) { r = &api.Task{} @@ -26,7 +23,6 @@ func (h *Task) Get(id uint) (r *api.Task, err error) { return } -// // List Tasks. func (h *Task) List() (list []api.Task, err error) { list = []api.Task{} @@ -34,7 +30,6 @@ func (h *Task) List() (list []api.Task, err error) { return } -// // Update a Task. func (h *Task) Update(r *api.Task) (err error) { path := Path(api.TaskRoot).Inject(Params{api.ID: r.ID}) @@ -42,14 +37,12 @@ func (h *Task) Update(r *api.Task) (err error) { return } -// // Delete a Task. func (h *Task) Delete(id uint) (err error) { err = h.client.Delete(Path(api.TaskRoot).Inject(Params{api.ID: id})) return } -// // Bucket returns the bucket API. func (h *Task) Bucket(id uint) (b *BucketContent) { params := Params{ diff --git a/binding/ticket.go b/binding/ticket.go index 60c294dd1..3edad23b7 100644 --- a/binding/ticket.go +++ b/binding/ticket.go @@ -4,20 +4,17 @@ import ( "github.com/konveyor/tackle2-hub/api" ) -// // Ticket API. type Ticket struct { client *Client } -// // Create a Ticket. func (h *Ticket) Create(r *api.Ticket) (err error) { err = h.client.Post(api.TicketsRoot, &r) return } -// // Get a Ticket by ID. func (h *Ticket) Get(id uint) (r *api.Ticket, err error) { r = &api.Ticket{} @@ -26,7 +23,6 @@ func (h *Ticket) Get(id uint) (r *api.Ticket, err error) { return } -// // List Tickets.. func (h *Ticket) List() (list []api.Ticket, err error) { list = []api.Ticket{} @@ -34,7 +30,6 @@ func (h *Ticket) List() (list []api.Ticket, err error) { return } -// // Delete a Ticket. func (h *Ticket) Delete(id uint) (err error) { err = h.client.Delete(Path(api.TicketRoot).Inject(Params{api.ID: id})) diff --git a/binding/tracker.go b/binding/tracker.go index 561a45f28..b1c095fa6 100644 --- a/binding/tracker.go +++ b/binding/tracker.go @@ -4,20 +4,17 @@ import ( "github.com/konveyor/tackle2-hub/api" ) -// // Tracker API. type Tracker struct { client *Client } -// // Create a Tracker. func (h *Tracker) Create(r *api.Tracker) (err error) { err = h.client.Post(api.TrackersRoot, &r) return } -// // Get a Tracker by ID. func (h *Tracker) Get(id uint) (r *api.Tracker, err error) { r = &api.Tracker{} @@ -26,7 +23,6 @@ func (h *Tracker) Get(id uint) (r *api.Tracker, err error) { return } -// // List Trackers. func (h *Tracker) List() (list []api.Tracker, err error) { list = []api.Tracker{} @@ -34,7 +30,6 @@ func (h *Tracker) List() (list []api.Tracker, err error) { return } -// // Update a Tracker. func (h *Tracker) Update(r *api.Tracker) (err error) { path := Path(api.TrackerRoot).Inject(Params{api.ID: r.ID}) @@ -42,14 +37,12 @@ func (h *Tracker) Update(r *api.Tracker) (err error) { return } -// // Delete a Tracker. func (h *Tracker) Delete(id uint) (err error) { err = h.client.Delete(Path(api.TrackerRoot).Inject(Params{api.ID: id})) return } -// // List Projects. func (h *Tracker) ListProjects(id uint) (projectList []api.Project, err error) { projectList = []api.Project{} @@ -57,7 +50,6 @@ func (h *Tracker) ListProjects(id uint) (projectList []api.Project, err error) { return } -// // Get Projects. func (h *Tracker) GetProjects(id1 uint, id2 uint) (project api.Project, err error) { project = api.Project{} @@ -65,7 +57,6 @@ func (h *Tracker) GetProjects(id1 uint, id2 uint) (project api.Project, err erro return } -// // List Project Issue Types. func (h *Tracker) ListProjectIssueTypes(id1 uint, id2 uint) (issueType []api.IssueType, err error) { issueType = []api.IssueType{} diff --git a/cmd/main.go b/cmd/main.go index 2c5791c93..86980f8e0 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -2,6 +2,9 @@ package main import ( "context" + "net/http" + "syscall" + "github.com/gin-gonic/gin" liberr "github.com/jortel/go-utils/error" "github.com/jortel/go-utils/logr" @@ -21,10 +24,8 @@ import ( "github.com/konveyor/tackle2-hub/tracker" "gorm.io/gorm" "k8s.io/client-go/kubernetes/scheme" - "net/http" "sigs.k8s.io/controller-runtime/pkg/client/config" "sigs.k8s.io/controller-runtime/pkg/manager" - "syscall" ) var Settings = &settings.Settings @@ -35,7 +36,6 @@ func init() { _ = Settings.Load() } -// // Setup the DB and models. func Setup() (db *gorm.DB, err error) { err = migration.Migrate(migration.All()) @@ -53,14 +53,12 @@ func Setup() (db *gorm.DB, err error) { return } -// // buildScheme adds CRDs to the k8s scheme. func buildScheme() (err error) { err = crd.AddToScheme(scheme.Scheme) return } -// // addonManager func addonManager(db *gorm.DB) (mgr manager.Manager, err error) { cfg, err := config.GetConfig() @@ -86,7 +84,6 @@ func addonManager(db *gorm.DB) (mgr manager.Manager, err error) { return } -// // main. func main() { log.Info("Started", "settings", Settings) diff --git a/controller/addon.go b/controller/addon.go index e225ceb90..08d29af7d 100644 --- a/controller/addon.go +++ b/controller/addon.go @@ -2,6 +2,7 @@ package controller import ( "context" + "github.com/go-logr/logr" logr2 "github.com/jortel/go-utils/logr" api "github.com/konveyor/tackle2-hub/k8s/api/tackle/v1alpha1" @@ -22,15 +23,12 @@ const ( Name = "addon" ) -// // Package logger. var log = logr2.WithName(Name) -// // Settings defines applcation settings. var Settings = &settings.Settings -// // Add the controller. func Add(mgr manager.Manager, db *gorm.DB) error { reconciler := &Reconciler{ @@ -60,7 +58,6 @@ func Add(mgr manager.Manager, db *gorm.DB) error { return nil } -// // Reconciler reconciles addon CRs. type Reconciler struct { record.EventRecorder @@ -69,7 +66,6 @@ type Reconciler struct { Log logr.Logger } -// // Reconcile a Addon CR. // Note: Must not a pointer receiver to ensure that the // logger and other state is not shared. @@ -108,13 +104,11 @@ func (r Reconciler) Reconcile(ctx context.Context, request reconcile.Request) (r return } -// // addonChanged an addon has been created/updated. func (r *Reconciler) addonChanged(addon *api.Addon) (err error) { return } -// // addonDeleted an addon has been deleted. func (r *Reconciler) addonDeleted(name string) (err error) { return diff --git a/database/db_test.go b/database/db_test.go index e763936d3..36555f21b 100644 --- a/database/db_test.go +++ b/database/db_test.go @@ -3,9 +3,10 @@ package database import ( "encoding/json" "fmt" - "github.com/konveyor/tackle2-hub/model" "os" "testing" + + "github.com/konveyor/tackle2-hub/model" ) var N = 800 diff --git a/database/pkg.go b/database/pkg.go index f392feafb..9f0b29cb2 100644 --- a/database/pkg.go +++ b/database/pkg.go @@ -3,6 +3,7 @@ package database import ( "database/sql" "fmt" + liberr "github.com/jortel/go-utils/error" "github.com/jortel/go-utils/logr" "github.com/konveyor/tackle2-hub/model" @@ -22,7 +23,6 @@ const ( FKsOff = "&_foreign_keys=no" ) -// // Open and automigrate the DB. func Open(enforceFKs bool) (db *gorm.DB, err error) { connStr := fmt.Sprintf(ConnectionString, Settings.DB.Path) @@ -59,7 +59,6 @@ func Open(enforceFKs bool) (db *gorm.DB, err error) { return } -// // Close the DB. func Close(db *gorm.DB) (err error) { var sqlDB *sql.DB diff --git a/docs/questionnaire-yaml.md b/docs/questionnaire-yaml.md new file mode 100644 index 000000000..88538991c --- /dev/null +++ b/docs/questionnaire-yaml.md @@ -0,0 +1,60 @@ + +## Questionnaire Documentation + +Here, we will describe the fields and their purpose to make creating a new assessment easy + +### Questionnaire Fields + +1. name: Name of the questionnaire. Name is required and must be unique for the entire konveyor instance. +2. description: An optional short description of the questionnaire. +3. thresholds: Required the threshold definition for each risk category for the application or the archetype to be considered affected by that risk level. The higher risk level always takes precedence. For example, if yellow threshold is established in 30% and red in 5%, and the answers for an application or archetype have 35% yellow and 6% red, the risk level for the application or archetype will be red. + 1. red: Required numeric percentage (example: 30 for 30%) of red answers the questionnaire can have until the risk level is considered red. + 2. yellow: Required numeric percentage (example: 30 for 30%) of yellow answers the questionnaire can have until the risk level is considered yellow. + 3. unknown: Required numeric percentage (example: 30 for 30%) of unknown answers the questionnaire can have until the risk level is considered unknown. +4. riskMessages: Required messages to be displayed in reports for each risk category. The risk_messages map is defined by the following fields: + 5. red: Required string message to display in reports for the red risk level. + 6. yellow: Required string message to display in reports for the yellow risk level. + 7. green: Required string message to display in reports for the green risk level. + 8. unknown: Required string message to display in reports for the unknown risk level. +5. sections: Required list of sections that the questionnaire will include. + 1. name: Name is the required string to be displayed for the section. + 1. order: Required int order in which the question should appear in the section. + 1. comment: Optional string to describe the section. + 1. questions: Required list of questions that belong to the section. + 1. order: Required int order in which the question should appear in the section. + 1. text: Required string of the question to be asked. + 1. explanation: Optional string of additional explanations for the question. + 2. includeFor: Optional list that defines a question should be displayed if any of the tags included in the list is present in the target application or archetype. + 1. category: Required string category of the target tag. + 2. tag: Required string for the target tag. + 3. excludeFor: Optional list defines that a question should be skipped if any of the tags included in the list is present in the target application or archetype. + 1. category: Required string category of the target tag. + 2. tag: Required string for the target tag. + 4. answers: Required list of answers for the given question. + 1. order: Required int order in which the question should appear in the section. + 1. text: Required string the actual answer for the question. + 2. risk: Required to be one of red, yellow, green, or unknown. The risk level the current answer implies. + 3. rationale: Optional string explaining the justification for the answer being considered a risk. + 4. mitigation: Optional string for an explanation of the potential mitigation strategy for the risk implied by this answer. + 5. applyTags: Optional list that defines a list of tags to be automatically applied to the assessed application or archetype if this answer is selected. + 1. category: Required string category of the target tag. + 2. tag: Required string for the target tag. + 6. autoAnswerFor: Optional list defines a list of tags that will lead to this answer being automatically selected when the application or archetype is assessed. + 1. category: Required string category of the target tag. + 2. tag: Required string for the target tag. + +> [!NOTE] +> 1. Anything with the word **required** must be filed out. Otherwise, the yaml will not validate on upload. +> 2. Each subsection defines a new struct/object in yaml. For instance + +> ```yaml +> ... +> name: Testing +> thresholds: +> red: 30 +> yellow: 45 +> unknown: 5 +> ... +> ``` + + diff --git a/encryption/aes.go b/encryption/aes.go index d6f2c73e3..8b21dffaf 100644 --- a/encryption/aes.go +++ b/encryption/aes.go @@ -8,14 +8,12 @@ import ( "io" ) -// // AES encryption. type AES struct { // Key Length must be (12|24|32). Key []byte } -// // Encrypt plain string. // Returns an AES encrypted; base64 encoded string. func (r *AES) Encrypt(plain string) (encrypted string, err error) { @@ -39,7 +37,6 @@ func (r *AES) Encrypt(plain string) (encrypted string, err error) { return } -// // Decrypt and AES encrypted string. // The `encrypted` string is an AES encrypted; base64 encoded string. // Returns the decoded string. @@ -67,7 +64,6 @@ func (r *AES) Decrypt(encrypted string) (plain string, err error) { return } -// // With Sets the key using the passphrase. // Only the first 32 bytes of the passphrase are used. func (r *AES) With(passphrase string) { @@ -83,21 +79,18 @@ func (r *AES) With(passphrase string) { } } -// // encode string. func (r *AES) encode(in []byte) (out string) { out = base64.StdEncoding.EncodeToString(in) return } -// // decode bytes. func (r *AES) decode(in string) (out []byte, err error) { out, err = base64.StdEncoding.DecodeString(in) return } -// // New AES encryptor for passphrase. func New(passphrase string) (n *AES) { n = &AES{} diff --git a/encryption/aes_test.go b/encryption/aes_test.go index 7b48640f7..e7c502652 100644 --- a/encryption/aes_test.go +++ b/encryption/aes_test.go @@ -1,8 +1,9 @@ package encryption import ( - "github.com/onsi/gomega" "testing" + + "github.com/onsi/gomega" ) func TestAES(t *testing.T) { diff --git a/go.mod b/go.mod index 2c6b55e11..ea271b33d 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/konveyor/tackle2-hub -go 1.18 +go 1.20 require ( github.com/Nerzal/gocloak/v10 v10.0.1 @@ -25,6 +25,7 @@ require ( k8s.io/apimachinery v0.25.0 k8s.io/apiserver v0.25.0 k8s.io/client-go v0.25.0 + k8s.io/utils v0.0.0-20220728103510-ee6ede2d64ed sigs.k8s.io/controller-runtime v0.13.1 ) @@ -100,7 +101,6 @@ require ( k8s.io/component-base v0.25.0 // indirect k8s.io/klog/v2 v2.70.1 // indirect k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1 // indirect - k8s.io/utils v0.0.0-20220728103510-ee6ede2d64ed // indirect sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect sigs.k8s.io/yaml v1.3.0 // indirect diff --git a/importer/manager.go b/importer/manager.go index 575e71528..651eedf15 100644 --- a/importer/manager.go +++ b/importer/manager.go @@ -6,22 +6,21 @@ import ( "fmt" "regexp" + "strings" + "time" + liberr "github.com/jortel/go-utils/error" "github.com/konveyor/tackle2-hub/api" "github.com/konveyor/tackle2-hub/model" "gorm.io/gorm" - "strings" - "time" ) -// // Manager for processing application imports. type Manager struct { // DB DB *gorm.DB } -// // Run the manager. func (m *Manager) Run(ctx context.Context) { go func() { @@ -37,7 +36,6 @@ func (m *Manager) Run(ctx context.Context) { }() } -// // processImports creates applications and dependencies from // unprocessed imports. func (m *Manager) processImports() (err error) { @@ -75,7 +73,6 @@ func (m *Manager) processImports() (err error) { return } -// // createDependency creates an application dependency from // a dependency import record. func (m *Manager) createDependency(imp *model.Import) (ok bool) { @@ -115,7 +112,6 @@ func (m *Manager) createDependency(imp *model.Import) (ok bool) { return } -// // createApplication creates an application from an // application import record. func (m *Manager) createApplication(imp *model.Import) (ok bool) { @@ -362,7 +358,6 @@ func (m *Manager) findStakeholder(email string) (stakeholder model.Stakeholder, return } -// // normalizedName transforms given name to be comparable as same with similar names // Example: normalizedName(" F oo-123 bar! ") returns "foo123bar!" func normalizedName(name string) (normName string) { @@ -372,7 +367,6 @@ func normalizedName(name string) (normName string) { return } -// // parseStakeholder attempts to parse a stakeholder's name and an email address // out of a string like `John Smith `. The pattern is very // simple and treats anything before the first bracket as the name, diff --git a/k8s/api/tackle/v1alpha1/addon.go b/k8s/api/tackle/v1alpha1/addon.go index fb22b7b92..b01f370ef 100644 --- a/k8s/api/tackle/v1alpha1/addon.go +++ b/k8s/api/tackle/v1alpha1/addon.go @@ -21,7 +21,6 @@ import ( meta "k8s.io/apimachinery/pkg/apis/meta/v1" ) -// // AddonSpec defines the desired state of Addon type AddonSpec struct { // Addon fqin. @@ -34,7 +33,6 @@ type AddonSpec struct { Resources core.ResourceRequirements `json:"resources,omitempty"` } -// // AddonStatus defines the observed state of Addon type AddonStatus struct { // The most recent generation observed by the controller. @@ -42,7 +40,6 @@ type AddonStatus struct { ObservedGeneration int64 `json:"observedGeneration,omitempty"` } -// // +genclient // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // +k8s:openapi-gen=true @@ -56,7 +53,6 @@ type Addon struct { Status AddonStatus `json:"status,omitempty"` } -// // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object type AddonList struct { meta.TypeMeta `json:",inline"` diff --git a/k8s/api/tackle/v1alpha1/tackle.go b/k8s/api/tackle/v1alpha1/tackle.go index 766e01b49..fbbe22c90 100644 --- a/k8s/api/tackle/v1alpha1/tackle.go +++ b/k8s/api/tackle/v1alpha1/tackle.go @@ -20,7 +20,6 @@ import ( meta "k8s.io/apimachinery/pkg/apis/meta/v1" ) -// // +genclient // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // +k8s:openapi-gen=true @@ -33,7 +32,6 @@ type Tackle struct { meta.ObjectMeta `json:"metadata,omitempty"` } -// // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object type TackleList struct { meta.TypeMeta `json:",inline"` diff --git a/k8s/client.go b/k8s/client.go index e688cbe8d..3051d86c8 100644 --- a/k8s/client.go +++ b/k8s/client.go @@ -2,6 +2,7 @@ package k8s import ( "context" + liberr "github.com/jortel/go-utils/error" "github.com/konveyor/tackle2-hub/settings" "k8s.io/apimachinery/pkg/api/meta" @@ -13,7 +14,6 @@ import ( var Settings = &settings.Settings -// // NewClient builds new k8s client. func NewClient() (newClient client.Client, err error) { if Settings.Disconnected { diff --git a/metrics/manager.go b/metrics/manager.go index 292a1db3a..72d75f5cb 100644 --- a/metrics/manager.go +++ b/metrics/manager.go @@ -2,10 +2,11 @@ package metrics import ( "context" + "time" + "github.com/jortel/go-utils/logr" "github.com/konveyor/tackle2-hub/model" "gorm.io/gorm" - "time" ) var ( @@ -35,7 +36,6 @@ func (m *Manager) Run(ctx context.Context) { }() } -// // gaugeApplications reports the number of applications in inventory func (m *Manager) gaugeApplications() { count := int64(0) diff --git a/migration/migrate.go b/migration/migrate.go index 7f0e38258..cc68493d6 100644 --- a/migration/migrate.go +++ b/migration/migrate.go @@ -3,19 +3,19 @@ package migration import ( "encoding/json" "errors" - liberr "github.com/jortel/go-utils/error" - "github.com/konveyor/tackle2-hub/database" - "github.com/konveyor/tackle2-hub/model" - "github.com/konveyor/tackle2-hub/nas" - "gorm.io/gorm" "os" "path" "regexp" "strconv" "strings" + + liberr "github.com/jortel/go-utils/error" + "github.com/konveyor/tackle2-hub/database" + "github.com/konveyor/tackle2-hub/model" + "github.com/konveyor/tackle2-hub/nas" + "gorm.io/gorm" ) -// // Migrate the hub by applying all necessary Migrations. func Migrate(migrations []Migration) (err error) { var db *gorm.DB @@ -109,7 +109,6 @@ func Migrate(migrations []Migration) (err error) { return } -// // Set the version record. func setVersion(db *gorm.DB, version int) (err error) { setting := &model.Setting{Key: VersionKey} @@ -124,7 +123,6 @@ func setVersion(db *gorm.DB, version int) (err error) { return } -// // AutoMigrate the database. func autoMigrate(db *gorm.DB, models []interface{}) (err error) { db, err = database.Open(false) @@ -145,7 +143,6 @@ func autoMigrate(db *gorm.DB, models []interface{}) (err error) { return } -// // writeSchema - writes the migrated schema to a file. func writeSchema(db *gorm.DB, version int) (err error) { var list []struct { diff --git a/migration/migrate_test.go b/migration/migrate_test.go index c3d34f37d..7fcb1f6ad 100644 --- a/migration/migrate_test.go +++ b/migration/migrate_test.go @@ -2,12 +2,13 @@ package migration import ( "encoding/json" + "os" + "testing" + "github.com/konveyor/tackle2-hub/database" "github.com/konveyor/tackle2-hub/model" "github.com/onsi/gomega" "gorm.io/gorm" - "os" - "testing" ) func TestFreshInstall(t *testing.T) { diff --git a/migration/pkg.go b/migration/pkg.go index 61a0c99d9..1bb72b55f 100644 --- a/migration/pkg.go +++ b/migration/pkg.go @@ -5,7 +5,7 @@ import ( v10 "github.com/konveyor/tackle2-hub/migration/v10" v11 "github.com/konveyor/tackle2-hub/migration/v11" v12 "github.com/konveyor/tackle2-hub/migration/v12" - "github.com/konveyor/tackle2-hub/migration/v2" + v2 "github.com/konveyor/tackle2-hub/migration/v2" v3 "github.com/konveyor/tackle2-hub/migration/v3" v4 "github.com/konveyor/tackle2-hub/migration/v4" v5 "github.com/konveyor/tackle2-hub/migration/v5" @@ -20,29 +20,24 @@ import ( var log = logr.WithName("migration") var Settings = &settings.Settings -// // VersionKey is the setting containing the migration version. const VersionKey = ".migration.version" -// // MinimumVersion is the index of the // earliest version that we can migrate from. var MinimumVersion = 1 -// // Version represents the value of the .migration.version setting. type Version struct { Version int `json:"version"` } -// // Migration encapsulates the functionality necessary to perform a migration. type Migration interface { Apply(*gorm.DB) error Models() []interface{} } -// // All migrations in order. func All() []Migration { return []Migration{ diff --git a/migration/v10/model/analysis.go b/migration/v10/model/analysis.go index 34efb6de2..d3b425d8f 100644 --- a/migration/v10/model/analysis.go +++ b/migration/v10/model/analysis.go @@ -2,7 +2,6 @@ package model import "gorm.io/gorm" -// // Analysis report. type Analysis struct { Model @@ -15,7 +14,6 @@ type Analysis struct { Application *Application } -// // TechDependency report dependency. type TechDependency struct { Model @@ -29,7 +27,6 @@ type TechDependency struct { Analysis *Analysis } -// // Issue report issue (violation). type Issue struct { Model @@ -47,7 +44,6 @@ type Issue struct { Analysis *Analysis } -// // Incident report an issue incident. type Incident struct { Model @@ -60,14 +56,12 @@ type Incident struct { Issue *Issue } -// // Link URL link. type Link struct { URL string `json:"url"` Title string `json:"title,omitempty"` } -// // ArchivedIssue resource created when issues are archived. type ArchivedIssue struct { RuleSet string `json:"ruleSet"` @@ -79,7 +73,6 @@ type ArchivedIssue struct { Incidents int `json:"incidents"` } -// // RuleSet - Analysis ruleset. type RuleSet struct { Model @@ -98,7 +91,6 @@ func (r *RuleSet) Builtin() bool { return r.UUID != nil } -// // BeforeUpdate hook to avoid cyclic dependencies. func (r *RuleSet) BeforeUpdate(db *gorm.DB) (err error) { seen := make(map[uint]bool) @@ -132,7 +124,6 @@ func (r *RuleSet) BeforeUpdate(db *gorm.DB) (err error) { return } -// // Rule - Analysis rule. type Rule struct { Model @@ -145,7 +136,6 @@ type Rule struct { File *File } -// // Target - analysis rule selector. type Target struct { Model diff --git a/migration/v10/model/application.go b/migration/v10/model/application.go index 64e1e52a2..f68476e8a 100644 --- a/migration/v10/model/application.go +++ b/migration/v10/model/application.go @@ -2,9 +2,10 @@ package model import ( "fmt" - "gorm.io/gorm" "sync" "time" + + "gorm.io/gorm" ) type Application struct { @@ -40,7 +41,6 @@ type Fact struct { Application *Application } -// // ApplicationTag represents a row in the join table for the // many-to-many relationship between Applications and Tags. type ApplicationTag struct { @@ -51,14 +51,12 @@ type ApplicationTag struct { Tag Tag `gorm:"constraint:OnDelete:CASCADE"` } -// // TableName must return "ApplicationTags" to ensure compatibility // with the autogenerated join table name. func (ApplicationTag) TableName() string { return "ApplicationTags" } -// // depMutex ensures Dependency.Create() is not executed concurrently. var depMutex sync.Mutex @@ -70,7 +68,6 @@ type Dependency struct { From *Application `gorm:"foreignKey:FromID;constraint:OnDelete:CASCADE"` } -// // Create a dependency synchronized using a mutex. func (r *Dependency) Create(db *gorm.DB) (err error) { depMutex.Lock() @@ -79,7 +76,6 @@ func (r *Dependency) Create(db *gorm.DB) (err error) { return } -// // Validation Hook to avoid cyclic dependencies. func (r *Dependency) BeforeCreate(db *gorm.DB) (err error) { var nextDeps []*Dependency @@ -100,7 +96,6 @@ func (r *Dependency) BeforeCreate(db *gorm.DB) (err error) { return } -// // Custom error type to allow API recognize Cyclic Dependency error and assign proper status code. type DependencyCyclicError struct{} diff --git a/migration/v10/model/assessment.go b/migration/v10/model/assessment.go index a8cc0b6fe..3a734e86e 100644 --- a/migration/v10/model/assessment.go +++ b/migration/v10/model/assessment.go @@ -12,7 +12,6 @@ type Questionnaire struct { Assessments []Assessment `gorm:"constraint:OnDelete:CASCADE"` } -// // Builtin returns true if this is a Konveyor-provided questionnaire. func (r *Questionnaire) Builtin() bool { return r.UUID != nil diff --git a/migration/v10/model/core.go b/migration/v10/model/core.go index fca0b85ab..637c0d879 100644 --- a/migration/v10/model/core.go +++ b/migration/v10/model/core.go @@ -3,16 +3,16 @@ package model import ( "encoding/json" "fmt" + "os" + "path" + "time" + "github.com/google/uuid" liberr "github.com/jortel/go-utils/error" "github.com/konveyor/tackle2-hub/encryption" "gorm.io/gorm" - "os" - "path" - "time" ) -// // Model Base model. type Model struct { ID uint `gorm:"<-:create;primaryKey"` @@ -27,7 +27,6 @@ type Setting struct { Value JSON `gorm:"type:json"` } -// // With updates the value of the Setting with the json representation // of the `value` parameter. func (r *Setting) With(value interface{}) (err error) { @@ -38,7 +37,6 @@ func (r *Setting) With(value interface{}) (err error) { return } -// // As unmarshalls the value of the Setting into the `ptr` parameter. func (r *Setting) As(ptr interface{}) (err error) { err = json.Unmarshal(r.Value, ptr) @@ -156,7 +154,6 @@ func (m *Task) BeforeCreate(db *gorm.DB) (err error) { return } -// // Error appends an error. func (m *Task) Error(severity, description string, x ...interface{}) { var list []TaskError @@ -167,11 +164,9 @@ func (m *Task) Error(severity, description string, x ...interface{}) { m.Errors, _ = json.Marshal(list) } -// // Map alias. type Map = map[string]interface{} -// // TTL time-to-live. type TTL struct { Created int `json:"created,omitempty"` @@ -182,7 +177,6 @@ type TTL struct { Failed int `json:"failed,omitempty"` } -// // TaskError used in Task.Errors. type TaskError struct { Severity string `json:"severity"` @@ -212,7 +206,6 @@ type TaskGroup struct { State string } -// // Propagate group data into the task. func (m *TaskGroup) Propagate() (err error) { for i := range m.Tasks { @@ -249,7 +242,6 @@ func (m *TaskGroup) Propagate() (err error) { return } -// // merge maps B into A. // The B map is the authority. func (m *TaskGroup) merge(a, b Map) (out Map) { @@ -286,7 +278,6 @@ func (m *TaskGroup) merge(a, b Map) (out Map) { return } -// // Proxy configuration. // kind = (http|https) type Proxy struct { diff --git a/migration/v10/model/pkg.go b/migration/v10/model/pkg.go index 46c071c59..2ba843598 100644 --- a/migration/v10/model/pkg.go +++ b/migration/v10/model/pkg.go @@ -6,11 +6,9 @@ var ( Settings = &settings.Settings ) -// // JSON field (data) type. type JSON = []byte -// // All builds all models. // Models are enumerated such that each are listed after // all the other models on which they may depend. diff --git a/migration/v11/model/analysis.go b/migration/v11/model/analysis.go index e7e297af6..6869a5bc4 100644 --- a/migration/v11/model/analysis.go +++ b/migration/v11/model/analysis.go @@ -2,7 +2,6 @@ package model import "gorm.io/gorm" -// // Analysis report. type Analysis struct { Model @@ -15,7 +14,6 @@ type Analysis struct { Application *Application } -// // TechDependency report dependency. type TechDependency struct { Model @@ -29,7 +27,6 @@ type TechDependency struct { Analysis *Analysis } -// // Issue report issue (violation). type Issue struct { Model @@ -47,7 +44,6 @@ type Issue struct { Analysis *Analysis } -// // Incident report an issue incident. type Incident struct { Model @@ -60,14 +56,12 @@ type Incident struct { Issue *Issue } -// // Link URL link. type Link struct { URL string `json:"url"` Title string `json:"title,omitempty"` } -// // ArchivedIssue resource created when issues are archived. type ArchivedIssue struct { RuleSet string `json:"ruleSet"` @@ -79,7 +73,6 @@ type ArchivedIssue struct { Incidents int `json:"incidents"` } -// // RuleSet - Analysis ruleset. type RuleSet struct { Model @@ -98,7 +91,6 @@ func (r *RuleSet) Builtin() bool { return r.UUID != nil } -// // BeforeUpdate hook to avoid cyclic dependencies. func (r *RuleSet) BeforeUpdate(db *gorm.DB) (err error) { seen := make(map[uint]bool) @@ -132,7 +124,6 @@ func (r *RuleSet) BeforeUpdate(db *gorm.DB) (err error) { return } -// // Rule - Analysis rule. type Rule struct { Model @@ -145,7 +136,6 @@ type Rule struct { File *File } -// // Target - analysis rule selector. type Target struct { Model diff --git a/migration/v11/model/application.go b/migration/v11/model/application.go index f6c1586c2..1bd928758 100644 --- a/migration/v11/model/application.go +++ b/migration/v11/model/application.go @@ -2,9 +2,10 @@ package model import ( "fmt" - "gorm.io/gorm" "sync" "time" + + "gorm.io/gorm" ) type Application struct { @@ -40,7 +41,6 @@ type Fact struct { Application *Application } -// // ApplicationTag represents a row in the join table for the // many-to-many relationship between Applications and Tags. type ApplicationTag struct { @@ -51,14 +51,12 @@ type ApplicationTag struct { Tag Tag `gorm:"constraint:OnDelete:CASCADE"` } -// // TableName must return "ApplicationTags" to ensure compatibility // with the autogenerated join table name. func (ApplicationTag) TableName() string { return "ApplicationTags" } -// // depMutex ensures Dependency.Create() is not executed concurrently. var depMutex sync.Mutex @@ -70,7 +68,6 @@ type Dependency struct { From *Application `gorm:"foreignKey:FromID;constraint:OnDelete:CASCADE"` } -// // Create a dependency synchronized using a mutex. func (r *Dependency) Create(db *gorm.DB) (err error) { depMutex.Lock() @@ -79,7 +76,6 @@ func (r *Dependency) Create(db *gorm.DB) (err error) { return } -// // Validation Hook to avoid cyclic dependencies. func (r *Dependency) BeforeCreate(db *gorm.DB) (err error) { var nextDeps []*Dependency @@ -100,7 +96,6 @@ func (r *Dependency) BeforeCreate(db *gorm.DB) (err error) { return } -// // Custom error type to allow API recognize Cyclic Dependency error and assign proper status code. type DependencyCyclicError struct{} diff --git a/migration/v11/model/assessment.go b/migration/v11/model/assessment.go index a8cc0b6fe..3a734e86e 100644 --- a/migration/v11/model/assessment.go +++ b/migration/v11/model/assessment.go @@ -12,7 +12,6 @@ type Questionnaire struct { Assessments []Assessment `gorm:"constraint:OnDelete:CASCADE"` } -// // Builtin returns true if this is a Konveyor-provided questionnaire. func (r *Questionnaire) Builtin() bool { return r.UUID != nil diff --git a/migration/v11/model/core.go b/migration/v11/model/core.go index fca0b85ab..637c0d879 100644 --- a/migration/v11/model/core.go +++ b/migration/v11/model/core.go @@ -3,16 +3,16 @@ package model import ( "encoding/json" "fmt" + "os" + "path" + "time" + "github.com/google/uuid" liberr "github.com/jortel/go-utils/error" "github.com/konveyor/tackle2-hub/encryption" "gorm.io/gorm" - "os" - "path" - "time" ) -// // Model Base model. type Model struct { ID uint `gorm:"<-:create;primaryKey"` @@ -27,7 +27,6 @@ type Setting struct { Value JSON `gorm:"type:json"` } -// // With updates the value of the Setting with the json representation // of the `value` parameter. func (r *Setting) With(value interface{}) (err error) { @@ -38,7 +37,6 @@ func (r *Setting) With(value interface{}) (err error) { return } -// // As unmarshalls the value of the Setting into the `ptr` parameter. func (r *Setting) As(ptr interface{}) (err error) { err = json.Unmarshal(r.Value, ptr) @@ -156,7 +154,6 @@ func (m *Task) BeforeCreate(db *gorm.DB) (err error) { return } -// // Error appends an error. func (m *Task) Error(severity, description string, x ...interface{}) { var list []TaskError @@ -167,11 +164,9 @@ func (m *Task) Error(severity, description string, x ...interface{}) { m.Errors, _ = json.Marshal(list) } -// // Map alias. type Map = map[string]interface{} -// // TTL time-to-live. type TTL struct { Created int `json:"created,omitempty"` @@ -182,7 +177,6 @@ type TTL struct { Failed int `json:"failed,omitempty"` } -// // TaskError used in Task.Errors. type TaskError struct { Severity string `json:"severity"` @@ -212,7 +206,6 @@ type TaskGroup struct { State string } -// // Propagate group data into the task. func (m *TaskGroup) Propagate() (err error) { for i := range m.Tasks { @@ -249,7 +242,6 @@ func (m *TaskGroup) Propagate() (err error) { return } -// // merge maps B into A. // The B map is the authority. func (m *TaskGroup) merge(a, b Map) (out Map) { @@ -286,7 +278,6 @@ func (m *TaskGroup) merge(a, b Map) (out Map) { return } -// // Proxy configuration. // kind = (http|https) type Proxy struct { diff --git a/migration/v11/model/pkg.go b/migration/v11/model/pkg.go index 46c071c59..2ba843598 100644 --- a/migration/v11/model/pkg.go +++ b/migration/v11/model/pkg.go @@ -6,11 +6,9 @@ var ( Settings = &settings.Settings ) -// // JSON field (data) type. type JSON = []byte -// // All builds all models. // Models are enumerated such that each are listed after // all the other models on which they may depend. diff --git a/migration/v12/model/analysis.go b/migration/v12/model/analysis.go index e7e297af6..6869a5bc4 100644 --- a/migration/v12/model/analysis.go +++ b/migration/v12/model/analysis.go @@ -2,7 +2,6 @@ package model import "gorm.io/gorm" -// // Analysis report. type Analysis struct { Model @@ -15,7 +14,6 @@ type Analysis struct { Application *Application } -// // TechDependency report dependency. type TechDependency struct { Model @@ -29,7 +27,6 @@ type TechDependency struct { Analysis *Analysis } -// // Issue report issue (violation). type Issue struct { Model @@ -47,7 +44,6 @@ type Issue struct { Analysis *Analysis } -// // Incident report an issue incident. type Incident struct { Model @@ -60,14 +56,12 @@ type Incident struct { Issue *Issue } -// // Link URL link. type Link struct { URL string `json:"url"` Title string `json:"title,omitempty"` } -// // ArchivedIssue resource created when issues are archived. type ArchivedIssue struct { RuleSet string `json:"ruleSet"` @@ -79,7 +73,6 @@ type ArchivedIssue struct { Incidents int `json:"incidents"` } -// // RuleSet - Analysis ruleset. type RuleSet struct { Model @@ -98,7 +91,6 @@ func (r *RuleSet) Builtin() bool { return r.UUID != nil } -// // BeforeUpdate hook to avoid cyclic dependencies. func (r *RuleSet) BeforeUpdate(db *gorm.DB) (err error) { seen := make(map[uint]bool) @@ -132,7 +124,6 @@ func (r *RuleSet) BeforeUpdate(db *gorm.DB) (err error) { return } -// // Rule - Analysis rule. type Rule struct { Model @@ -145,7 +136,6 @@ type Rule struct { File *File } -// // Target - analysis rule selector. type Target struct { Model diff --git a/migration/v12/model/application.go b/migration/v12/model/application.go index f6c1586c2..1bd928758 100644 --- a/migration/v12/model/application.go +++ b/migration/v12/model/application.go @@ -2,9 +2,10 @@ package model import ( "fmt" - "gorm.io/gorm" "sync" "time" + + "gorm.io/gorm" ) type Application struct { @@ -40,7 +41,6 @@ type Fact struct { Application *Application } -// // ApplicationTag represents a row in the join table for the // many-to-many relationship between Applications and Tags. type ApplicationTag struct { @@ -51,14 +51,12 @@ type ApplicationTag struct { Tag Tag `gorm:"constraint:OnDelete:CASCADE"` } -// // TableName must return "ApplicationTags" to ensure compatibility // with the autogenerated join table name. func (ApplicationTag) TableName() string { return "ApplicationTags" } -// // depMutex ensures Dependency.Create() is not executed concurrently. var depMutex sync.Mutex @@ -70,7 +68,6 @@ type Dependency struct { From *Application `gorm:"foreignKey:FromID;constraint:OnDelete:CASCADE"` } -// // Create a dependency synchronized using a mutex. func (r *Dependency) Create(db *gorm.DB) (err error) { depMutex.Lock() @@ -79,7 +76,6 @@ func (r *Dependency) Create(db *gorm.DB) (err error) { return } -// // Validation Hook to avoid cyclic dependencies. func (r *Dependency) BeforeCreate(db *gorm.DB) (err error) { var nextDeps []*Dependency @@ -100,7 +96,6 @@ func (r *Dependency) BeforeCreate(db *gorm.DB) (err error) { return } -// // Custom error type to allow API recognize Cyclic Dependency error and assign proper status code. type DependencyCyclicError struct{} diff --git a/migration/v12/model/assessment.go b/migration/v12/model/assessment.go index a8cc0b6fe..3a734e86e 100644 --- a/migration/v12/model/assessment.go +++ b/migration/v12/model/assessment.go @@ -12,7 +12,6 @@ type Questionnaire struct { Assessments []Assessment `gorm:"constraint:OnDelete:CASCADE"` } -// // Builtin returns true if this is a Konveyor-provided questionnaire. func (r *Questionnaire) Builtin() bool { return r.UUID != nil diff --git a/migration/v12/model/core.go b/migration/v12/model/core.go index 6fb8ce100..60464a929 100644 --- a/migration/v12/model/core.go +++ b/migration/v12/model/core.go @@ -3,16 +3,16 @@ package model import ( "encoding/json" "fmt" + "os" + "path" + "time" + "github.com/google/uuid" liberr "github.com/jortel/go-utils/error" "github.com/konveyor/tackle2-hub/encryption" "gorm.io/gorm" - "os" - "path" - "time" ) -// // Model Base model. type Model struct { ID uint `gorm:"<-:create;primaryKey"` @@ -27,7 +27,6 @@ type Setting struct { Value JSON `gorm:"type:json"` } -// // With updates the value of the Setting with the json representation // of the `value` parameter. func (r *Setting) With(value interface{}) (err error) { @@ -38,7 +37,6 @@ func (r *Setting) With(value interface{}) (err error) { return } -// // As unmarshalls the value of the Setting into the `ptr` parameter. func (r *Setting) As(ptr interface{}) (err error) { err = json.Unmarshal(r.Value, ptr) @@ -156,7 +154,6 @@ func (m *Task) BeforeCreate(db *gorm.DB) (err error) { return } -// // Error appends an error. func (m *Task) Error(severity, description string, x ...interface{}) { var list []TaskError @@ -167,11 +164,9 @@ func (m *Task) Error(severity, description string, x ...interface{}) { m.Errors, _ = json.Marshal(list) } -// // Map alias. type Map = map[string]interface{} -// // TTL time-to-live. type TTL struct { Created int `json:"created,omitempty"` @@ -182,7 +177,6 @@ type TTL struct { Failed int `json:"failed,omitempty"` } -// // TaskError used in Task.Errors. type TaskError struct { Severity string `json:"severity"` @@ -213,7 +207,6 @@ type TaskGroup struct { State string } -// // Propagate group data into the task. func (m *TaskGroup) Propagate() (err error) { for i := range m.Tasks { @@ -250,7 +243,6 @@ func (m *TaskGroup) Propagate() (err error) { return } -// // merge maps B into A. // The B map is the authority. func (m *TaskGroup) merge(a, b Map) (out Map) { @@ -287,7 +279,6 @@ func (m *TaskGroup) merge(a, b Map) (out Map) { return } -// // Proxy configuration. // kind = (http|https) type Proxy struct { diff --git a/migration/v12/model/pkg.go b/migration/v12/model/pkg.go index 46c071c59..2ba843598 100644 --- a/migration/v12/model/pkg.go +++ b/migration/v12/model/pkg.go @@ -6,11 +6,9 @@ var ( Settings = &settings.Settings ) -// // JSON field (data) type. type JSON = []byte -// // All builds all models. // Models are enumerated such that each are listed after // all the other models on which they may depend. diff --git a/migration/v2/model/application.go b/migration/v2/model/application.go index 1c17a8c8a..8d9416969 100644 --- a/migration/v2/model/application.go +++ b/migration/v2/model/application.go @@ -2,8 +2,9 @@ package model import ( "fmt" - "gorm.io/gorm" "sync" + + "gorm.io/gorm" ) type Application struct { @@ -23,7 +24,6 @@ type Application struct { BusinessService *BusinessService } -// // depMutex ensures Dependency.Create() is not executed concurrently. var depMutex sync.Mutex @@ -35,7 +35,6 @@ type Dependency struct { From *Application `gorm:"foreignKey:FromID;constraint:OnDelete:CASCADE"` } -// // Create a dependency synchronized using a mutex. func (r *Dependency) Create(db *gorm.DB) (err error) { depMutex.Lock() @@ -44,7 +43,6 @@ func (r *Dependency) Create(db *gorm.DB) (err error) { return } -// // Validation Hook to avoid cyclic dependencies. func (r *Dependency) BeforeCreate(db *gorm.DB) (err error) { var nextDeps []*Dependency @@ -65,7 +63,6 @@ func (r *Dependency) BeforeCreate(db *gorm.DB) (err error) { return } -// // Custom error type to allow API recognize Cyclic Dependency error and assign proper status code. type DependencyCyclicError struct{} diff --git a/migration/v2/model/core.go b/migration/v2/model/core.go index 32ab4fb82..bd485a6b8 100644 --- a/migration/v2/model/core.go +++ b/migration/v2/model/core.go @@ -2,15 +2,15 @@ package model import ( "encoding/json" - "github.com/google/uuid" - liberr "github.com/jortel/go-utils/error" - "gorm.io/gorm" "os" "path" "time" + + "github.com/google/uuid" + liberr "github.com/jortel/go-utils/error" + "gorm.io/gorm" ) -// // Model Base model. type Model struct { ID uint `gorm:"<-:create;primaryKey"` @@ -84,11 +84,9 @@ func (m *Task) BeforeCreate(db *gorm.DB) (err error) { return } -// // Map alias. type Map = map[string]interface{} -// // TTL time-to-live. type TTL struct { Created int `json:"created,omitempty"` @@ -110,7 +108,6 @@ type TaskGroup struct { State string } -// // Propagate group data into the task. func (m *TaskGroup) Propagate() (err error) { for i := range m.Tasks { @@ -147,7 +144,6 @@ func (m *TaskGroup) Propagate() (err error) { return } -// // merge maps B into A. // The B map is the authority. func (m *TaskGroup) merge(a, b Map) (out Map) { @@ -196,7 +192,6 @@ type TaskReport struct { Task *Task } -// // Proxy configuration. // kind = (http|https) type Proxy struct { @@ -210,7 +205,6 @@ type Proxy struct { Identity *Identity } -// // Identity represents and identity with a set of credentials. type Identity struct { Model diff --git a/migration/v2/model/pkg.go b/migration/v2/model/pkg.go index c895d46c4..b3f6211e7 100644 --- a/migration/v2/model/pkg.go +++ b/migration/v2/model/pkg.go @@ -8,11 +8,9 @@ var ( Settings = &settings.Settings ) -// // JSON field (data) type. type JSON = []byte -// // All builds all models. // Models are enumerated such that each are listed after // all the other models on which they may depend. diff --git a/migration/v2/model/seed.go b/migration/v2/model/seed.go index 7ae95ec53..8f7197dce 100644 --- a/migration/v2/model/seed.go +++ b/migration/v2/model/seed.go @@ -4,7 +4,6 @@ import ( "gorm.io/gorm" ) -// // Seed the database with models. func Seed(db *gorm.DB) { settings := []Setting{ diff --git a/migration/v3/migrate.go b/migration/v3/migrate.go index deed54cb4..00f048c94 100644 --- a/migration/v3/migrate.go +++ b/migration/v3/migrate.go @@ -2,6 +2,7 @@ package v3 import ( "encoding/json" + liberr "github.com/jortel/go-utils/error" "github.com/jortel/go-utils/logr" v2 "github.com/konveyor/tackle2-hub/migration/v2/model" @@ -85,7 +86,6 @@ func (r Migration) Models() []interface{} { return model.All() } -// // factMigration migrates Application.Facts. // This involves changing the Facts type from JSON which maps to // a column in the DB to an ORM virtual field. This, and the data @@ -126,7 +126,6 @@ func (r Migration) factMigration(db *gorm.DB) (err error) { return } -// // bucketMigration migrates buckets. func (r Migration) bucketMigration(db *gorm.DB) (err error) { migrator := db.Migrator() @@ -150,7 +149,6 @@ func (r Migration) bucketMigration(db *gorm.DB) (err error) { return } -// // appBucketMigration migrates application buckets. // The (v2) Application.Bucket (string) contains the bucket storage path. Migration needs to // build a `Bucket` object using this path for each and set v3 BucketID. @@ -195,7 +193,6 @@ func (r Migration) appBucketMigration(db *gorm.DB) (err error) { return } -// // taskBucketMigration migrates task buckets. // The (v2) Task.Bucket (string) contains the bucket storage path. Migration needs to // build a `Bucket` object using this path for each and set v3 BucketID. @@ -240,7 +237,6 @@ func (r Migration) taskBucketMigration(db *gorm.DB) (err error) { return } -// // taskGroupBucketMigration migrates task group buckets. // The (v2) TaskGroup.Bucket (string) contains the bucket storage path. Migration needs to // build a `Bucket` object using this path for each and set v3 BucketID. diff --git a/migration/v3/model/analysis.go b/migration/v3/model/analysis.go index 48e8dafdb..71d16cb3a 100644 --- a/migration/v3/model/analysis.go +++ b/migration/v3/model/analysis.go @@ -1,6 +1,5 @@ package model -// // RuleBundle - Analysis rules. type RuleBundle struct { Model @@ -16,7 +15,6 @@ type RuleBundle struct { RuleSets []RuleSet `gorm:"constraint:OnDelete:CASCADE"` } -// // RuleSet - Analysis ruleset. type RuleSet struct { Model diff --git a/migration/v3/model/application.go b/migration/v3/model/application.go index 9c5db0f16..84050367c 100644 --- a/migration/v3/model/application.go +++ b/migration/v3/model/application.go @@ -2,9 +2,10 @@ package model import ( "fmt" - "gorm.io/gorm" "sync" "time" + + "gorm.io/gorm" ) type Application struct { @@ -31,7 +32,6 @@ type Fact struct { Application *Application } -// // ApplicationTag represents a row in the join table for the // many-to-many relationship between Applications and Tags. type ApplicationTag struct { @@ -42,14 +42,12 @@ type ApplicationTag struct { Tag Tag `gorm:"constraint:OnDelete:CASCADE"` } -// // TableName must return "ApplicationTags" to ensure compatibility // with the autogenerated join table name. func (ApplicationTag) TableName() string { return "ApplicationTags" } -// // depMutex ensures Dependency.Create() is not executed concurrently. var depMutex sync.Mutex @@ -61,7 +59,6 @@ type Dependency struct { From *Application `gorm:"foreignKey:FromID;constraint:OnDelete:CASCADE"` } -// // Create a dependency synchronized using a mutex. func (r *Dependency) Create(db *gorm.DB) (err error) { depMutex.Lock() @@ -70,7 +67,6 @@ func (r *Dependency) Create(db *gorm.DB) (err error) { return } -// // Validation Hook to avoid cyclic dependencies. func (r *Dependency) BeforeCreate(db *gorm.DB) (err error) { var nextDeps []*Dependency @@ -91,7 +87,6 @@ func (r *Dependency) BeforeCreate(db *gorm.DB) (err error) { return } -// // Custom error type to allow API recognize Cyclic Dependency error and assign proper status code. type DependencyCyclicError struct{} diff --git a/migration/v3/model/core.go b/migration/v3/model/core.go index bd253bb69..ac43b6966 100644 --- a/migration/v3/model/core.go +++ b/migration/v3/model/core.go @@ -2,15 +2,15 @@ package model import ( "encoding/json" - "github.com/google/uuid" - liberr "github.com/jortel/go-utils/error" - "gorm.io/gorm" "os" "path" "time" + + "github.com/google/uuid" + liberr "github.com/jortel/go-utils/error" + "gorm.io/gorm" ) -// // Model Base model. type Model struct { ID uint `gorm:"<-:create;primaryKey"` @@ -132,11 +132,9 @@ func (m *Task) BeforeCreate(db *gorm.DB) (err error) { return } -// // Map alias. type Map = map[string]interface{} -// // TTL time-to-live. type TTL struct { Created int `json:"created,omitempty"` @@ -158,7 +156,6 @@ type TaskGroup struct { State string } -// // Propagate group data into the task. func (m *TaskGroup) Propagate() (err error) { for i := range m.Tasks { @@ -195,7 +192,6 @@ func (m *TaskGroup) Propagate() (err error) { return } -// // merge maps B into A. // The B map is the authority. func (m *TaskGroup) merge(a, b Map) (out Map) { @@ -244,7 +240,6 @@ type TaskReport struct { Task *Task } -// // Proxy configuration. // kind = (http|https) type Proxy struct { @@ -258,7 +253,6 @@ type Proxy struct { Identity *Identity } -// // Identity represents and identity with a set of credentials. type Identity struct { Model diff --git a/migration/v3/model/pkg.go b/migration/v3/model/pkg.go index 8a631093e..72de00566 100644 --- a/migration/v3/model/pkg.go +++ b/migration/v3/model/pkg.go @@ -8,11 +8,9 @@ var ( Settings = &settings.Settings ) -// // JSON field (data) type. type JSON = []byte -// // All builds all models. // Models are enumerated such that each are listed after // all the other models on which they may depend. diff --git a/migration/v3/seed/bundle.go b/migration/v3/seed/bundle.go index 05209fe03..1c3025e3e 100644 --- a/migration/v3/seed/bundle.go +++ b/migration/v3/seed/bundle.go @@ -2,12 +2,12 @@ package seed import ( "encoding/json" + "os" + "github.com/konveyor/tackle2-hub/migration/v3/model" "gorm.io/gorm" - "os" ) -// // RuleBundle seed object. type RuleBundle struct { model.RuleBundle @@ -15,7 +15,6 @@ type RuleBundle struct { excluded bool } -// // Create resources and files. func (r *RuleBundle) Create(db *gorm.DB) { r.Image = &model.File{Name: "file.svg"} @@ -37,7 +36,6 @@ func (r *RuleBundle) Create(db *gorm.DB) { _ = db.Create(&r.RuleBundle) } -// // Metadata builds windup metadata. func Metadata(source, target string) (b []byte) { type MD struct { @@ -51,7 +49,6 @@ func Metadata(source, target string) (b []byte) { return } -// // Target builds metadata. func Target(t string) (b []byte) { return Metadata("", t) diff --git a/migration/v4/model/analysis.go b/migration/v4/model/analysis.go index 48e8dafdb..71d16cb3a 100644 --- a/migration/v4/model/analysis.go +++ b/migration/v4/model/analysis.go @@ -1,6 +1,5 @@ package model -// // RuleBundle - Analysis rules. type RuleBundle struct { Model @@ -16,7 +15,6 @@ type RuleBundle struct { RuleSets []RuleSet `gorm:"constraint:OnDelete:CASCADE"` } -// // RuleSet - Analysis ruleset. type RuleSet struct { Model diff --git a/migration/v4/model/application.go b/migration/v4/model/application.go index 071a68440..70e12e1a8 100644 --- a/migration/v4/model/application.go +++ b/migration/v4/model/application.go @@ -2,9 +2,10 @@ package model import ( "fmt" - "gorm.io/gorm" "sync" "time" + + "gorm.io/gorm" ) type Application struct { @@ -36,7 +37,6 @@ type Fact struct { Application *Application } -// // ApplicationTag represents a row in the join table for the // many-to-many relationship between Applications and Tags. type ApplicationTag struct { @@ -47,14 +47,12 @@ type ApplicationTag struct { Tag Tag `gorm:"constraint:OnDelete:CASCADE"` } -// // TableName must return "ApplicationTags" to ensure compatibility // with the autogenerated join table name. func (ApplicationTag) TableName() string { return "ApplicationTags" } -// // depMutex ensures Dependency.Create() is not executed concurrently. var depMutex sync.Mutex @@ -66,7 +64,6 @@ type Dependency struct { From *Application `gorm:"foreignKey:FromID;constraint:OnDelete:CASCADE"` } -// // Create a dependency synchronized using a mutex. func (r *Dependency) Create(db *gorm.DB) (err error) { depMutex.Lock() @@ -75,7 +72,6 @@ func (r *Dependency) Create(db *gorm.DB) (err error) { return } -// // Validation Hook to avoid cyclic dependencies. func (r *Dependency) BeforeCreate(db *gorm.DB) (err error) { var nextDeps []*Dependency @@ -96,7 +92,6 @@ func (r *Dependency) BeforeCreate(db *gorm.DB) (err error) { return } -// // Custom error type to allow API recognize Cyclic Dependency error and assign proper status code. type DependencyCyclicError struct{} diff --git a/migration/v4/model/core.go b/migration/v4/model/core.go index bd253bb69..ac43b6966 100644 --- a/migration/v4/model/core.go +++ b/migration/v4/model/core.go @@ -2,15 +2,15 @@ package model import ( "encoding/json" - "github.com/google/uuid" - liberr "github.com/jortel/go-utils/error" - "gorm.io/gorm" "os" "path" "time" + + "github.com/google/uuid" + liberr "github.com/jortel/go-utils/error" + "gorm.io/gorm" ) -// // Model Base model. type Model struct { ID uint `gorm:"<-:create;primaryKey"` @@ -132,11 +132,9 @@ func (m *Task) BeforeCreate(db *gorm.DB) (err error) { return } -// // Map alias. type Map = map[string]interface{} -// // TTL time-to-live. type TTL struct { Created int `json:"created,omitempty"` @@ -158,7 +156,6 @@ type TaskGroup struct { State string } -// // Propagate group data into the task. func (m *TaskGroup) Propagate() (err error) { for i := range m.Tasks { @@ -195,7 +192,6 @@ func (m *TaskGroup) Propagate() (err error) { return } -// // merge maps B into A. // The B map is the authority. func (m *TaskGroup) merge(a, b Map) (out Map) { @@ -244,7 +240,6 @@ type TaskReport struct { Task *Task } -// // Proxy configuration. // kind = (http|https) type Proxy struct { @@ -258,7 +253,6 @@ type Proxy struct { Identity *Identity } -// // Identity represents and identity with a set of credentials. type Identity struct { Model diff --git a/migration/v4/model/pkg.go b/migration/v4/model/pkg.go index f333361bb..2f09a63c7 100644 --- a/migration/v4/model/pkg.go +++ b/migration/v4/model/pkg.go @@ -8,11 +8,9 @@ var ( Settings = &settings.Settings ) -// // JSON field (data) type. type JSON = []byte -// // All builds all models. // Models are enumerated such that each are listed after // all the other models on which they may depend. diff --git a/migration/v5/migrate.go b/migration/v5/migrate.go index 14cc284ce..c81705292 100644 --- a/migration/v5/migrate.go +++ b/migration/v5/migrate.go @@ -3,6 +3,7 @@ package v5 import ( "encoding/json" "fmt" + liberr "github.com/jortel/go-utils/error" "github.com/jortel/go-utils/logr" v3 "github.com/konveyor/tackle2-hub/migration/v3/model" @@ -130,7 +131,6 @@ func (r Migration) migrateRuleBundles(db *gorm.DB) (err error) { return } -// // updateBundleSeed updates the description for Open Liberty. func (r Migration) updateBundleSeed(db *gorm.DB) (err error) { db = db.Model(&model.RuleSet{}) @@ -142,7 +142,6 @@ func (r Migration) updateBundleSeed(db *gorm.DB) (err error) { return } -// // migrateIdentitiesUniqName de-duplicates identity names. func (r Migration) migrateIdentitiesUniqName(db *gorm.DB) (err error) { var identities []v3.Identity diff --git a/migration/v5/model/analysis.go b/migration/v5/model/analysis.go index 3624852ea..134799a95 100644 --- a/migration/v5/model/analysis.go +++ b/migration/v5/model/analysis.go @@ -1,6 +1,5 @@ package model -// // Analysis report. type Analysis struct { Model @@ -11,7 +10,6 @@ type Analysis struct { Application *Application } -// // TechDependency report dependency. type TechDependency struct { Model @@ -24,7 +22,6 @@ type TechDependency struct { Analysis *Analysis } -// // Issue report issue (violation). type Issue struct { Model @@ -42,7 +39,6 @@ type Issue struct { Analysis *Analysis } -// // Incident report an issue incident. type Incident struct { Model @@ -55,14 +51,12 @@ type Incident struct { Issue *Issue } -// // Link URL link. type Link struct { URL string `json:"url"` Title string `json:"title,omitempty"` } -// // RuleSet - Analysis ruleset. type RuleSet struct { Model @@ -78,7 +72,6 @@ type RuleSet struct { Rules []Rule `gorm:"constraint:OnDelete:CASCADE"` } -// // Rule - Analysis rule. type Rule struct { Model diff --git a/migration/v5/model/application.go b/migration/v5/model/application.go index aae434219..6049278da 100644 --- a/migration/v5/model/application.go +++ b/migration/v5/model/application.go @@ -2,9 +2,10 @@ package model import ( "fmt" - "gorm.io/gorm" "sync" "time" + + "gorm.io/gorm" ) type Application struct { @@ -39,7 +40,6 @@ type Fact struct { Application *Application } -// // ApplicationTag represents a row in the join table for the // many-to-many relationship between Applications and Tags. type ApplicationTag struct { @@ -50,14 +50,12 @@ type ApplicationTag struct { Tag Tag `gorm:"constraint:OnDelete:CASCADE"` } -// // TableName must return "ApplicationTags" to ensure compatibility // with the autogenerated join table name. func (ApplicationTag) TableName() string { return "ApplicationTags" } -// // depMutex ensures Dependency.Create() is not executed concurrently. var depMutex sync.Mutex @@ -69,7 +67,6 @@ type Dependency struct { From *Application `gorm:"foreignKey:FromID;constraint:OnDelete:CASCADE"` } -// // Create a dependency synchronized using a mutex. func (r *Dependency) Create(db *gorm.DB) (err error) { depMutex.Lock() @@ -78,7 +75,6 @@ func (r *Dependency) Create(db *gorm.DB) (err error) { return } -// // Validation Hook to avoid cyclic dependencies. func (r *Dependency) BeforeCreate(db *gorm.DB) (err error) { var nextDeps []*Dependency @@ -99,7 +95,6 @@ func (r *Dependency) BeforeCreate(db *gorm.DB) (err error) { return } -// // Custom error type to allow API recognize Cyclic Dependency error and assign proper status code. type DependencyCyclicError struct{} diff --git a/migration/v5/model/core.go b/migration/v5/model/core.go index a64b1e5b7..0fb5a3312 100644 --- a/migration/v5/model/core.go +++ b/migration/v5/model/core.go @@ -2,16 +2,16 @@ package model import ( "encoding/json" + "os" + "path" + "time" + "github.com/google/uuid" liberr "github.com/jortel/go-utils/error" "github.com/konveyor/tackle2-hub/encryption" "gorm.io/gorm" - "os" - "path" - "time" ) -// // Model Base model. type Model struct { ID uint `gorm:"<-:create;primaryKey"` @@ -133,11 +133,9 @@ func (m *Task) BeforeCreate(db *gorm.DB) (err error) { return } -// // Map alias. type Map = map[string]interface{} -// // TTL time-to-live. type TTL struct { Created int `json:"created,omitempty"` @@ -159,7 +157,6 @@ type TaskGroup struct { State string } -// // Propagate group data into the task. func (m *TaskGroup) Propagate() (err error) { for i := range m.Tasks { @@ -196,7 +193,6 @@ func (m *TaskGroup) Propagate() (err error) { return } -// // merge maps B into A. // The B map is the authority. func (m *TaskGroup) merge(a, b Map) (out Map) { @@ -245,7 +241,6 @@ type TaskReport struct { Task *Task } -// // Proxy configuration. // kind = (http|https) type Proxy struct { diff --git a/migration/v5/model/pkg.go b/migration/v5/model/pkg.go index 4ce2479de..17b80b721 100644 --- a/migration/v5/model/pkg.go +++ b/migration/v5/model/pkg.go @@ -8,11 +8,9 @@ var ( Settings = &settings.Settings ) -// // JSON field (data) type. type JSON = []byte -// // All builds all models. // Models are enumerated such that each are listed after // all the other models on which they may depend. diff --git a/migration/v6/migrate.go b/migration/v6/migrate.go index de8f9e4b2..b285e559a 100644 --- a/migration/v6/migrate.go +++ b/migration/v6/migrate.go @@ -2,6 +2,7 @@ package v6 import ( "encoding/json" + "github.com/jortel/go-utils/logr" "github.com/konveyor/tackle2-hub/migration/v6/model" "gorm.io/gorm" diff --git a/migration/v6/model/analysis.go b/migration/v6/model/analysis.go index 43f3e8e1a..790451a4d 100644 --- a/migration/v6/model/analysis.go +++ b/migration/v6/model/analysis.go @@ -2,7 +2,6 @@ package model import "gorm.io/gorm" -// // Analysis report. type Analysis struct { Model @@ -13,7 +12,6 @@ type Analysis struct { Application *Application } -// // TechDependency report dependency. type TechDependency struct { Model @@ -27,7 +25,6 @@ type TechDependency struct { Analysis *Analysis } -// // Issue report issue (violation). type Issue struct { Model @@ -45,7 +42,6 @@ type Issue struct { Analysis *Analysis } -// // Incident report an issue incident. type Incident struct { Model @@ -58,14 +54,12 @@ type Incident struct { Issue *Issue } -// // Link URL link. type Link struct { URL string `json:"url"` Title string `json:"title,omitempty"` } -// // RuleSet - Analysis ruleset. type RuleSet struct { Model @@ -82,7 +76,6 @@ type RuleSet struct { DependsOn []RuleSet `gorm:"many2many:RuleSetDependencies;constraint:OnDelete:CASCADE"` } -// // BeforeUpdate hook to avoid cyclic dependencies. func (r *RuleSet) BeforeUpdate(db *gorm.DB) (err error) { seen := make(map[uint]bool) @@ -116,7 +109,6 @@ func (r *RuleSet) BeforeUpdate(db *gorm.DB) (err error) { return } -// // Rule - Analysis rule. type Rule struct { Model diff --git a/migration/v6/model/application.go b/migration/v6/model/application.go index aae434219..6049278da 100644 --- a/migration/v6/model/application.go +++ b/migration/v6/model/application.go @@ -2,9 +2,10 @@ package model import ( "fmt" - "gorm.io/gorm" "sync" "time" + + "gorm.io/gorm" ) type Application struct { @@ -39,7 +40,6 @@ type Fact struct { Application *Application } -// // ApplicationTag represents a row in the join table for the // many-to-many relationship between Applications and Tags. type ApplicationTag struct { @@ -50,14 +50,12 @@ type ApplicationTag struct { Tag Tag `gorm:"constraint:OnDelete:CASCADE"` } -// // TableName must return "ApplicationTags" to ensure compatibility // with the autogenerated join table name. func (ApplicationTag) TableName() string { return "ApplicationTags" } -// // depMutex ensures Dependency.Create() is not executed concurrently. var depMutex sync.Mutex @@ -69,7 +67,6 @@ type Dependency struct { From *Application `gorm:"foreignKey:FromID;constraint:OnDelete:CASCADE"` } -// // Create a dependency synchronized using a mutex. func (r *Dependency) Create(db *gorm.DB) (err error) { depMutex.Lock() @@ -78,7 +75,6 @@ func (r *Dependency) Create(db *gorm.DB) (err error) { return } -// // Validation Hook to avoid cyclic dependencies. func (r *Dependency) BeforeCreate(db *gorm.DB) (err error) { var nextDeps []*Dependency @@ -99,7 +95,6 @@ func (r *Dependency) BeforeCreate(db *gorm.DB) (err error) { return } -// // Custom error type to allow API recognize Cyclic Dependency error and assign proper status code. type DependencyCyclicError struct{} diff --git a/migration/v6/model/core.go b/migration/v6/model/core.go index 6d6557ae6..f0b2d05a5 100644 --- a/migration/v6/model/core.go +++ b/migration/v6/model/core.go @@ -3,16 +3,16 @@ package model import ( "encoding/json" "fmt" + "os" + "path" + "time" + "github.com/google/uuid" liberr "github.com/jortel/go-utils/error" "github.com/konveyor/tackle2-hub/encryption" "gorm.io/gorm" - "os" - "path" - "time" ) -// // Model Base model. type Model struct { ID uint `gorm:"<-:create;primaryKey"` @@ -134,7 +134,6 @@ func (m *Task) BeforeCreate(db *gorm.DB) (err error) { return } -// // Error appends an error. func (m *Task) Error(severity, description string, x ...interface{}) { var list []TaskError @@ -145,11 +144,9 @@ func (m *Task) Error(severity, description string, x ...interface{}) { m.Errors, _ = json.Marshal(list) } -// // Map alias. type Map = map[string]interface{} -// // TTL time-to-live. type TTL struct { Created int `json:"created,omitempty"` @@ -160,7 +157,6 @@ type TTL struct { Failed int `json:"failed,omitempty"` } -// // TaskError used in Task.Errors. type TaskError struct { Severity string `json:"severity"` @@ -190,7 +186,6 @@ type TaskGroup struct { State string } -// // Propagate group data into the task. func (m *TaskGroup) Propagate() (err error) { for i := range m.Tasks { @@ -227,7 +222,6 @@ func (m *TaskGroup) Propagate() (err error) { return } -// // merge maps B into A. // The B map is the authority. func (m *TaskGroup) merge(a, b Map) (out Map) { @@ -264,7 +258,6 @@ func (m *TaskGroup) merge(a, b Map) (out Map) { return } -// // Proxy configuration. // kind = (http|https) type Proxy struct { diff --git a/migration/v6/model/pkg.go b/migration/v6/model/pkg.go index 33c97725e..9e842a5b5 100644 --- a/migration/v6/model/pkg.go +++ b/migration/v6/model/pkg.go @@ -6,11 +6,9 @@ var ( Settings = &settings.Settings ) -// // JSON field (data) type. type JSON = []byte -// // All builds all models. // Models are enumerated such that each are listed after // all the other models on which they may depend. diff --git a/migration/v7/model/analysis.go b/migration/v7/model/analysis.go index a3f1ea1f2..096a4f36d 100644 --- a/migration/v7/model/analysis.go +++ b/migration/v7/model/analysis.go @@ -2,7 +2,6 @@ package model import "gorm.io/gorm" -// // Analysis report. type Analysis struct { Model @@ -13,7 +12,6 @@ type Analysis struct { Application *Application } -// // TechDependency report dependency. type TechDependency struct { Model @@ -27,7 +25,6 @@ type TechDependency struct { Analysis *Analysis } -// // Issue report issue (violation). type Issue struct { Model @@ -45,7 +42,6 @@ type Issue struct { Analysis *Analysis } -// // Incident report an issue incident. type Incident struct { Model @@ -58,14 +54,12 @@ type Incident struct { Issue *Issue } -// // Link URL link. type Link struct { URL string `json:"url"` Title string `json:"title,omitempty"` } -// // RuleSet - Analysis ruleset. type RuleSet struct { Model @@ -83,7 +77,6 @@ type RuleSet struct { DependsOn []RuleSet `gorm:"many2many:RuleSetDependencies;constraint:OnDelete:CASCADE"` } -// // BeforeUpdate hook to avoid cyclic dependencies. func (r *RuleSet) BeforeUpdate(db *gorm.DB) (err error) { seen := make(map[uint]bool) @@ -117,7 +110,6 @@ func (r *RuleSet) BeforeUpdate(db *gorm.DB) (err error) { return } -// // Rule - Analysis rule. type Rule struct { Model diff --git a/migration/v7/model/application.go b/migration/v7/model/application.go index f604ccfe0..672391cd6 100644 --- a/migration/v7/model/application.go +++ b/migration/v7/model/application.go @@ -2,9 +2,10 @@ package model import ( "fmt" - "gorm.io/gorm" "sync" "time" + + "gorm.io/gorm" ) type Application struct { @@ -39,7 +40,6 @@ type Fact struct { Application *Application } -// // ApplicationTag represents a row in the join table for the // many-to-many relationship between Applications and Tags. type ApplicationTag struct { @@ -50,14 +50,12 @@ type ApplicationTag struct { Tag Tag `gorm:"constraint:OnDelete:CASCADE"` } -// // TableName must return "ApplicationTags" to ensure compatibility // with the autogenerated join table name. func (ApplicationTag) TableName() string { return "ApplicationTags" } -// // depMutex ensures Dependency.Create() is not executed concurrently. var depMutex sync.Mutex @@ -69,7 +67,6 @@ type Dependency struct { From *Application `gorm:"foreignKey:FromID;constraint:OnDelete:CASCADE"` } -// // Create a dependency synchronized using a mutex. func (r *Dependency) Create(db *gorm.DB) (err error) { depMutex.Lock() @@ -78,7 +75,6 @@ func (r *Dependency) Create(db *gorm.DB) (err error) { return } -// // Validation Hook to avoid cyclic dependencies. func (r *Dependency) BeforeCreate(db *gorm.DB) (err error) { var nextDeps []*Dependency @@ -99,7 +95,6 @@ func (r *Dependency) BeforeCreate(db *gorm.DB) (err error) { return } -// // Custom error type to allow API recognize Cyclic Dependency error and assign proper status code. type DependencyCyclicError struct{} diff --git a/migration/v7/model/core.go b/migration/v7/model/core.go index c18e5663e..4989ad63b 100644 --- a/migration/v7/model/core.go +++ b/migration/v7/model/core.go @@ -3,16 +3,16 @@ package model import ( "encoding/json" "fmt" + "os" + "path" + "time" + "github.com/google/uuid" liberr "github.com/jortel/go-utils/error" "github.com/konveyor/tackle2-hub/encryption" "gorm.io/gorm" - "os" - "path" - "time" ) -// // Model Base model. type Model struct { ID uint `gorm:"<-:create;primaryKey"` @@ -135,7 +135,6 @@ func (m *Task) BeforeCreate(db *gorm.DB) (err error) { return } -// // Error appends an error. func (m *Task) Error(severity, description string, x ...interface{}) { var list []TaskError @@ -146,11 +145,9 @@ func (m *Task) Error(severity, description string, x ...interface{}) { m.Errors, _ = json.Marshal(list) } -// // Map alias. type Map = map[string]interface{} -// // TTL time-to-live. type TTL struct { Created int `json:"created,omitempty"` @@ -161,7 +158,6 @@ type TTL struct { Failed int `json:"failed,omitempty"` } -// // TaskError used in Task.Errors. type TaskError struct { Severity string `json:"severity"` @@ -191,7 +187,6 @@ type TaskGroup struct { State string } -// // Propagate group data into the task. func (m *TaskGroup) Propagate() (err error) { for i := range m.Tasks { @@ -228,7 +223,6 @@ func (m *TaskGroup) Propagate() (err error) { return } -// // merge maps B into A. // The B map is the authority. func (m *TaskGroup) merge(a, b Map) (out Map) { @@ -265,7 +259,6 @@ func (m *TaskGroup) merge(a, b Map) (out Map) { return } -// // Proxy configuration. // kind = (http|https) type Proxy struct { diff --git a/migration/v7/model/pkg.go b/migration/v7/model/pkg.go index 111324a64..50bfb9d62 100644 --- a/migration/v7/model/pkg.go +++ b/migration/v7/model/pkg.go @@ -2,7 +2,6 @@ package model import "github.com/konveyor/tackle2-hub/settings" -// // JSON field (data) type. type JSON = []byte @@ -10,7 +9,6 @@ var ( Settings = &settings.Settings ) -// // All builds all models. // Models are enumerated such that each are listed after // all the other models on which they may depend. diff --git a/migration/v8/migrate.go b/migration/v8/migrate.go index e6034a70d..a67372b6a 100644 --- a/migration/v8/migrate.go +++ b/migration/v8/migrate.go @@ -2,6 +2,7 @@ package v8 import ( "encoding/json" + liberr "github.com/jortel/go-utils/error" "github.com/jortel/go-utils/logr" v7 "github.com/konveyor/tackle2-hub/migration/v7/model" diff --git a/migration/v8/model/analysis.go b/migration/v8/model/analysis.go index 3c9e2e52e..abe025661 100644 --- a/migration/v8/model/analysis.go +++ b/migration/v8/model/analysis.go @@ -2,7 +2,6 @@ package model import "gorm.io/gorm" -// // Analysis report. type Analysis struct { Model @@ -13,7 +12,6 @@ type Analysis struct { Application *Application } -// // TechDependency report dependency. type TechDependency struct { Model @@ -27,7 +25,6 @@ type TechDependency struct { Analysis *Analysis } -// // Issue report issue (violation). type Issue struct { Model @@ -45,7 +42,6 @@ type Issue struct { Analysis *Analysis } -// // Incident report an issue incident. type Incident struct { Model @@ -58,14 +54,12 @@ type Incident struct { Issue *Issue } -// // Link URL link. type Link struct { URL string `json:"url"` Title string `json:"title,omitempty"` } -// // RuleSet - Analysis ruleset. type RuleSet struct { Model @@ -84,7 +78,6 @@ func (r *RuleSet) Builtin() bool { return r.UUID != nil } -// // BeforeUpdate hook to avoid cyclic dependencies. func (r *RuleSet) BeforeUpdate(db *gorm.DB) (err error) { seen := make(map[uint]bool) @@ -118,7 +111,6 @@ func (r *RuleSet) BeforeUpdate(db *gorm.DB) (err error) { return } -// // Rule - Analysis rule. type Rule struct { Model @@ -131,7 +123,6 @@ type Rule struct { File *File } -// // Target - analysis rule selector. type Target struct { Model diff --git a/migration/v8/model/application.go b/migration/v8/model/application.go index f604ccfe0..672391cd6 100644 --- a/migration/v8/model/application.go +++ b/migration/v8/model/application.go @@ -2,9 +2,10 @@ package model import ( "fmt" - "gorm.io/gorm" "sync" "time" + + "gorm.io/gorm" ) type Application struct { @@ -39,7 +40,6 @@ type Fact struct { Application *Application } -// // ApplicationTag represents a row in the join table for the // many-to-many relationship between Applications and Tags. type ApplicationTag struct { @@ -50,14 +50,12 @@ type ApplicationTag struct { Tag Tag `gorm:"constraint:OnDelete:CASCADE"` } -// // TableName must return "ApplicationTags" to ensure compatibility // with the autogenerated join table name. func (ApplicationTag) TableName() string { return "ApplicationTags" } -// // depMutex ensures Dependency.Create() is not executed concurrently. var depMutex sync.Mutex @@ -69,7 +67,6 @@ type Dependency struct { From *Application `gorm:"foreignKey:FromID;constraint:OnDelete:CASCADE"` } -// // Create a dependency synchronized using a mutex. func (r *Dependency) Create(db *gorm.DB) (err error) { depMutex.Lock() @@ -78,7 +75,6 @@ func (r *Dependency) Create(db *gorm.DB) (err error) { return } -// // Validation Hook to avoid cyclic dependencies. func (r *Dependency) BeforeCreate(db *gorm.DB) (err error) { var nextDeps []*Dependency @@ -99,7 +95,6 @@ func (r *Dependency) BeforeCreate(db *gorm.DB) (err error) { return } -// // Custom error type to allow API recognize Cyclic Dependency error and assign proper status code. type DependencyCyclicError struct{} diff --git a/migration/v8/model/core.go b/migration/v8/model/core.go index c18e5663e..4989ad63b 100644 --- a/migration/v8/model/core.go +++ b/migration/v8/model/core.go @@ -3,16 +3,16 @@ package model import ( "encoding/json" "fmt" + "os" + "path" + "time" + "github.com/google/uuid" liberr "github.com/jortel/go-utils/error" "github.com/konveyor/tackle2-hub/encryption" "gorm.io/gorm" - "os" - "path" - "time" ) -// // Model Base model. type Model struct { ID uint `gorm:"<-:create;primaryKey"` @@ -135,7 +135,6 @@ func (m *Task) BeforeCreate(db *gorm.DB) (err error) { return } -// // Error appends an error. func (m *Task) Error(severity, description string, x ...interface{}) { var list []TaskError @@ -146,11 +145,9 @@ func (m *Task) Error(severity, description string, x ...interface{}) { m.Errors, _ = json.Marshal(list) } -// // Map alias. type Map = map[string]interface{} -// // TTL time-to-live. type TTL struct { Created int `json:"created,omitempty"` @@ -161,7 +158,6 @@ type TTL struct { Failed int `json:"failed,omitempty"` } -// // TaskError used in Task.Errors. type TaskError struct { Severity string `json:"severity"` @@ -191,7 +187,6 @@ type TaskGroup struct { State string } -// // Propagate group data into the task. func (m *TaskGroup) Propagate() (err error) { for i := range m.Tasks { @@ -228,7 +223,6 @@ func (m *TaskGroup) Propagate() (err error) { return } -// // merge maps B into A. // The B map is the authority. func (m *TaskGroup) merge(a, b Map) (out Map) { @@ -265,7 +259,6 @@ func (m *TaskGroup) merge(a, b Map) (out Map) { return } -// // Proxy configuration. // kind = (http|https) type Proxy struct { diff --git a/migration/v8/model/pkg.go b/migration/v8/model/pkg.go index 615ee9e66..07446cd47 100644 --- a/migration/v8/model/pkg.go +++ b/migration/v8/model/pkg.go @@ -2,7 +2,6 @@ package model import "github.com/konveyor/tackle2-hub/settings" -// // JSON field (data) type. type JSON = []byte @@ -10,7 +9,6 @@ var ( Settings = &settings.Settings ) -// // All builds all models. // Models are enumerated such that each are listed after // all the other models on which they may depend. diff --git a/migration/v9/model/analysis.go b/migration/v9/model/analysis.go index 3c9e2e52e..abe025661 100644 --- a/migration/v9/model/analysis.go +++ b/migration/v9/model/analysis.go @@ -2,7 +2,6 @@ package model import "gorm.io/gorm" -// // Analysis report. type Analysis struct { Model @@ -13,7 +12,6 @@ type Analysis struct { Application *Application } -// // TechDependency report dependency. type TechDependency struct { Model @@ -27,7 +25,6 @@ type TechDependency struct { Analysis *Analysis } -// // Issue report issue (violation). type Issue struct { Model @@ -45,7 +42,6 @@ type Issue struct { Analysis *Analysis } -// // Incident report an issue incident. type Incident struct { Model @@ -58,14 +54,12 @@ type Incident struct { Issue *Issue } -// // Link URL link. type Link struct { URL string `json:"url"` Title string `json:"title,omitempty"` } -// // RuleSet - Analysis ruleset. type RuleSet struct { Model @@ -84,7 +78,6 @@ func (r *RuleSet) Builtin() bool { return r.UUID != nil } -// // BeforeUpdate hook to avoid cyclic dependencies. func (r *RuleSet) BeforeUpdate(db *gorm.DB) (err error) { seen := make(map[uint]bool) @@ -118,7 +111,6 @@ func (r *RuleSet) BeforeUpdate(db *gorm.DB) (err error) { return } -// // Rule - Analysis rule. type Rule struct { Model @@ -131,7 +123,6 @@ type Rule struct { File *File } -// // Target - analysis rule selector. type Target struct { Model diff --git a/migration/v9/model/application.go b/migration/v9/model/application.go index 64e1e52a2..f68476e8a 100644 --- a/migration/v9/model/application.go +++ b/migration/v9/model/application.go @@ -2,9 +2,10 @@ package model import ( "fmt" - "gorm.io/gorm" "sync" "time" + + "gorm.io/gorm" ) type Application struct { @@ -40,7 +41,6 @@ type Fact struct { Application *Application } -// // ApplicationTag represents a row in the join table for the // many-to-many relationship between Applications and Tags. type ApplicationTag struct { @@ -51,14 +51,12 @@ type ApplicationTag struct { Tag Tag `gorm:"constraint:OnDelete:CASCADE"` } -// // TableName must return "ApplicationTags" to ensure compatibility // with the autogenerated join table name. func (ApplicationTag) TableName() string { return "ApplicationTags" } -// // depMutex ensures Dependency.Create() is not executed concurrently. var depMutex sync.Mutex @@ -70,7 +68,6 @@ type Dependency struct { From *Application `gorm:"foreignKey:FromID;constraint:OnDelete:CASCADE"` } -// // Create a dependency synchronized using a mutex. func (r *Dependency) Create(db *gorm.DB) (err error) { depMutex.Lock() @@ -79,7 +76,6 @@ func (r *Dependency) Create(db *gorm.DB) (err error) { return } -// // Validation Hook to avoid cyclic dependencies. func (r *Dependency) BeforeCreate(db *gorm.DB) (err error) { var nextDeps []*Dependency @@ -100,7 +96,6 @@ func (r *Dependency) BeforeCreate(db *gorm.DB) (err error) { return } -// // Custom error type to allow API recognize Cyclic Dependency error and assign proper status code. type DependencyCyclicError struct{} diff --git a/migration/v9/model/core.go b/migration/v9/model/core.go index c18e5663e..4989ad63b 100644 --- a/migration/v9/model/core.go +++ b/migration/v9/model/core.go @@ -3,16 +3,16 @@ package model import ( "encoding/json" "fmt" + "os" + "path" + "time" + "github.com/google/uuid" liberr "github.com/jortel/go-utils/error" "github.com/konveyor/tackle2-hub/encryption" "gorm.io/gorm" - "os" - "path" - "time" ) -// // Model Base model. type Model struct { ID uint `gorm:"<-:create;primaryKey"` @@ -135,7 +135,6 @@ func (m *Task) BeforeCreate(db *gorm.DB) (err error) { return } -// // Error appends an error. func (m *Task) Error(severity, description string, x ...interface{}) { var list []TaskError @@ -146,11 +145,9 @@ func (m *Task) Error(severity, description string, x ...interface{}) { m.Errors, _ = json.Marshal(list) } -// // Map alias. type Map = map[string]interface{} -// // TTL time-to-live. type TTL struct { Created int `json:"created,omitempty"` @@ -161,7 +158,6 @@ type TTL struct { Failed int `json:"failed,omitempty"` } -// // TaskError used in Task.Errors. type TaskError struct { Severity string `json:"severity"` @@ -191,7 +187,6 @@ type TaskGroup struct { State string } -// // Propagate group data into the task. func (m *TaskGroup) Propagate() (err error) { for i := range m.Tasks { @@ -228,7 +223,6 @@ func (m *TaskGroup) Propagate() (err error) { return } -// // merge maps B into A. // The B map is the authority. func (m *TaskGroup) merge(a, b Map) (out Map) { @@ -265,7 +259,6 @@ func (m *TaskGroup) merge(a, b Map) (out Map) { return } -// // Proxy configuration. // kind = (http|https) type Proxy struct { diff --git a/migration/v9/model/pkg.go b/migration/v9/model/pkg.go index 5bc918d1c..9a3b3f765 100644 --- a/migration/v9/model/pkg.go +++ b/migration/v9/model/pkg.go @@ -2,7 +2,6 @@ package model import "github.com/konveyor/tackle2-hub/settings" -// // JSON field (data) type. type JSON = []byte @@ -10,7 +9,6 @@ var ( Settings = &settings.Settings ) -// // All builds all models. // Models are enumerated such that each are listed after // all the other models on which they may depend. diff --git a/model/pkg.go b/model/pkg.go index 17524f962..b2689ce16 100644 --- a/model/pkg.go +++ b/model/pkg.go @@ -5,11 +5,9 @@ import ( "gorm.io/datatypes" ) -// // Field (data) types. type JSON = datatypes.JSON -// // Models type Model = model.Model type Application = model.Application @@ -49,13 +47,10 @@ type TaskReport = model.TaskReport type Ticket = model.Ticket type Tracker = model.Tracker -// type TTL = model.TTL -// // Join tables type ApplicationTag = model.ApplicationTag -// // Errors type DependencyCyclicError = model.DependencyCyclicError diff --git a/model/query.go b/model/query.go index 49226d163..e0d9ff93c 100644 --- a/model/query.go +++ b/model/query.go @@ -1,11 +1,11 @@ package model import ( - "gorm.io/gorm" "strings" + + "gorm.io/gorm" ) -// // Intersect returns an SQL intersect of the queries. func Intersect(q ...*gorm.DB) (intersect *gorm.DB) { var part []string diff --git a/nas/dir.go b/nas/dir.go index 277699cf1..b8c6790b4 100644 --- a/nas/dir.go +++ b/nas/dir.go @@ -6,12 +6,12 @@ package nas import ( "errors" - liberr "github.com/jortel/go-utils/error" "os" "os/exec" + + liberr "github.com/jortel/go-utils/error" ) -// // RmDir deletes the directory. func RmDir(path string) (err error) { cmd := exec.Command("/usr/bin/rm", "-rf", path) @@ -19,14 +19,12 @@ func RmDir(path string) (err error) { return } -// // HasDir return if the path exists. func HasDir(path string) (found bool, err error) { found, err = Exists(path) return } -// // MkDir ensures the directory exists. func MkDir(path string, mode os.FileMode) (err error) { err = os.MkdirAll(path, mode) @@ -43,7 +41,6 @@ func MkDir(path string, mode os.FileMode) (err error) { return } -// // Exists return if the path exists. func Exists(path string) (found bool, err error) { _, err = os.Stat(path) diff --git a/reaper/bucket.go b/reaper/bucket.go index da9a9c90f..33eb99801 100644 --- a/reaper/bucket.go +++ b/reaper/bucket.go @@ -1,22 +1,21 @@ package reaper import ( + "os" + "time" + liberr "github.com/jortel/go-utils/error" "github.com/konveyor/tackle2-hub/model" "github.com/konveyor/tackle2-hub/nas" "gorm.io/gorm" - "os" - "time" ) -// // BucketReaper bucket reaper. type BucketReaper struct { // DB DB *gorm.DB } -// // Run Executes the reaper. // A bucket is deleted when it is no longer referenced and the TTL has expired. func (r *BucketReaper) Run() { @@ -60,7 +59,6 @@ func (r *BucketReaper) Run() { } } -// // busy determines if anything references the bucket. func (r *BucketReaper) busy(bucket *model.Bucket) (busy bool, err error) { nRef := int64(0) @@ -82,7 +80,6 @@ func (r *BucketReaper) busy(bucket *model.Bucket) (busy bool, err error) { return } -// // Delete bucket. func (r *BucketReaper) delete(bucket *model.Bucket) (err error) { err = nas.RmDir(bucket.Path) diff --git a/reaper/file.go b/reaper/file.go index 2f0a68749..b13767df4 100644 --- a/reaper/file.go +++ b/reaper/file.go @@ -1,21 +1,20 @@ package reaper import ( + "os" + "time" + liberr "github.com/jortel/go-utils/error" "github.com/konveyor/tackle2-hub/model" "gorm.io/gorm" - "os" - "time" ) -// // FileReaper file reaper. type FileReaper struct { // DB DB *gorm.DB } -// // Run Executes the reaper. // A file is deleted when it is no longer referenced and the TTL has expired. func (r *FileReaper) Run() { @@ -59,7 +58,6 @@ func (r *FileReaper) Run() { } } -// // busy determines if anything references the file. func (r *FileReaper) busy(file *model.File) (busy bool, err error) { nRef := int64(0) @@ -82,7 +80,6 @@ func (r *FileReaper) busy(file *model.File) (busy bool, err error) { return } -// // Delete file. func (r *FileReaper) delete(file *model.File) (err error) { err = os.Remove(file.Path) diff --git a/reaper/manager.go b/reaper/manager.go index bebc6cfef..c3efb7095 100644 --- a/reaper/manager.go +++ b/reaper/manager.go @@ -2,12 +2,13 @@ package reaper import ( "context" + "time" + "github.com/jortel/go-utils/logr" "github.com/konveyor/tackle2-hub/settings" "github.com/konveyor/tackle2-hub/task" "gorm.io/gorm" k8s "sigs.k8s.io/controller-runtime/pkg/client" - "time" ) const ( @@ -21,7 +22,6 @@ var ( type Task = task.Task -// // Manager provides task management. type Manager struct { // DB @@ -30,7 +30,6 @@ type Manager struct { Client k8s.Client } -// // Run the manager. func (m *Manager) Run(ctx context.Context) { registered := []Reaper{ @@ -65,14 +64,12 @@ func (m *Manager) Run(ctx context.Context) { }() } -// // Pause. func (m *Manager) pause() { d := Unit * time.Duration(Settings.Frequency.Reaper) time.Sleep(d) } -// // Reaper interface. type Reaper interface { Run() diff --git a/reaper/ref.go b/reaper/ref.go index 1c0a9f427..7b70fd83f 100644 --- a/reaper/ref.go +++ b/reaper/ref.go @@ -1,13 +1,13 @@ package reaper import ( + "fmt" + "reflect" + liberr "github.com/jortel/go-utils/error" "gorm.io/gorm" - "reflect" - "fmt" ) -// // RefCounter provides model inspection for files // tagged with: ref:. type RefCounter struct { @@ -15,7 +15,6 @@ type RefCounter struct { DB *gorm.DB } -// // Count find & count references. func (r *RefCounter) Count(m interface{}, kind string, pk uint) (nRef int64, err error) { db := r.DB.Model(m) diff --git a/reaper/task.go b/reaper/task.go index c968c1822..df89da766 100644 --- a/reaper/task.go +++ b/reaper/task.go @@ -2,16 +2,16 @@ package reaper import ( "encoding/json" + "time" + "github.com/konveyor/tackle2-hub/api" "github.com/konveyor/tackle2-hub/model" "github.com/konveyor/tackle2-hub/task" "gorm.io/gorm" "gorm.io/gorm/clause" k8s "sigs.k8s.io/controller-runtime/pkg/client" - "time" ) -// // TaskReaper reaps tasks. type TaskReaper struct { // DB @@ -20,30 +20,30 @@ type TaskReaper struct { Client k8s.Client } -// // Run Executes the reaper. // Rules by state: -// Created -// - Deleted after TTL.Created > created timestamp or -// settings.Task.Reaper.Created. -// Pending -// - Deleted after TTL.Pending > created timestamp or -// settings.Task.Reaper.Created. -// Postponed -// - Deleted after TTL.Postponed > created timestamp or -// settings.Task.Reaper.Created. -// Running -// - Deleted after TTL.Running > started timestamp. -// Succeeded -// - Deleted after TTL > terminated timestamp or -// settings.Task.Reaper.Succeeded. -// - Bucket is released after the defined period. -// - Pod is deleted after the defined period. -// Failed -// - Deleted after TTL > terminated timestamp or -// settings.Task.Reaper.Failed. -// - Bucket is released after the defined period. -// - Pod is deleted after the defined period. +// +// Created +// - Deleted after TTL.Created > created timestamp or +// settings.Task.Reaper.Created. +// Pending +// - Deleted after TTL.Pending > created timestamp or +// settings.Task.Reaper.Created. +// Postponed +// - Deleted after TTL.Postponed > created timestamp or +// settings.Task.Reaper.Created. +// Running +// - Deleted after TTL.Running > started timestamp. +// Succeeded +// - Deleted after TTL > terminated timestamp or +// settings.Task.Reaper.Succeeded. +// - Bucket is released after the defined period. +// - Pod is deleted after the defined period. +// Failed +// - Deleted after TTL > terminated timestamp or +// settings.Task.Reaper.Failed. +// - Bucket is released after the defined period. +// - Pod is deleted after the defined period. func (r *TaskReaper) Run() { Log.V(1).Info("Reaping tasks.") list := []model.Task{} @@ -130,7 +130,6 @@ func (r *TaskReaper) Run() { } } -// // release resources. func (r *TaskReaper) release(m *model.Task) { nChanged := 0 @@ -158,10 +157,9 @@ func (r *TaskReaper) release(m *model.Task) { return } -// // delete task. func (r *TaskReaper) delete(m *model.Task) { - rt := Task{m} + rt := Task{Task: m} err := rt.Delete(r.Client) if err != nil { Log.Error(err, "") @@ -174,7 +172,6 @@ func (r *TaskReaper) delete(m *model.Task) { } } -// // TTL returns the task TTL. func (r *TaskReaper) TTL(m *model.Task) (ttl api.TTL) { if m.TTL != nil { @@ -187,21 +184,20 @@ func (r *TaskReaper) TTL(m *model.Task) (ttl api.TTL) { // // -// // GroupReaper reaps task groups. type GroupReaper struct { // DB DB *gorm.DB } -// // Run Executes the reaper. // Rules by state: -// Created -// - Deleted after the defined period. -// Ready (submitted) -// - Deleted when all of its task have been deleted. -// - Bucket is released immediately. +// +// Created +// - Deleted after the defined period. +// Ready (submitted) +// - Deleted when all of its task have been deleted. +// - Bucket is released immediately. func (r *GroupReaper) Run() { Log.V(1).Info("Reaping groups.") list := []model.TaskGroup{} @@ -232,7 +228,6 @@ func (r *GroupReaper) Run() { } } -// // release resources. func (r *GroupReaper) release(m *model.TaskGroup) { m.SetBucket(nil) @@ -244,7 +239,6 @@ func (r *GroupReaper) release(m *model.TaskGroup) { } } -// // delete task. func (r *GroupReaper) delete(m *model.TaskGroup) { err := r.DB.Delete(m).Error diff --git a/seed/jobfunction.go b/seed/jobfunction.go index 6bd2cb98d..dbad0b6bd 100644 --- a/seed/jobfunction.go +++ b/seed/jobfunction.go @@ -3,19 +3,18 @@ package seed import ( "errors" "fmt" + liberr "github.com/jortel/go-utils/error" "github.com/konveyor/tackle2-hub/model" libseed "github.com/konveyor/tackle2-seed/pkg" "gorm.io/gorm" ) -// // JobFunction applies JobFunction seeds. type JobFunction struct { jobFunctions []libseed.JobFunction } -// // With collects all the JobFunction seeds. func (r *JobFunction) With(seed libseed.Seed) (err error) { items, err := seed.DecodeItems() @@ -28,7 +27,6 @@ func (r *JobFunction) With(seed libseed.Seed) (err error) { return } -// // Apply seeds the database with JobFunctions. func (r *JobFunction) Apply(db *gorm.DB) (err error) { log.Info("Applying JobFunctions", "count", len(r.jobFunctions)) @@ -82,7 +80,6 @@ func (r *JobFunction) Apply(db *gorm.DB) (err error) { return } -// // Convenience method to find a JobFunction. func (r *JobFunction) find(db *gorm.DB, conditions ...interface{}) (jf *model.JobFunction, found bool, err error) { jf = &model.JobFunction{} @@ -98,7 +95,6 @@ func (r *JobFunction) find(db *gorm.DB, conditions ...interface{}) (jf *model.Jo return } -// // Rename a JobFunction by adding a suffix. func (r *JobFunction) rename(db *gorm.DB, jf *model.JobFunction) (err error) { suffix := 0 diff --git a/seed/pkg.go b/seed/pkg.go index 64b2dc7a6..114b9d5b1 100644 --- a/seed/pkg.go +++ b/seed/pkg.go @@ -2,29 +2,27 @@ package seed import ( "errors" + "io/fs" + liberr "github.com/jortel/go-utils/error" "github.com/jortel/go-utils/logr" "github.com/konveyor/tackle2-hub/database" "github.com/konveyor/tackle2-hub/settings" libseed "github.com/konveyor/tackle2-seed/pkg" "gorm.io/gorm" - "io/fs" ) var log = logr.WithName("seeding") -// // SeedKey identifies the setting containing the applied seed digest. const SeedKey = ".hub.db.seed" -// // Seeder specifies an interface for seeding DB models. type Seeder interface { With(libseed.Seed) error Apply(*gorm.DB) error } -// // Seed applies DB seeds. func Seed() (err error) { var db *gorm.DB diff --git a/seed/questionnaire.go b/seed/questionnaire.go index fa1c943ba..a3b0c3121 100644 --- a/seed/questionnaire.go +++ b/seed/questionnaire.go @@ -4,19 +4,18 @@ import ( "encoding/json" "errors" "fmt" + liberr "github.com/jortel/go-utils/error" "github.com/konveyor/tackle2-hub/model" libseed "github.com/konveyor/tackle2-seed/pkg" "gorm.io/gorm" ) -// // Questionnaire applies Questionnaire seeds. type Questionnaire struct { questionnaires []libseed.Questionnaire } -// // With collects all the Questionnaire seeds. func (r *Questionnaire) With(seed libseed.Seed) (err error) { items, err := seed.DecodeItems() @@ -29,7 +28,6 @@ func (r *Questionnaire) With(seed libseed.Seed) (err error) { return } -// // Apply seeds the database with Questionnaires. func (r *Questionnaire) Apply(db *gorm.DB) (err error) { log.Info("Applying Questionnaires", "count", len(r.questionnaires)) @@ -91,7 +89,6 @@ func (r *Questionnaire) Apply(db *gorm.DB) (err error) { return } -// // Convenience method to find a Questionnaire. func (r *Questionnaire) find(db *gorm.DB, conditions ...interface{}) (q *model.Questionnaire, found bool, err error) { q = &model.Questionnaire{} @@ -107,7 +104,6 @@ func (r *Questionnaire) find(db *gorm.DB, conditions ...interface{}) (q *model.Q return } -// // Rename a Questionnaire by adding a suffix. func (r *Questionnaire) rename(db *gorm.DB, q *model.Questionnaire) (err error) { suffix := 0 diff --git a/seed/ruleset.go b/seed/ruleset.go index ab8afb7b3..97bcd614f 100644 --- a/seed/ruleset.go +++ b/seed/ruleset.go @@ -4,22 +4,21 @@ import ( "encoding/json" "errors" "fmt" + "io" + "os" + "path" + liberr "github.com/jortel/go-utils/error" "github.com/konveyor/tackle2-hub/model" libseed "github.com/konveyor/tackle2-seed/pkg" "gorm.io/gorm" - "io" - "os" - "path" ) -// // RuleSet applies RuleSet seeds. type RuleSet struct { ruleSets []libseed.RuleSet } -// // With collects all the RuleSet seeds. func (r *RuleSet) With(seed libseed.Seed) (err error) { items, err := seed.DecodeItems() @@ -33,7 +32,6 @@ func (r *RuleSet) With(seed libseed.Seed) (err error) { return } -// // Apply seeds the database with RuleSets. func (r *RuleSet) Apply(db *gorm.DB) (err error) { log.Info("Applying RuleSets", "count", len(r.ruleSets)) @@ -122,7 +120,6 @@ func (r *RuleSet) Apply(db *gorm.DB) (err error) { return } -// // Seed a RuleSet's Rules. func (r *RuleSet) applyRules(db *gorm.DB, ruleSet *model.RuleSet, rs libseed.RuleSet) (err error) { result := db.Delete(&model.Rule{}, "RuleSetID = ?", ruleSet.ID) @@ -151,7 +148,6 @@ func (r *RuleSet) applyRules(db *gorm.DB, ruleSet *model.RuleSet, rs libseed.Rul return } -// // Create a File model and copy a real file to its path. func file(db *gorm.DB, filePath string) (file *model.File, err error) { file = &model.File{ @@ -182,7 +178,6 @@ func file(db *gorm.DB, filePath string) (file *model.File, err error) { return } -// // Convenience method to find a RuleSet. func (r *RuleSet) find(db *gorm.DB, conditions ...interface{}) (rs *model.RuleSet, found bool, err error) { rs = &model.RuleSet{} @@ -198,7 +193,6 @@ func (r *RuleSet) find(db *gorm.DB, conditions ...interface{}) (rs *model.RuleSe return } -// // Rename a RuleSet by adding a suffix. func (r *RuleSet) rename(db *gorm.DB, rs *model.RuleSet) (err error) { suffix := 0 diff --git a/seed/seed.go b/seed/seed.go index 94bfab2f3..1ae605a9d 100644 --- a/seed/seed.go +++ b/seed/seed.go @@ -3,15 +3,15 @@ package seed import ( "encoding/json" "fmt" + "strings" + liberr "github.com/jortel/go-utils/error" "github.com/konveyor/tackle2-hub/migration" "github.com/konveyor/tackle2-hub/model" libseed "github.com/konveyor/tackle2-seed/pkg" "gorm.io/gorm" - "strings" ) -// // Hub is responsible for collecting and applying Hub seeds. type Hub struct { TagCategory @@ -21,7 +21,6 @@ type Hub struct { Questionnaire } -// // With collects the resources to be seeded. func (r *Hub) With(seed libseed.Seed) (err error) { switch strings.ToLower(seed.Kind) { @@ -41,7 +40,6 @@ func (r *Hub) With(seed libseed.Seed) (err error) { return } -// // Apply seeds the database with resources from the seed files. func (r *Hub) Apply(db *gorm.DB) (err error) { err = r.TagCategory.Apply(db) @@ -68,7 +66,6 @@ func (r *Hub) Apply(db *gorm.DB) (err error) { return } -// // compareChecksum compares the seed checksum to the stored checksum. func compareChecksum(db *gorm.DB, checksum []byte) (match bool, err error) { setting := &model.Setting{} @@ -90,7 +87,6 @@ func compareChecksum(db *gorm.DB, checksum []byte) (match bool, err error) { return } -// // saveChecksum saves the seed checksum to the setting specified by SeedKey. func saveChecksum(db *gorm.DB, checksum []byte) (err error) { setting := &model.Setting{Key: SeedKey} @@ -104,7 +100,6 @@ func saveChecksum(db *gorm.DB, checksum []byte) (err error) { return } -// // migrationVersion gets the current migration version. func migrationVersion(db *gorm.DB) (version uint, err error) { setting := &model.Setting{} diff --git a/seed/tag.go b/seed/tag.go index bc84674e0..7673338df 100644 --- a/seed/tag.go +++ b/seed/tag.go @@ -3,19 +3,18 @@ package seed import ( "errors" "fmt" + liberr "github.com/jortel/go-utils/error" "github.com/konveyor/tackle2-hub/model" libseed "github.com/konveyor/tackle2-seed/pkg" "gorm.io/gorm" ) -// // TagCategory applies TagCategory seeds. type TagCategory struct { categories []libseed.TagCategory } -// // With collects all the TagCategory seeds. func (r *TagCategory) With(seed libseed.Seed) (err error) { items, err := seed.DecodeItems() @@ -28,7 +27,6 @@ func (r *TagCategory) With(seed libseed.Seed) (err error) { return } -// // Apply seeds the database with TagCategories and Tags. func (r *TagCategory) Apply(db *gorm.DB) (err error) { log.Info("Applying TagCategories", "count", len(r.categories)) @@ -89,7 +87,6 @@ func (r *TagCategory) Apply(db *gorm.DB) (err error) { return } -// // Seed a TagCategory's tags. func (r *TagCategory) applyTags(db *gorm.DB, category *model.TagCategory, tc libseed.TagCategory) (err error) { for i := range tc.Tags { @@ -120,7 +117,6 @@ func (r *TagCategory) applyTags(db *gorm.DB, category *model.TagCategory, tc lib return } -// // Convenience method to find a TagCategory. func (r *TagCategory) find(db *gorm.DB, conditions ...interface{}) (category *model.TagCategory, found bool, err error) { category = &model.TagCategory{} @@ -136,7 +132,6 @@ func (r *TagCategory) find(db *gorm.DB, conditions ...interface{}) (category *mo return } -// // Rename a TagCategory by adding a suffix. func (r *TagCategory) rename(db *gorm.DB, category *model.TagCategory) (err error) { suffix := 0 diff --git a/seed/target.go b/seed/target.go index d3deb2266..554f79e5a 100644 --- a/seed/target.go +++ b/seed/target.go @@ -5,6 +5,7 @@ import ( "encoding/json" "errors" "fmt" + liberr "github.com/jortel/go-utils/error" "github.com/konveyor/tackle2-hub/model" libseed "github.com/konveyor/tackle2-seed/pkg" @@ -13,13 +14,11 @@ import ( const UITargetOrder = "ui.target.order" -// // Target applies Target seeds. type Target struct { targets []libseed.Target } -// // With collects all the Target seeds. func (r *Target) With(seed libseed.Seed) (err error) { items, err := seed.DecodeItems() @@ -32,7 +31,6 @@ func (r *Target) With(seed libseed.Seed) (err error) { return } -// // Apply seeds the database with JobFunctions. func (r *Target) Apply(db *gorm.DB) (err error) { log.Info("Applying Targets", "count", len(r.targets)) @@ -106,7 +104,6 @@ func (r *Target) Apply(db *gorm.DB) (err error) { return } -// // reorder updates the value of the ui.target.order setting // to add any missing target ids. (namely, newly added targets.) func (r *Target) reorder(db *gorm.DB, seedIds []uint) (err error) { @@ -139,12 +136,12 @@ func (r *Target) reorder(db *gorm.DB, seedIds []uint) (err error) { return } -// // merge new targets into the user's custom target order. -// params: -// userOrder: slice of target IDs in the user's desired order -// seedOrder: slice of target IDs in seedfile order -// ids: slice of ids of all the targets in the DB +// +// params: +// userOrder: slice of target IDs in the user's desired order +// seedOrder: slice of target IDs in seedfile order +// ids: slice of ids of all the targets in the DB func merge(userOrder []uint, seedOrder []uint, ids []uint) (mergedOrder []uint) { ll := list.New() known := make(map[uint]*list.Element) @@ -178,7 +175,6 @@ func merge(userOrder []uint, seedOrder []uint, ids []uint) (mergedOrder []uint) return } -// // Convenience method to find a Target. func (r *Target) find(db *gorm.DB, conditions ...interface{}) (t *model.Target, found bool, err error) { t = &model.Target{} @@ -194,7 +190,6 @@ func (r *Target) find(db *gorm.DB, conditions ...interface{}) (t *model.Target, return } -// // Rename a Target by adding a suffix. func (r *Target) rename(db *gorm.DB, t *model.Target) (err error) { suffix := 0 diff --git a/seed/target_test.go b/seed/target_test.go index 3a7681ae5..0505b55d5 100644 --- a/seed/target_test.go +++ b/seed/target_test.go @@ -1,8 +1,9 @@ package seed import ( - "github.com/onsi/gomega" "testing" + + "github.com/onsi/gomega" ) func TestMerge(t *testing.T) { diff --git a/settings/addon.go b/settings/addon.go index f9e47cfb9..94c30c57a 100644 --- a/settings/addon.go +++ b/settings/addon.go @@ -12,7 +12,6 @@ const ( EnvTask = "TASK" ) -// // Addon settings. type Addon struct { // Hub settings. diff --git a/settings/all.go b/settings/all.go index f6140043f..e69e9adb7 100644 --- a/settings/all.go +++ b/settings/all.go @@ -34,7 +34,6 @@ func (r *TackleSettings) Load() (err error) { return } -// // Get boolean. func getEnvBool(name string, def bool) bool { boolean := def diff --git a/settings/auth.go b/settings/auth.go index b0dae0811..56512c09b 100644 --- a/settings/auth.go +++ b/settings/auth.go @@ -4,7 +4,6 @@ import ( "os" ) -// // Environment variables const ( EnvAuthRequired = "AUTH_REQUIRED" diff --git a/settings/hub.go b/settings/hub.go index deaf0c00f..e6255a706 100644 --- a/settings/hub.go +++ b/settings/hub.go @@ -201,7 +201,6 @@ func (r *Hub) Load() (err error) { return } -// // namespace determines the namespace. func (r *Hub) namespace() (ns string, err error) { ns, found := os.LookupEnv(EnvNamespace) diff --git a/settings/metrics.go b/settings/metrics.go index 89c418fb5..df84141b0 100644 --- a/settings/metrics.go +++ b/settings/metrics.go @@ -6,14 +6,12 @@ import ( "strconv" ) -// // Environment variables. const ( MetricsEnabled = "METRICS_ENABLED" MetricsPort = "METRICS_PORT" ) -// // Metrics settings type Metrics struct { // Metrics port. @@ -22,7 +20,6 @@ type Metrics struct { Enabled bool } -// // Load settings. func (r *Metrics) Load() error { // Enabled @@ -37,7 +34,6 @@ func (r *Metrics) Load() error { return nil } -// // Address on which to serve metrics. func (r *Metrics) Address() string { return fmt.Sprintf(":%d", r.Port) diff --git a/tar/filter.go b/tar/filter.go index 63fdd5a1c..f91094b48 100644 --- a/tar/filter.go +++ b/tar/filter.go @@ -5,14 +5,12 @@ import ( "path/filepath" ) -// // NewFilter returns a filter. func NewFilter(root string) (f Filter) { f = Filter{Root: root} return } -// // Filter supports glob-style filtering. type Filter struct { included FilterSet @@ -20,7 +18,6 @@ type Filter struct { Root string } -// // Match determines if path matches the filter. func (r *Filter) Match(path string) (b bool) { r.included.root = r.Root @@ -42,21 +39,18 @@ func (r *Filter) Match(path string) (b bool) { return } -// // Include adds included patterns. // Empty ("") patterns are ignored. func (r *Filter) Include(patterns ...string) { r.included.Add(patterns...) } -// // Exclude adds excluded patterns. // Empty ("") patterns are ignored. func (r *Filter) Exclude(patterns ...string) { r.excluded.Add(patterns...) } -// // FilterSet is a collection of filter patterns. type FilterSet struct { root string @@ -64,7 +58,6 @@ type FilterSet struct { cache map[string]bool } -// // Match returns true when the path matches. func (r *FilterSet) Match(path string) (match bool) { r.build() @@ -72,7 +65,6 @@ func (r *FilterSet) Match(path string) (match bool) { return } -// // Add pattern. // Empty ("") patterns are ignored. func (r *FilterSet) Add(patterns ...string) { @@ -87,13 +79,11 @@ func (r *FilterSet) Add(patterns ...string) { } } -// // Len returns number of patterns. func (r *FilterSet) Len() (n int) { return len(r.patterns) } -// // build populates the cache as needed. func (r *FilterSet) build() { if r.cache != nil { diff --git a/tar/reader.go b/tar/reader.go index 91b056b3d..3f3524e31 100644 --- a/tar/reader.go +++ b/tar/reader.go @@ -3,27 +3,25 @@ package tar import ( "archive/tar" "compress/gzip" - liberr "github.com/jortel/go-utils/error" - "github.com/konveyor/tackle2-hub/nas" "io" "os" pathlib "path" + + liberr "github.com/jortel/go-utils/error" + "github.com/konveyor/tackle2-hub/nas" ) -// // NewReader returns a new reader. func NewReader() (reader *Reader) { reader = &Reader{} return } -// // Reader archive reader. type Reader struct { Filter Filter } -// // Extract archive content to the destination path. func (r *Reader) Extract(outDir string, reader io.Reader) (err error) { zipReader, err := gzip.NewReader(reader) diff --git a/tar/tar_test.go b/tar/tar_test.go index 027e67f76..0c43d41c4 100644 --- a/tar/tar_test.go +++ b/tar/tar_test.go @@ -1,14 +1,15 @@ package tar import ( - liberr "github.com/jortel/go-utils/error" - "github.com/konveyor/tackle2-hub/nas" - "github.com/konveyor/tackle2-hub/test/assert" - "github.com/onsi/gomega" "os" "path" "path/filepath" "testing" + + liberr "github.com/jortel/go-utils/error" + "github.com/konveyor/tackle2-hub/nas" + "github.com/konveyor/tackle2-hub/test/assert" + "github.com/onsi/gomega" ) func TestWriter(t *testing.T) { diff --git a/tar/writer.go b/tar/writer.go index 8b55708d4..5e0ba4e77 100644 --- a/tar/writer.go +++ b/tar/writer.go @@ -3,15 +3,15 @@ package tar import ( "archive/tar" "compress/gzip" - liberr "github.com/jortel/go-utils/error" "io" "os" "path/filepath" "runtime" "strings" + + liberr "github.com/jortel/go-utils/error" ) -// // NewWriter returns a new writer. func NewWriter(output io.Writer) (writer *Writer) { writer = &Writer{} @@ -24,7 +24,6 @@ func NewWriter(output io.Writer) (writer *Writer) { return } -// // Writer is a Zipped TAR streamed writer. type Writer struct { Filter Filter @@ -37,7 +36,6 @@ type Writer struct { } } -// // Open the writer. func (r *Writer) Open(output io.Writer) { if r.tarWriter != nil { @@ -56,7 +54,6 @@ func (r *Writer) Open(output io.Writer) { }() } -// // AssertDir validates the path is a readable directory. func (r *Writer) AssertDir(pathIn string) (err error) { st, err := os.Stat(pathIn) @@ -100,7 +97,6 @@ func (r *Writer) AssertDir(pathIn string) (err error) { return } -// // AddDir adds a directory. func (r *Writer) AddDir(pathIn string) (err error) { if r.tarWriter == nil { @@ -162,7 +158,6 @@ func (r *Writer) AddDir(pathIn string) (err error) { return } -// // AssertFile validates the path is a readable file. func (r *Writer) AssertFile(pathIn string) (err error) { st, err := os.Stat(pathIn) @@ -183,7 +178,6 @@ func (r *Writer) AssertFile(pathIn string) (err error) { return } -// // AddFile adds a file. func (r *Writer) AddFile(pathIn, destPath string) (err error) { if r.tarWriter == nil { @@ -226,7 +220,6 @@ func (r *Writer) AddFile(pathIn, destPath string) (err error) { return } -// // Close the writer. func (r *Writer) Close() { if r.tarWriter == nil { diff --git a/task/auth.go b/task/auth.go index 1b2254e4d..83601dbc1 100644 --- a/task/auth.go +++ b/task/auth.go @@ -3,27 +3,26 @@ package task import ( "context" "fmt" + "path" + "github.com/golang-jwt/jwt/v4" "github.com/konveyor/tackle2-hub/auth" "github.com/konveyor/tackle2-hub/model" "gorm.io/gorm" core "k8s.io/api/core/v1" - "path" k8s "sigs.k8s.io/controller-runtime/pkg/client" ) -// // Validator validates task tokens. type Validator struct { // k8s client. Client k8s.Client } -// // Valid token when: -// - The token references a task. -// - The task is valid and running. -// - The task pod valid and pending|running. +// - The token references a task. +// - The task is valid and running. +// - The task pod valid and pending|running. func (r *Validator) Valid(token *jwt.Token, db *gorm.DB) (err error) { claims := token.Claims.(jwt.MapClaims) v, found := claims["task"] diff --git a/task/manager.go b/task/manager.go index 172fc0f8b..c2e66fa1d 100644 --- a/task/manager.go +++ b/task/manager.go @@ -4,6 +4,10 @@ import ( "context" "errors" "fmt" + "path" + "strconv" + "time" + "github.com/golang-jwt/jwt/v4" liberr "github.com/jortel/go-utils/error" "github.com/jortel/go-utils/logr" @@ -16,13 +20,9 @@ import ( core "k8s.io/api/core/v1" k8serr "k8s.io/apimachinery/pkg/api/errors" meta "k8s.io/apimachinery/pkg/apis/meta/v1" - "path" k8s "sigs.k8s.io/controller-runtime/pkg/client" - "strconv" - "time" ) -// // States const ( Created = "Created" @@ -35,7 +35,6 @@ const ( Canceled = "Canceled" ) -// // Policies const ( Isolated = "isolated" @@ -50,7 +49,6 @@ var ( Log = logr.WithName("task-scheduler") ) -// // AddonNotFound used to report addon referenced // by a task but cannot be found. type AddonNotFound struct { @@ -66,7 +64,6 @@ func (e *AddonNotFound) Is(err error) (matched bool) { return } -// // Manager provides task management. type Manager struct { // DB @@ -77,7 +74,6 @@ type Manager struct { Scopes []string } -// // Run the manager. func (m *Manager) Run(ctx context.Context) { auth.Validators = append( @@ -101,14 +97,12 @@ func (m *Manager) Run(ctx context.Context) { }() } -// // Pause. func (m *Manager) pause() { d := Unit * time.Duration(Settings.Frequency.Task) time.Sleep(d) } -// // startReady starts pending tasks. func (m *Manager) startReady() { list := []model.Task{} @@ -178,7 +172,6 @@ func (m *Manager) startReady() { } } -// // updateRunning tasks to reflect pod state. func (m *Manager) updateRunning() { list := []model.Task{} @@ -214,7 +207,6 @@ func (m *Manager) updateRunning() { } } -// // postpone Postpones a task as needed based on rules. func (m *Manager) postpone(ready *model.Task, list []model.Task) (postponed bool) { ruleSet := []Rule{ @@ -241,7 +233,6 @@ func (m *Manager) postpone(ready *model.Task, list []model.Task) (postponed bool return } -// // The task has been canceled. func (m *Manager) canceled(task *model.Task) { rt := Task{task} @@ -258,14 +249,12 @@ func (m *Manager) canceled(task *model.Task) { return } -// // Task is an runtime task. type Task struct { // model. *model.Task } -// // Run the specified task. func (r *Task) Run(client k8s.Client) (err error) { mark := time.Now() @@ -328,7 +317,6 @@ func (r *Task) Run(client k8s.Client) (err error) { return } -// // Reflect finds the associated pod and updates the task state. func (r *Task) Reflect(client k8s.Client) (err error) { pod := &core.Pod{} @@ -381,7 +369,6 @@ func (r *Task) Reflect(client k8s.Client) (err error) { return } -// // Delete the associated pod as needed. func (r *Task) Delete(client k8s.Client) (err error) { if r.Pod == "" { @@ -411,7 +398,6 @@ func (r *Task) Delete(client k8s.Client) (err error) { return } -// // Cancel the task. func (r *Task) Cancel(client k8s.Client) (err error) { err = r.Delete(client) @@ -427,7 +413,6 @@ func (r *Task) Cancel(client k8s.Client) (err error) { return } -// // findAddon by name. func (r *Task) findAddon(client k8s.Client, name string) (addon *crd.Addon, err error) { addon = &crd.Addon{} @@ -450,7 +435,6 @@ func (r *Task) findAddon(client k8s.Client, name string) (addon *crd.Addon, err return } -// // findTackle returns the tackle CR. func (r *Task) findTackle(client k8s.Client) (owner *crd.Tackle, err error) { list := crd.TackleList{} @@ -470,7 +454,6 @@ func (r *Task) findTackle(client k8s.Client) (owner *crd.Tackle, err error) { return } -// // pod build the pod. func (r *Task) pod(addon *crd.Addon, owner *crd.Tackle, secret *core.Secret) (pod core.Pod) { pod = core.Pod{ @@ -493,7 +476,6 @@ func (r *Task) pod(addon *crd.Addon, owner *crd.Tackle, secret *core.Secret) (po return } -// // specification builds a Pod specification. func (r *Task) specification(addon *crd.Addon, secret *core.Secret) (specification core.PodSpec) { cache := core.Volume{ @@ -524,7 +506,6 @@ func (r *Task) specification(addon *crd.Addon, secret *core.Secret) (specificati return } -// // container builds the pod container. func (r *Task) container(addon *crd.Addon, secret *core.Secret) (container core.Container) { userid := int64(0) @@ -572,7 +553,6 @@ func (r *Task) container(addon *crd.Addon, secret *core.Secret) (container core. return } -// // secret builds the pod secret. func (r *Task) secret(addon *crd.Addon) (secret core.Secret) { user := "addon:" + addon.Name @@ -596,13 +576,11 @@ func (r *Task) secret(addon *crd.Addon) (secret core.Secret) { return } -// // k8sName returns a name suitable to be used for k8s resources. func (r *Task) k8sName() string { return fmt.Sprintf("task-%d-", r.ID) } -// // labels builds k8s labels. func (r *Task) labels() map[string]string { return map[string]string{ diff --git a/task/rule.go b/task/rule.go index eed0bb651..f627d9adf 100644 --- a/task/rule.go +++ b/task/rule.go @@ -1,17 +1,16 @@ package task import ( - "github.com/konveyor/tackle2-hub/model" "strings" + + "github.com/konveyor/tackle2-hub/model" ) -// // Rule defines postpone rules. type Rule interface { Match(candidate, other *model.Task) bool } -// // RuleUnique running tasks must be unique by: // - application // - variant @@ -19,7 +18,6 @@ type Rule interface { type RuleUnique struct { } -// // Match determines the match. func (r *RuleUnique) Match(candidate, other *model.Task) (matched bool) { if candidate.ApplicationID == nil || other.ApplicationID == nil { @@ -42,12 +40,10 @@ func (r *RuleUnique) Match(candidate, other *model.Task) (matched bool) { return } -// // RuleIsolated policy. type RuleIsolated struct { } -// // Match determines the match. func (r *RuleIsolated) Match(candidate, other *model.Task) (matched bool) { matched = r.hasPolicy(candidate, Isolated) || r.hasPolicy(other, Isolated) @@ -63,7 +59,6 @@ func (r *RuleIsolated) Match(candidate, other *model.Task) (matched bool) { return } -// // Returns true if the task policy includes: isolated func (r *RuleIsolated) hasPolicy(task *model.Task, name string) (matched bool) { for _, p := range strings.Split(task.Policy, ";") { diff --git a/test/api/application/facts_test.go b/test/api/application/facts_test.go index 3dd5c74c2..e68705b1f 100644 --- a/test/api/application/facts_test.go +++ b/test/api/application/facts_test.go @@ -11,13 +11,13 @@ import ( var SampleFacts = []*api.Fact{ { - Key: "pet", - Value: "{\"kind\":\"dog\",\"Age\":4}", + Key: "pet", + Value: "{\"kind\":\"dog\",\"Age\":4}", Source: "test", }, { - Key: "address", - Value: "{\"street\":\"Maple\",\"State\":\"AL\"}", + Key: "address", + Value: "{\"street\":\"Maple\",\"State\":\"AL\"}", Source: "test", }, } diff --git a/test/api/application/pkg.go b/test/api/application/pkg.go index 9a863a8e9..83342b7f7 100644 --- a/test/api/application/pkg.go +++ b/test/api/application/pkg.go @@ -6,12 +6,11 @@ import ( ) var ( - Client *binding.Client - RichClient *binding.RichClient + Client *binding.Client + RichClient *binding.RichClient Application binding.Application ) - func init() { // Prepare RichClient and login to Hub API (configured from env variables). RichClient = client.PrepareRichClient() diff --git a/test/api/application/samples.go b/test/api/application/samples.go index 0faa42260..84340b67c 100644 --- a/test/api/application/samples.go +++ b/test/api/application/samples.go @@ -7,18 +7,17 @@ import ( // Set of valid Application resources for tests and reuse. // Important: initialize test application from this samples, not use it directly to not affect other tests. var ( - Minimal = api.Application{ - Name: "Minimal application", - } - PathfinderGit = api.Application{ - Name: "Pathfinder", - Description: "Tackle Pathfinder application.", - Repository: &api.Repository{ - Kind: "git", - URL: "https://github.com/konveyor/tackle-pathfinder.git", - Branch: "1.2.0", - }, - } - Samples = []api.Application{Minimal, PathfinderGit} + Minimal = api.Application{ + Name: "Minimal application", + } + PathfinderGit = api.Application{ + Name: "Pathfinder", + Description: "Tackle Pathfinder application.", + Repository: &api.Repository{ + Kind: "git", + URL: "https://github.com/konveyor/tackle-pathfinder.git", + Branch: "1.2.0", + }, + } + Samples = []api.Application{Minimal, PathfinderGit} ) - diff --git a/test/api/archetype/pkg.go b/test/api/archetype/pkg.go index 9aea4744d..cc5a622c8 100644 --- a/test/api/archetype/pkg.go +++ b/test/api/archetype/pkg.go @@ -7,10 +7,9 @@ import ( var ( RichClient *binding.RichClient - Archetype binding.Archetype + Archetype binding.Archetype ) - func init() { // Prepare RichClient and login to Hub API (configured from env variables). RichClient = client.PrepareRichClient() diff --git a/test/api/assessment/api_test.go b/test/api/assessment/api_test.go index 33815dcfe..c131d1296 100644 --- a/test/api/assessment/api_test.go +++ b/test/api/assessment/api_test.go @@ -26,7 +26,7 @@ func TestAssessmentCRUD(t *testing.T) { if err != nil { t.Errorf(err.Error()) } - + } // Get. diff --git a/test/api/assessment/pkg.go b/test/api/assessment/pkg.go index dedc942e3..c6419e490 100644 --- a/test/api/assessment/pkg.go +++ b/test/api/assessment/pkg.go @@ -10,7 +10,6 @@ var ( Assessment binding.Assessment ) - func init() { // Prepare RichClient and login to Hub API (configured from env variables). RichClient = client.PrepareRichClient() @@ -21,4 +20,4 @@ func init() { func uint2ptr(u uint) *uint { return &u -} \ No newline at end of file +} diff --git a/test/api/businesservice/pkg.go b/test/api/businesservice/pkg.go index 57e8d16ee..480fd8c65 100644 --- a/test/api/businesservice/pkg.go +++ b/test/api/businesservice/pkg.go @@ -6,11 +6,10 @@ import ( ) var ( - RichClient *binding.RichClient + RichClient *binding.RichClient BusinessService binding.BusinessService ) - func init() { // Prepare RichClient and login to Hub API (configured from env variables). RichClient = client.PrepareRichClient() diff --git a/test/api/businesservice/samples.go b/test/api/businesservice/samples.go index 4118c900d..523358c61 100644 --- a/test/api/businesservice/samples.go +++ b/test/api/businesservice/samples.go @@ -13,4 +13,4 @@ var ( Description: "Sales support service.", } Samples = []api.BusinessService{Marketing, Sales} -) \ No newline at end of file +) diff --git a/test/api/client/client.go b/test/api/client/client.go index c8b21d8a9..6129af88c 100644 --- a/test/api/client/client.go +++ b/test/api/client/client.go @@ -8,27 +8,27 @@ import ( "github.com/konveyor/tackle2-hub/settings" ) -const( +const ( Username = "HUB_USERNAME" Password = "HUB_PASSWORD" ) -// // Create RichClient to interact with Hub API // Parameters are read environment variables: -// HUB_BASE_URL (required) -// HUB_USERNAME, HUB_PASSWORD (optional, depends on Require Auth option in Konveyor installation) +// +// HUB_BASE_URL (required) +// HUB_USERNAME, HUB_PASSWORD (optional, depends on Require Auth option in Konveyor installation) func PrepareRichClient() (richClient *binding.RichClient) { - // Prepare RichClient and login to Hub API - richClient = binding.New(settings.Settings.Addon.Hub.URL) - err := richClient.Login(os.Getenv(Username), os.Getenv(Password)) + // Prepare RichClient and login to Hub API + richClient = binding.New(settings.Settings.Addon.Hub.URL) + err := richClient.Login(os.Getenv(Username), os.Getenv(Password)) + + if err != nil { + panic(fmt.Sprintf("Cannot login to API: %v.", err.Error())) + } - if err != nil { - panic(fmt.Sprintf("Cannot login to API: %v.", err.Error())) - } - // Disable HTTP requests retry for network-related errors to fail quickly. richClient.Client.Retry = 1 - return -} \ No newline at end of file + return +} diff --git a/test/api/file/api_test.go b/test/api/file/api_test.go index 84a4d0ad5..703012d9b 100644 --- a/test/api/file/api_test.go +++ b/test/api/file/api_test.go @@ -6,10 +6,11 @@ import ( "path/filepath" "testing" - "github.com/konveyor/tackle2-hub/test/assert" - "k8s.io/apimachinery/pkg/util/rand" "io/ioutil" "strings" + + "github.com/konveyor/tackle2-hub/test/assert" + "k8s.io/apimachinery/pkg/util/rand" ) func TestFilePutGetDelete(t *testing.T) { diff --git a/test/api/file/pkg.go b/test/api/file/pkg.go index 320cfb10d..d60ff96da 100644 --- a/test/api/file/pkg.go +++ b/test/api/file/pkg.go @@ -7,10 +7,9 @@ import ( var ( RichClient *binding.RichClient - File binding.File + File binding.File ) - func init() { // Prepare RichClient and login to Hub API (configured from env variables). RichClient = client.PrepareRichClient() diff --git a/test/api/identity/pkg.go b/test/api/identity/pkg.go index 34663fc94..4b70d73cf 100644 --- a/test/api/identity/pkg.go +++ b/test/api/identity/pkg.go @@ -7,10 +7,9 @@ import ( var ( RichClient *binding.RichClient - Identity binding.Identity + Identity binding.Identity ) - func init() { // Prepare RichClient and login to Hub API (configured from env variables). RichClient = client.PrepareRichClient() diff --git a/test/api/importcsv/api_test.go b/test/api/importcsv/api_test.go index 2f7c96752..3c98e1051 100644 --- a/test/api/importcsv/api_test.go +++ b/test/api/importcsv/api_test.go @@ -1,13 +1,14 @@ package importcsv import ( - "github.com/konveyor/tackle2-hub/api" - "github.com/konveyor/tackle2-hub/binding" - "github.com/konveyor/tackle2-hub/test/assert" "io/ioutil" "os" "testing" "time" + + "github.com/konveyor/tackle2-hub/api" + "github.com/konveyor/tackle2-hub/binding" + "github.com/konveyor/tackle2-hub/test/assert" ) func TestImportCSV(t *testing.T) { @@ -26,14 +27,14 @@ func TestImportCSV(t *testing.T) { var outputImportSummaries []api.ImportSummary outputMatchingSummary := api.ImportSummary{} - for{ + for { assert.Should(t, Client.Get(api.SummariesRoot, &outputImportSummaries)) for _, gotImport := range outputImportSummaries { if uint(gotImport.ID) == inputData.ID { outputMatchingSummary = gotImport } } - if(outputMatchingSummary.ValidCount + outputMatchingSummary.InvalidCount == len(r.ExpectedApplications)+len(r.ExpectedDependencies)){ + if outputMatchingSummary.ValidCount+outputMatchingSummary.InvalidCount == len(r.ExpectedApplications)+len(r.ExpectedDependencies) { break } time.Sleep(time.Second) @@ -79,7 +80,8 @@ func TestImportCSV(t *testing.T) { t.Errorf("Mismatch in number of Contributors: Expected %d, Actual %d", len(r.ExpectedApplications[i].Contributors), len(gotApp.Contributors)) } else { for j, contributor := range gotApp.Contributors { - if contributor.Name != r.ExpectedApplications[i].Contributors[j].Name {} + if contributor.Name != r.ExpectedApplications[i].Contributors[j].Name { + } } } } @@ -98,7 +100,7 @@ func TestImportCSV(t *testing.T) { t.Errorf("Mismatch in imported Dependency: Expected %s, Actual %s", r.ExpectedDependencies[i].From.Name, importedDep.From.Name) } } - } + } // Get summaries of the Input ID. outputImportSummary := api.ImportSummary{} @@ -107,12 +109,12 @@ func TestImportCSV(t *testing.T) { // Get all imports. var outputImports []api.Import assert.Should(t, Client.Get(api.ImportsRoot, &outputImports)) - + // Check for number of imports. if len(outputImports) != len(r.ExpectedApplications)+len(r.ExpectedDependencies) { t.Errorf("Mismatch in number of imports") } - + // Checks for individual applications and dependencies. j, k := 0, 0 for _, imp := range outputImports { diff --git a/test/api/jobfunction/api_test.go b/test/api/jobfunction/api_test.go index 6e27c265d..b3cf12f16 100644 --- a/test/api/jobfunction/api_test.go +++ b/test/api/jobfunction/api_test.go @@ -75,7 +75,6 @@ func TestJobFunctionList(t *testing.T) { } } - func TestJobFunctionSeed(t *testing.T) { got, err := JobFunction.List() if err != nil { diff --git a/test/api/jobfunction/pkg.go b/test/api/jobfunction/pkg.go index 9514bd97a..0953a0c3f 100644 --- a/test/api/jobfunction/pkg.go +++ b/test/api/jobfunction/pkg.go @@ -6,11 +6,10 @@ import ( ) var ( - RichClient *binding.RichClient + RichClient *binding.RichClient JobFunction binding.JobFunction ) - func init() { // Prepare RichClient and login to Hub API (configured from env variables). RichClient = client.PrepareRichClient() diff --git a/test/api/proxy/api_test.go b/test/api/proxy/api_test.go index eecb73b72..b4f003ec8 100644 --- a/test/api/proxy/api_test.go +++ b/test/api/proxy/api_test.go @@ -6,7 +6,7 @@ import ( ) func TestProxyGetUpdate(t *testing.T) { - for _, id := range []uint{1,2} { // Existing proxies in Hub have IDs 1, 2 + for _, id := range []uint{1, 2} { // Existing proxies in Hub have IDs 1, 2 t.Run(fmt.Sprint(id), func(t *testing.T) { // Get. orig, err := Proxy.Get(id) diff --git a/test/api/proxy/pkg.go b/test/api/proxy/pkg.go index 2a44c86ff..1762fd86f 100644 --- a/test/api/proxy/pkg.go +++ b/test/api/proxy/pkg.go @@ -7,10 +7,9 @@ import ( var ( RichClient *binding.RichClient - Proxy binding.Proxy + Proxy binding.Proxy ) - func init() { // Prepare RichClient and login to Hub API (configured from env variables). RichClient = client.PrepareRichClient() diff --git a/test/api/questionnaire/pkg.go b/test/api/questionnaire/pkg.go index 479a880a6..2d443115c 100644 --- a/test/api/questionnaire/pkg.go +++ b/test/api/questionnaire/pkg.go @@ -6,11 +6,10 @@ import ( ) var ( - RichClient *binding.RichClient + RichClient *binding.RichClient Questionnaire binding.Questionnaire ) - func init() { // Prepare RichClient and login to Hub API (configured from env variables). RichClient = client.PrepareRichClient() diff --git a/test/api/questionnaire/samples.go b/test/api/questionnaire/samples.go index 213bdfb41..988dbf0c9 100644 --- a/test/api/questionnaire/samples.go +++ b/test/api/questionnaire/samples.go @@ -50,4 +50,4 @@ var ( func uint2ptr(u uint) *uint { return &u -} \ No newline at end of file +} diff --git a/test/api/ruleset/pkg.go b/test/api/ruleset/pkg.go index 85c2911b9..e86d90eaf 100644 --- a/test/api/ruleset/pkg.go +++ b/test/api/ruleset/pkg.go @@ -7,10 +7,9 @@ import ( var ( RichClient *binding.RichClient - RuleSet binding.RuleSet + RuleSet binding.RuleSet ) - func init() { // Prepare RichClient and login to Hub API (configured from env variables). RichClient = client.PrepareRichClient() diff --git a/test/api/schema/pkg.go b/test/api/schema/pkg.go index 938d6cd83..852b6d133 100644 --- a/test/api/schema/pkg.go +++ b/test/api/schema/pkg.go @@ -9,7 +9,6 @@ var ( RichClient *binding.RichClient ) - func init() { // Prepare RichClient and login to Hub API (configured from env variables). RichClient = client.PrepareRichClient() diff --git a/test/api/setting/pkg.go b/test/api/setting/pkg.go index 05b9acfef..5b63c4949 100644 --- a/test/api/setting/pkg.go +++ b/test/api/setting/pkg.go @@ -7,10 +7,9 @@ import ( var ( RichClient *binding.RichClient - Setting binding.Setting + Setting binding.Setting ) - func init() { // Prepare RichClient and login to Hub API (configured from env variables). RichClient = client.PrepareRichClient() diff --git a/test/api/setting/samples.go b/test/api/setting/samples.go index f49a73768..b360cbd1f 100644 --- a/test/api/setting/samples.go +++ b/test/api/setting/samples.go @@ -7,9 +7,9 @@ import ( // Set of valid resources for tests and reuse. var ( SampleSetting = api.Setting{ - Key: "sample.setting.1", + Key: "sample.setting.1", Value: "data-123", } - + Samples = []api.Setting{SampleSetting} ) diff --git a/test/api/stakeholder/pkg.go b/test/api/stakeholder/pkg.go index af5451a69..f1cdac79b 100644 --- a/test/api/stakeholder/pkg.go +++ b/test/api/stakeholder/pkg.go @@ -6,11 +6,10 @@ import ( ) var ( - RichClient *binding.RichClient + RichClient *binding.RichClient Stakeholder binding.Stakeholder ) - func init() { // Prepare RichClient and login to Hub API (configured from env variables). RichClient = client.PrepareRichClient() diff --git a/test/api/stakeholdergroup/pkg.go b/test/api/stakeholdergroup/pkg.go index b6c68f3d3..64e037759 100644 --- a/test/api/stakeholdergroup/pkg.go +++ b/test/api/stakeholdergroup/pkg.go @@ -6,11 +6,10 @@ import ( ) var ( - RichClient *binding.RichClient + RichClient *binding.RichClient StakeholderGroup binding.StakeholderGroup ) - func init() { // Prepare RichClient and login to Hub API (configured from env variables). RichClient = client.PrepareRichClient() diff --git a/test/api/tag/api_test.go b/test/api/tag/api_test.go index 5e28b1de7..1b9dd2aa8 100644 --- a/test/api/tag/api_test.go +++ b/test/api/tag/api_test.go @@ -75,7 +75,6 @@ func TestTagList(t *testing.T) { } } - func TestTagSeed(t *testing.T) { got, err := Tag.List() if err != nil { @@ -84,4 +83,4 @@ func TestTagSeed(t *testing.T) { if len(got) < 1 { t.Errorf("Seed looks empty, but it shouldn't.") } -} \ No newline at end of file +} diff --git a/test/api/tag/pkg.go b/test/api/tag/pkg.go index 4233d6337..57e2254e5 100644 --- a/test/api/tag/pkg.go +++ b/test/api/tag/pkg.go @@ -7,10 +7,9 @@ import ( var ( RichClient *binding.RichClient - Tag binding.Tag + Tag binding.Tag ) - func init() { // Prepare RichClient and login to Hub API (configured from env variables). RichClient = client.PrepareRichClient() diff --git a/test/api/tagcategory/api_test.go b/test/api/tagcategory/api_test.go index fa0ca44e9..30b1532e9 100644 --- a/test/api/tagcategory/api_test.go +++ b/test/api/tagcategory/api_test.go @@ -75,7 +75,6 @@ func TestTagCategoryList(t *testing.T) { } } - func TestTagCategorySeed(t *testing.T) { got, err := TagCategory.List() if err != nil { diff --git a/test/api/tagcategory/pkg.go b/test/api/tagcategory/pkg.go index 0e51b55a0..a3ffeb75f 100644 --- a/test/api/tagcategory/pkg.go +++ b/test/api/tagcategory/pkg.go @@ -6,11 +6,10 @@ import ( ) var ( - RichClient *binding.RichClient + RichClient *binding.RichClient TagCategory binding.TagCategory ) - func init() { // Prepare RichClient and login to Hub API (configured from env variables). RichClient = client.PrepareRichClient() diff --git a/test/api/task/pkg.go b/test/api/task/pkg.go index d32bde185..02359226e 100644 --- a/test/api/task/pkg.go +++ b/test/api/task/pkg.go @@ -7,10 +7,9 @@ import ( var ( RichClient *binding.RichClient - Task binding.Task + Task binding.Task ) - func init() { // Prepare RichClient and login to Hub API (configured from env variables). RichClient = client.PrepareRichClient() diff --git a/test/assert/equality.go b/test/assert/equality.go index cc860065e..7167a52c0 100644 --- a/test/assert/equality.go +++ b/test/assert/equality.go @@ -4,7 +4,6 @@ import ( "fmt" ) -// // Simple equality check working for flat types (no nested types passed by reference). func FlatEqual(got, expected interface{}) bool { return fmt.Sprintf("%v", got) == fmt.Sprintf("%v", expected) diff --git a/test/assert/error.go b/test/assert/error.go index 1316167c0..31ef8f001 100644 --- a/test/assert/error.go +++ b/test/assert/error.go @@ -4,7 +4,6 @@ import ( "testing" ) -// // Check error and if present, fail the test case. // Examples usage: client.Should(t, task.Create(&r)) func Should(t *testing.T, err error) { @@ -13,7 +12,6 @@ func Should(t *testing.T, err error) { } } -// // Check error and if present, fail and stop the test suite. // Examples usage: client.Must(t, task.Create(&r)) func Must(t *testing.T, err error) { diff --git a/test/assert/file.go b/test/assert/file.go index d5ff51530..593314baf 100644 --- a/test/assert/file.go +++ b/test/assert/file.go @@ -7,7 +7,6 @@ import ( "os" ) -// // Compare two files content using sha256sum function. func EqualFileContent(gotPath, expectedPath string) bool { got, err := os.Open(gotPath) diff --git a/tracker/jira.go b/tracker/jira.go index ff3a22dfa..8c757acd6 100644 --- a/tracker/jira.go +++ b/tracker/jira.go @@ -26,20 +26,17 @@ const ( JiraEndpointMyself = JiraEndpointBase + "/myself" ) -// // JiraConnector for the Jira Cloud API type JiraConnector struct { tracker *model.Tracker } -// // With updates the connector with the Tracker model. func (r *JiraConnector) With(t *model.Tracker) { r.tracker = t _ = r.tracker.Identity.Decrypt() } -// // Create the ticket in Jira. func (r *JiraConnector) Create(t *model.Ticket) (err error) { client, err := r.client() @@ -82,7 +79,6 @@ func (r *JiraConnector) Create(t *model.Ticket) (err error) { return } -// // RefreshAll retrieves fresh status information for all the tracker's tickets. func (r *JiraConnector) RefreshAll() (tickets map[*model.Ticket]bool, err error) { client, err := r.client() @@ -143,7 +139,6 @@ func (r *JiraConnector) RefreshAll() (tickets map[*model.Ticket]bool, err error) return } -// // Projects returns a list of Projects. func (r *JiraConnector) Projects() (projects []Project, err error) { client, err := r.client() @@ -172,7 +167,6 @@ func (r *JiraConnector) Projects() (projects []Project, err error) { return } -// // Project returns a Project. func (r *JiraConnector) Project(id string) (project Project, err error) { client, err := r.client() @@ -199,7 +193,6 @@ func (r *JiraConnector) Project(id string) (project Project, err error) { return } -// // IssueTypes returns a list of IssueTypes for a Project. func (r *JiraConnector) IssueTypes(id string) (issueTypes []IssueType, err error) { client, err := r.client() @@ -231,7 +224,6 @@ func (r *JiraConnector) IssueTypes(id string) (issueTypes []IssueType, err error return } -// // client builds a Jira API client for the tracker. func (r *JiraConnector) client() (client *jira.Client, err error) { transport := http.DefaultTransport.(*http.Transport).Clone() @@ -267,7 +259,6 @@ func (r *JiraConnector) client() (client *jira.Client, err error) { return } -// // TestConnection to Jira Cloud. func (r *JiraConnector) TestConnection() (connected bool, err error) { client, err := r.client() @@ -292,7 +283,6 @@ func (r *JiraConnector) TestConnection() (connected bool, err error) { return } -// // status returns a normalized status based on the issue status category. func status(issue *jira.Issue) (s string) { key := "" @@ -313,7 +303,6 @@ func status(issue *jira.Issue) (s string) { return } -// // handleJiraError simplifies dealing with errors from the Jira API. func handleJiraError(response *jira.Response, in error) (out error) { if in == nil { @@ -343,13 +332,11 @@ func handleJiraError(response *jira.Response, in error) (out error) { return } -// // clientWrapper wraps the http client used by the jira client. type clientWrapper struct { client *http.Client } -// // Do applies an Accept header before performing the request. func (r *clientWrapper) Do(req *http.Request) (*http.Response, error) { req.Header.Add("Accept", "application/json") @@ -357,7 +344,6 @@ func (r *clientWrapper) Do(req *http.Request) (*http.Response, error) { return resp, err } -// // jiraError is a catch-all structure for the various ways that the // Jira API can report an error in JSON format. type jiraError struct { @@ -366,7 +352,6 @@ type jiraError struct { Errors map[string]string `json:"errors"` } -// // Error reports the consolidated error message. func (r *jiraError) Error() (error string) { if len(r.Message) > 0 { diff --git a/tracker/manager.go b/tracker/manager.go index e5948aedc..7a451d8f6 100644 --- a/tracker/manager.go +++ b/tracker/manager.go @@ -2,11 +2,12 @@ package tracker import ( "context" + "time" + "github.com/jortel/go-utils/logr" "github.com/konveyor/tackle2-hub/model" "gorm.io/gorm" "gorm.io/gorm/clause" - "time" ) var ( diff --git a/tracker/pkg.go b/tracker/pkg.go index 996de6f1e..45a0d793d 100644 --- a/tracker/pkg.go +++ b/tracker/pkg.go @@ -11,7 +11,6 @@ const ( JiraOnPrem = "jira-onprem" ) -// // Ticket status const ( New = "New" @@ -20,7 +19,6 @@ const ( Unknown = "Unknown" ) -// // Auth kinds const ( BearerAuth = "bearer" @@ -57,7 +55,6 @@ func NewConnector(t *model.Tracker) (conn Connector, err error) { return } -// // Project represents an external ticket tracker's project // in which an issue can be created. type Project struct { @@ -65,7 +62,6 @@ type Project struct { Name string } -// // IssueType represents a type of issue that can be created on // an external issue tracker. type IssueType struct {