Skip to content

Commit 2630542

Browse files
committed
Merge branch 'develop' of github.com:devtron-labs/devtron into build-worker-status
# Conflicts: # wire_gen.go
2 parents 5c07fc7 + 27e8cc5 commit 2630542

File tree

108 files changed

+2184
-621
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+2184
-621
lines changed

.github/workflows/multiarch_new.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ jobs:
4141
local image="$1"
4242
local image_ref=$(echo $image | sed 's/:.*//')
4343
44-
# skipping the check for 'inception', 'postgres' , 'postgres_exporter' and 'workflow-controller' images
45-
if [[ "$image_ref" == "inception" || "$image_ref" == "postgres" || "$image_ref" == "postgres_exporter" || "$image_ref" == "workflow-controller" ]]; then
44+
# skipping the check for 'inception', 'postgres' , 'postgres_exporter', 'workflow-controller', 'casbin' and 'scoop' images
45+
if [[ "$image_ref" == "inception" || "$image_ref" == "postgres" || "$image_ref" == "postgres_exporter" || "$image_ref" == "workflow-controller" || "$image_ref" == "casbin" || "$image_ref" == "scoop" ]]; then
4646
return
4747
fi
4848

api/restHandler/app/appList/AppListingRestHandler_ent.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ func (handler AppListingRestHandlerImpl) GetAllAppEnvsFromResourceNames(w http.R
1515
}
1616

1717
func (handler AppListingRestHandlerImpl) updateApprovalConfigDataInAppDetailResp(appDetail AppView.AppDetailContainer, appId, envId int) (AppView.AppDetailContainer, error) {
18-
return AppView.AppDetailContainer{}, nil
18+
return appDetail, nil
1919
}

cmd/external-app/wire.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ import (
8080
"github.com/devtron-labs/devtron/pkg/kubernetesResourceAuditLogs"
8181
repository2 "github.com/devtron-labs/devtron/pkg/kubernetesResourceAuditLogs/repository"
8282
"github.com/devtron-labs/devtron/pkg/pipeline"
83-
"github.com/devtron-labs/devtron/pkg/policyGovernance/security/imageScanning"
84-
security2 "github.com/devtron-labs/devtron/pkg/policyGovernance/security/imageScanning/repository"
83+
"github.com/devtron-labs/devtron/pkg/policyGovernance/security/scanTool"
84+
security2 "github.com/devtron-labs/devtron/pkg/policyGovernance/security/scanTool/repository"
8585
"github.com/devtron-labs/devtron/pkg/sql"
8686
util2 "github.com/devtron-labs/devtron/pkg/util"
8787
util3 "github.com/devtron-labs/devtron/util"
@@ -130,6 +130,7 @@ func InitializeApp() (*App, error) {
130130
telemetry.NewPosthogClient,
131131
delete2.NewDeleteServiceImpl,
132132
gitMaterial.GitMaterialWireSet,
133+
scanTool.ScanToolWireSet,
133134

134135
sql.NewTransactionUtilImpl,
135136

@@ -221,9 +222,6 @@ func InitializeApp() (*App, error) {
221222
kubernetesResourceAuditLogs.Newk8sResourceHistoryServiceImpl,
222223
wire.Bind(new(kubernetesResourceAuditLogs.K8sResourceHistoryService), new(*kubernetesResourceAuditLogs.K8sResourceHistoryServiceImpl)),
223224

224-
imageScanning.NewScanToolMetadataServiceImpl,
225-
wire.Bind(new(imageScanning.ScanToolMetadataService), new(*imageScanning.ScanToolMetadataServiceImpl)),
226-
227225
security2.NewScanToolMetadataRepositoryImpl,
228226
wire.Bind(new(security2.ScanToolMetadataRepository), new(*security2.ScanToolMetadataRepositoryImpl)),
229227

cmd/external-app/wire_gen.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fetchAllEnv/fetchAllEnv.go

Lines changed: 2 additions & 203 deletions
Original file line numberDiff line numberDiff line change
@@ -17,210 +17,9 @@
1717
package main
1818

1919
import (
20-
"encoding/json"
21-
"errors"
22-
"go/ast"
23-
"go/parser"
24-
"go/token"
25-
"log"
26-
"os"
27-
"path/filepath"
28-
"reflect"
29-
"sort"
30-
"strings"
31-
"text/template"
20+
"github.com/devtron-labs/common-lib/fetchAllEnv"
3221
)
3322

34-
type EnvField struct {
35-
Env string
36-
EnvType string
37-
EnvValue string
38-
EnvDescription string
39-
Example string
40-
Deprecated string
41-
}
42-
43-
type CategoryField struct {
44-
Category string
45-
Fields []EnvField
46-
}
47-
48-
const (
49-
categoryCommentStructPrefix = "CATEGORY="
50-
defaultCategory = "DEVTRON"
51-
deprecatedDefaultValue = "false"
52-
53-
envFieldTypeTag = "env"
54-
envDefaultFieldTypeTag = "envDefault"
55-
envDescriptionFieldTypeTag = "description"
56-
envPossibleValuesFieldTypeTag = "example"
57-
envDeprecatedFieldTypeTag = "deprecated"
58-
MARKDOWN_FILENAME = "env_gen.md"
59-
MARKDOWN_JSON_FILENAME = "env_gen.json"
60-
)
61-
62-
const MarkdownTemplate = `
63-
{{range . }}
64-
## {{ .Category }} Related Environment Variables
65-
| Key | Type | Default Value | Description | Example | Deprecated |
66-
|-------|----------|-------------------|-------------------|-----------------------|------------------|
67-
{{range .Fields }} | {{ .Env }} | {{ .EnvType }} |{{ .EnvValue }} | {{ .EnvDescription }} | {{ .Example }} | {{ .Deprecated }} |
68-
{{end}}
69-
{{end}}`
70-
7123
func main() {
72-
WalkThroughProject()
73-
return
74-
}
75-
76-
func WalkThroughProject() {
77-
categoryFieldsMap := make(map[string][]EnvField)
78-
uniqueKeys := make(map[string]bool)
79-
err := filepath.Walk(".", func(path string, info os.FileInfo, err error) error {
80-
if err != nil {
81-
return err
82-
}
83-
if !info.IsDir() && strings.HasSuffix(path, ".go") {
84-
err = processGoFile(path, categoryFieldsMap, uniqueKeys)
85-
if err != nil {
86-
log.Println("error in processing go file", err)
87-
return err
88-
}
89-
}
90-
return nil
91-
})
92-
if err != nil {
93-
return
94-
}
95-
writeToFile(categoryFieldsMap)
96-
}
97-
98-
func processGoFile(filePath string, categoryFieldsMap map[string][]EnvField, uniqueKeys map[string]bool) error {
99-
fset := token.NewFileSet()
100-
node, err := parser.ParseFile(fset, filePath, nil, parser.ParseComments)
101-
if err != nil {
102-
log.Println("error parsing file:", err)
103-
return err
104-
}
105-
ast.Inspect(node, func(n ast.Node) bool {
106-
if genDecl, ok := n.(*ast.GenDecl); ok {
107-
// checking if type declaration, one of [func, map, struct, array, channel, interface]
108-
if genDecl.Tok == token.TYPE {
109-
for _, spec := range genDecl.Specs {
110-
if typeSpec, ok := spec.(*ast.TypeSpec); ok {
111-
// only checking struct type declarations
112-
if structType, ok2 := typeSpec.Type.(*ast.StructType); ok2 {
113-
allFields := make([]EnvField, 0, len(structType.Fields.List))
114-
for _, field := range structType.Fields.List {
115-
if field.Tag != nil {
116-
envField := getEnvKeyAndValue(field)
117-
envKey := envField.Env
118-
if len(envKey) == 0 || uniqueKeys[envKey] {
119-
continue
120-
}
121-
allFields = append(allFields, envField)
122-
uniqueKeys[envKey] = true
123-
}
124-
}
125-
if len(allFields) > 0 {
126-
category := getCategoryForAStruct(genDecl)
127-
categoryFieldsMap[category] = append(categoryFieldsMap[category], allFields...)
128-
}
129-
}
130-
}
131-
}
132-
}
133-
}
134-
return true
135-
})
136-
return nil
137-
}
138-
139-
func getEnvKeyAndValue(field *ast.Field) EnvField {
140-
tag := reflect.StructTag(strings.Trim(field.Tag.Value, "`")) // remove surrounding backticks
141-
142-
envKey := addReadmeTableDelimiterEscapeChar(tag.Get(envFieldTypeTag))
143-
envValue := addReadmeTableDelimiterEscapeChar(tag.Get(envDefaultFieldTypeTag))
144-
envDescription := addReadmeTableDelimiterEscapeChar(tag.Get(envDescriptionFieldTypeTag))
145-
envPossibleValues := addReadmeTableDelimiterEscapeChar(tag.Get(envPossibleValuesFieldTypeTag))
146-
envDeprecated := addReadmeTableDelimiterEscapeChar(tag.Get(envDeprecatedFieldTypeTag))
147-
// check if there exist any value provided in env for this field
148-
if value, ok := os.LookupEnv(envKey); ok {
149-
envValue = value
150-
}
151-
env := EnvField{
152-
Env: envKey,
153-
EnvValue: envValue,
154-
EnvDescription: envDescription,
155-
Example: envPossibleValues,
156-
Deprecated: envDeprecated,
157-
}
158-
if indent, ok := field.Type.(*ast.Ident); ok && indent != nil {
159-
env.EnvType = indent.Name
160-
}
161-
if len(envDeprecated) == 0 {
162-
env.Deprecated = deprecatedDefaultValue
163-
}
164-
return env
165-
}
166-
167-
func getCategoryForAStruct(genDecl *ast.GenDecl) string {
168-
category := defaultCategory
169-
if genDecl.Doc != nil {
170-
commentTexts := strings.Split(genDecl.Doc.Text(), "\n")
171-
for _, comment := range commentTexts {
172-
commentText := strings.TrimPrefix(strings.ReplaceAll(comment, " ", ""), "//") // this can happen if comment group is in /* */
173-
if strings.HasPrefix(commentText, categoryCommentStructPrefix) {
174-
categories := strings.Split(strings.TrimPrefix(commentText, categoryCommentStructPrefix), ",")
175-
if len(categories) > 0 && len(categories[0]) > 0 { //only supporting one category as of now
176-
category = categories[0] //overriding category
177-
break
178-
}
179-
}
180-
}
181-
}
182-
return category
183-
}
184-
185-
func addReadmeTableDelimiterEscapeChar(s string) string {
186-
return strings.ReplaceAll(s, "|", `\|`)
187-
}
188-
189-
func writeToFile(categoryFieldsMap map[string][]EnvField) {
190-
cfs := make([]CategoryField, 0, len(categoryFieldsMap))
191-
for category, allFields := range categoryFieldsMap {
192-
sort.Slice(allFields, func(i, j int) bool {
193-
return allFields[i].Env < allFields[j].Env
194-
})
195-
196-
cfs = append(cfs, CategoryField{
197-
Category: category,
198-
Fields: allFields,
199-
})
200-
}
201-
sort.Slice(cfs, func(i, j int) bool {
202-
return cfs[i].Category < cfs[j].Category
203-
})
204-
file, err := os.Create(MARKDOWN_FILENAME)
205-
if err != nil && !errors.Is(err, os.ErrExist) {
206-
panic(err)
207-
}
208-
defer file.Close()
209-
tmpl, err := template.New("markdown").Parse(MarkdownTemplate)
210-
if err != nil {
211-
panic(err)
212-
}
213-
err = tmpl.Execute(file, cfs)
214-
if err != nil {
215-
panic(err)
216-
}
217-
cfsMarshaled, err := json.Marshal(cfs)
218-
if err != nil {
219-
log.Println("error marshalling category fields:", err)
220-
panic(err)
221-
}
222-
err = os.WriteFile(MARKDOWN_JSON_FILENAME, cfsMarshaled, 0644)
223-
if err != nil {
224-
panic(err)
225-
}
24+
fetchAllEnv.FetchEnvAndWriteToFile()
22625
}

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,8 @@ require gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
288288

289289
replace (
290290
github.com/argoproj/argo-workflows/v3 v3.5.10 => github.com/devtron-labs/argo-workflows/v3 v3.5.13
291-
github.com/devtron-labs/authenticator => github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250117064214-73c2e66ce2d7
292-
github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250122110043-4d939279c70a
291+
github.com/devtron-labs/authenticator => github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250127104410-85d6bfe0b45f
292+
github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250127104410-85d6bfe0b45f
293293
github.com/go-check/check => github.com/go-check/check v0.0.0-20180628173108-788fd7840127
294294
github.com/googleapis/gnostic => github.com/googleapis/gnostic v0.5.5
295295
k8s.io/api => k8s.io/api v0.29.7

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -792,10 +792,10 @@ github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc h1:VRRKCwnzq
792792
github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU=
793793
github.com/devtron-labs/argo-workflows/v3 v3.5.13 h1:3pINq0gXOSeTw2z/vYe+j80lRpSN5Rp/8mfQORh8SmU=
794794
github.com/devtron-labs/argo-workflows/v3 v3.5.13/go.mod h1:/vqxcovDPT4zqr4DjR5v7CF8ggpY1l3TSa2CIG3jmjA=
795-
github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250117064214-73c2e66ce2d7 h1:Z29616pM3W6fcDvFsiX6JTWz2lYvdZdqzIRBfBwnK1U=
796-
github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250117064214-73c2e66ce2d7/go.mod h1:5lv4Wfj5ERhhvDGXe2IeES6qxjvUVCcohaRwKnWBMNo=
797-
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250122110043-4d939279c70a h1:kDemKb2wGKXaRjRqWuu7FIGcfeacoW0kH9yzpSDTWN8=
798-
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250122110043-4d939279c70a/go.mod h1:1QJJLpgJSkb5Jm9xPeKAk+kXb0QgBOOOgJj0cgYhAVA=
795+
github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250127104410-85d6bfe0b45f h1:8nYP02cYX/9e3H8YfBV4b8hP4WwbGY/dUMNu+N9cH1Q=
796+
github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250127104410-85d6bfe0b45f/go.mod h1:5lv4Wfj5ERhhvDGXe2IeES6qxjvUVCcohaRwKnWBMNo=
797+
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250127104410-85d6bfe0b45f h1:4wUbt+83DmpZFqYS69CJxNtBpSuCb58UwqOrWsZG82s=
798+
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250127104410-85d6bfe0b45f/go.mod h1:1QJJLpgJSkb5Jm9xPeKAk+kXb0QgBOOOgJj0cgYhAVA=
799799
github.com/devtron-labs/go-bitbucket v0.9.60-beta h1:VEx1jvDgdtDPS6A1uUFoaEi0l1/oLhbr+90xOwr6sDU=
800800
github.com/devtron-labs/go-bitbucket v0.9.60-beta/go.mod h1:GnuiCesvh8xyHeMCb+twm8lBR/kQzJYSKL28ZfObp1Y=
801801
github.com/devtron-labs/protos v0.0.3-0.20240802105333-92ee9bb85d80 h1:xwbTeijNTf4/j1v+tSfwVqwLVnReas/NqEKeQHvSTys=

internal/sql/repository/AppListingRepository.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,10 @@ func (impl AppListingRepositoryImpl) FetchAppsByEnvironmentV2(appListingFilter h
308308

309309
// if any pipeline found get the latest deployment time
310310
if len(pipelineIds) > 0 {
311-
query := impl.appListingRepositoryQueryBuilder.BuildAppListingQueryLastDeploymentTimeV2(pipelineIds)
311+
query, queryParams := impl.appListingRepositoryQueryBuilder.BuildAppListingQueryLastDeploymentTimeV2(pipelineIds)
312312
impl.Logger.Debugw("basic app detail query: ", query)
313313
start := time.Now()
314-
_, err := impl.dbConnection.Query(&lastDeployedTimeDTO, query)
314+
_, err := impl.dbConnection.Query(&lastDeployedTimeDTO, query, queryParams...)
315315
middleware.AppListingDuration.WithLabelValues("buildAppListingQueryLastDeploymentTime", "devtron").Observe(time.Since(start).Seconds())
316316
if err != nil {
317317
impl.Logger.Errorw("error in getting latest deployment time for given pipelines", "err", err, "pipelines", pipelineIds, "query", query)

internal/sql/repository/CiArtifactRepository.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,8 @@ func (impl CiArtifactRepositoryImpl) GetArtifactsByCDPipelineV3(listingFilterOpt
362362
artifactsResp := make([]*CiArtifactWithExtraData, 0, listingFilterOpts.Limit)
363363
var artifacts []*CiArtifact
364364
totalCount := 0
365-
finalQuery := BuildQueryForParentTypeCIOrWebhook(*listingFilterOpts)
366-
_, err := impl.dbConnection.Query(&artifactsResp, finalQuery)
365+
finalQuery, finalQueryParams := BuildQueryForParentTypeCIOrWebhook(*listingFilterOpts)
366+
_, err := impl.dbConnection.Query(&artifactsResp, finalQuery, finalQueryParams...)
367367
if err != nil {
368368
return nil, totalCount, err
369369
}

internal/sql/repository/CiArtifactsListingQueryBuilder.go

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,28 @@ import (
2020
"fmt"
2121
"github.com/devtron-labs/devtron/api/bean"
2222
"github.com/devtron-labs/devtron/internal/sql/repository/helper"
23+
"github.com/go-pg/pg"
2324
)
2425

2526
const EmptyLikeRegex = "%%"
2627

27-
func BuildQueryForParentTypeCIOrWebhook(listingFilterOpts bean.ArtifactsListFilterOptions) string {
28-
commonPaginatedQueryPart := fmt.Sprintf(" cia.image LIKE '%v'", listingFilterOpts.SearchString)
28+
func BuildQueryForParentTypeCIOrWebhook(listingFilterOpts bean.ArtifactsListFilterOptions) (string, []interface{}) {
29+
commonPaginatedQueryPart, commonPaginatedQueryParams := " cia.image LIKE ?", []interface{}{listingFilterOpts.SearchString}
2930
orderByClause := " ORDER BY cia.id DESC"
30-
limitOffsetQueryPart := fmt.Sprintf(" LIMIT %v OFFSET %v", listingFilterOpts.Limit, listingFilterOpts.Offset)
31+
limitOffsetQueryPart, limitOffsetQueryParams := fmt.Sprintf(" LIMIT ? OFFSET ?"), []interface{}{listingFilterOpts.Limit, listingFilterOpts.Offset}
3132
finalQuery := ""
33+
var finalQueryParams []interface{}
34+
var remainingQueryParams []interface{}
3235
if listingFilterOpts.ParentStageType == bean.CI_WORKFLOW_TYPE {
3336
selectQuery := " SELECT cia.* "
3437
remainingQuery := " FROM ci_artifact cia" +
3538
" INNER JOIN ci_pipeline cp ON (cp.id=cia.pipeline_id or (cp.id=cia.component_id and cia.data_source='post_ci' ) )" +
36-
" INNER JOIN pipeline p ON (p.ci_pipeline_id = cp.id and p.id=%v )" +
39+
" INNER JOIN pipeline p ON (p.ci_pipeline_id = cp.id and p.id=? )" +
3740
" WHERE "
38-
remainingQuery = fmt.Sprintf(remainingQuery, listingFilterOpts.PipelineId)
41+
remainingQueryParams = []interface{}{listingFilterOpts.PipelineId}
3942
if len(listingFilterOpts.ExcludeArtifactIds) > 0 {
40-
remainingQuery += fmt.Sprintf("cia.id NOT IN (%s) AND ", helper.GetCommaSepratedString(listingFilterOpts.ExcludeArtifactIds))
43+
remainingQuery += "cia.id NOT IN (?) AND "
44+
remainingQueryParams = append(remainingQueryParams, pg.In(listingFilterOpts.ExcludeArtifactIds))
4145
}
4246

4347
countQuery := " SELECT count(cia.id) as total_count"
@@ -47,19 +51,24 @@ func BuildQueryForParentTypeCIOrWebhook(listingFilterOpts bean.ArtifactsListFilt
4751
} else if listingFilterOpts.ParentStageType == bean.WEBHOOK_WORKFLOW_TYPE {
4852
selectQuery := " SELECT cia.* "
4953
remainingQuery := " FROM ci_artifact cia " +
50-
" WHERE cia.external_ci_pipeline_id = %v AND "
51-
remainingQuery = fmt.Sprintf(remainingQuery, listingFilterOpts.ParentId)
54+
" WHERE cia.external_ci_pipeline_id = ? AND "
55+
remainingQueryParams = []interface{}{listingFilterOpts.ParentId}
5256
if len(listingFilterOpts.ExcludeArtifactIds) > 0 {
53-
remainingQuery += fmt.Sprintf("cia.id NOT IN (%s) AND ", helper.GetCommaSepratedString(listingFilterOpts.ExcludeArtifactIds))
57+
remainingQuery += "cia.id NOT IN (?) AND "
58+
remainingQueryParams = append(remainingQueryParams, pg.In(listingFilterOpts.ExcludeArtifactIds))
5459
}
5560

5661
countQuery := " SELECT count(cia.id) as total_count"
5762
totalCountQuery := countQuery + remainingQuery + commonPaginatedQueryPart
5863
selectQuery = fmt.Sprintf("%s,(%s) ", selectQuery, totalCountQuery)
5964
finalQuery = selectQuery + remainingQuery + commonPaginatedQueryPart + orderByClause + limitOffsetQueryPart
60-
6165
}
62-
return finalQuery
66+
finalQueryParams = append(finalQueryParams, remainingQueryParams...)
67+
finalQueryParams = append(finalQueryParams, commonPaginatedQueryParams...)
68+
finalQueryParams = append(finalQueryParams, remainingQueryParams...)
69+
finalQueryParams = append(finalQueryParams, commonPaginatedQueryParams...)
70+
finalQueryParams = append(finalQueryParams, limitOffsetQueryParams...)
71+
return finalQuery, finalQueryParams
6372
}
6473

6574
func BuildQueryForArtifactsForCdStage(listingFilterOptions bean.ArtifactsListFilterOptions) string {

0 commit comments

Comments
 (0)