Skip to content

Commit e5f0bb4

Browse files
committed
Merge branch 'main' into cve-severity-image-scan-oss
2 parents 0a991b6 + 8eb880d commit e5f0bb4

Some content is hidden

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

63 files changed

+5594
-475
lines changed

.github/workflows/github_pagerduty_score_calculation.yml

+9-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,15 @@ jobs:
1414
uses: actions/setup-python@v2
1515
with:
1616
python-version: '3.x'
17-
17+
- if: github.event.label.name == 'pager-duty'
18+
name: discord webhook
19+
env:
20+
DISCORD_WEBHOOK: ${{ secrets.GH_ISSUES_DISCORD_WEBHOOK }}
21+
DISCORD_WEBHOOK_FORUM: ${{ secrets.PAGERDUTY_DISCORD_WEBHOOK }}
22+
ENABLE_FORUM: true
23+
uses: devtron-labs/action-discord@master
24+
with:
25+
args: " ${{ github.event.issue.title }} ${{ github.event.issue.html_url }}"
1826
- name: Check if pager-duty template is used
1927
if: ${{ contains(github.event.issue.labels.*.name, 'pager-duty') && contains(github.event.issue.labels.*.name, 'bug') }}
2028
run: |

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@
44
.env
55
/cmd/external-app/devtron-ea
66
devtron
7-
/vendor/github.com/argoproj/argo-cd/assets

Wire.go

+8
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,10 @@ import (
7575
"github.com/devtron-labs/devtron/cel"
7676
"github.com/devtron-labs/devtron/client/argocdServer"
7777
"github.com/devtron-labs/devtron/client/argocdServer/application"
78+
"github.com/devtron-labs/devtron/client/argocdServer/certificate"
7879
cluster2 "github.com/devtron-labs/devtron/client/argocdServer/cluster"
7980
"github.com/devtron-labs/devtron/client/argocdServer/connection"
81+
repocreds "github.com/devtron-labs/devtron/client/argocdServer/repocreds"
8082
repository2 "github.com/devtron-labs/devtron/client/argocdServer/repository"
8183
session2 "github.com/devtron-labs/devtron/client/argocdServer/session"
8284
"github.com/devtron-labs/devtron/client/cron"
@@ -973,6 +975,9 @@ func InitializeApp() (*App, error) {
973975
imageDigestPolicy.NewImageDigestPolicyServiceImpl,
974976
wire.Bind(new(imageDigestPolicy.ImageDigestPolicyService), new(*imageDigestPolicy.ImageDigestPolicyServiceImpl)),
975977

978+
certificate.NewServiceClientImpl,
979+
wire.Bind(new(certificate.Client), new(*certificate.ServiceClientImpl)),
980+
976981
appStoreRestHandler.AppStoreWireSet,
977982

978983
cel.NewCELServiceImpl,
@@ -983,6 +988,9 @@ func InitializeApp() (*App, error) {
983988

984989
common.NewDeploymentConfigServiceImpl,
985990
wire.Bind(new(common.DeploymentConfigService), new(*common.DeploymentConfigServiceImpl)),
991+
992+
repocreds.NewServiceClientImpl,
993+
wire.Bind(new(repocreds.ServiceClient), new(*repocreds.ServiceClientImpl)),
986994
)
987995
return &App{}, nil
988996
}

api/bean/gitOps/GitOpsConfig.go

+22-13
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,30 @@
1616

1717
package gitOps
1818

19-
import "time"
19+
import (
20+
"github.com/devtron-labs/devtron/api/bean"
21+
"time"
22+
)
2023

2124
type GitOpsConfigDto struct {
22-
Id int `json:"id,omitempty"`
23-
Provider string `json:"provider" validate:"oneof=GITLAB GITHUB AZURE_DEVOPS BITBUCKET_CLOUD"`
24-
Username string `json:"username"`
25-
Token string `json:"token"`
26-
GitLabGroupId string `json:"gitLabGroupId"`
27-
GitHubOrgId string `json:"gitHubOrgId"`
28-
Host string `json:"host"`
29-
Active bool `json:"active"`
30-
AzureProjectName string `json:"azureProjectName"`
31-
BitBucketWorkspaceId string `json:"bitBucketWorkspaceId"`
32-
BitBucketProjectKey string `json:"bitBucketProjectKey"`
33-
AllowCustomRepository bool `json:"allowCustomRepository"`
25+
Id int `json:"id,omitempty"`
26+
Provider string `json:"provider" validate:"oneof=GITLAB GITHUB AZURE_DEVOPS BITBUCKET_CLOUD"`
27+
Username string `json:"username"`
28+
Token string `json:"token"`
29+
GitLabGroupId string `json:"gitLabGroupId"`
30+
GitHubOrgId string `json:"gitHubOrgId"`
31+
Host string `json:"host"`
32+
Active bool `json:"active"`
33+
AzureProjectName string `json:"azureProjectName"`
34+
BitBucketWorkspaceId string `json:"bitBucketWorkspaceId"`
35+
BitBucketProjectKey string `json:"bitBucketProjectKey"`
36+
AllowCustomRepository bool `json:"allowCustomRepository"`
37+
EnableTLSVerification bool `json:"enableTLSVerification"`
38+
TLSConfig *bean.TLSConfig `json:"tlsConfig"`
39+
40+
IsCADataPresent bool `json:"isCADataPresent"`
41+
IsTLSCertDataPresent bool `json:"isTLSCertDataPresent"`
42+
IsTLSKeyDataPresent bool `json:"isTLSKeyDataPresent"`
3443

3544
// TODO refactoring: create different struct for internal fields
3645
GitRepoName string `json:"-"`

api/bean/tlsConfig.go

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package bean
2+
3+
type TLSConfig struct {
4+
CaData string `json:"caData"`
5+
TLSCertData string `json:"tlsCertData"`
6+
TLSKeyData string `json:"tlsKeyData"`
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package certificate
2+
3+
import (
4+
"context"
5+
"errors"
6+
"github.com/argoproj/argo-cd/v2/pkg/apiclient/certificate"
7+
"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
8+
"github.com/devtron-labs/devtron/client/argocdServer/connection"
9+
"github.com/devtron-labs/devtron/util/argo"
10+
"go.uber.org/zap"
11+
"google.golang.org/grpc"
12+
"time"
13+
)
14+
15+
type Client interface {
16+
ListCertificates(ctx context.Context, query *certificate.RepositoryCertificateQuery, opts ...grpc.CallOption) (*v1alpha1.RepositoryCertificateList, error)
17+
CreateCertificate(ctx context.Context, query *certificate.RepositoryCertificateCreateRequest) (*v1alpha1.RepositoryCertificateList, error)
18+
DeleteCertificate(ctx context.Context, query *certificate.RepositoryCertificateQuery, opts ...grpc.CallOption) (*v1alpha1.RepositoryCertificateList, error)
19+
}
20+
21+
type ServiceClientImpl struct {
22+
logger *zap.SugaredLogger
23+
argoCDConnectionManager connection.ArgoCDConnectionManager
24+
argoUserService argo.ArgoUserService
25+
}
26+
27+
func NewServiceClientImpl(
28+
logger *zap.SugaredLogger,
29+
argoCDConnectionManager connection.ArgoCDConnectionManager,
30+
argoUserService argo.ArgoUserService) *ServiceClientImpl {
31+
return &ServiceClientImpl{
32+
logger: logger,
33+
argoCDConnectionManager: argoCDConnectionManager,
34+
argoUserService: argoUserService,
35+
}
36+
}
37+
38+
func (c *ServiceClientImpl) getService(ctx context.Context) (certificate.CertificateServiceClient, error) {
39+
token, ok := ctx.Value("token").(string)
40+
if !ok {
41+
return nil, errors.New("Unauthorized")
42+
}
43+
conn := c.argoCDConnectionManager.GetConnection(token)
44+
//defer conn.Close()
45+
return certificate.NewCertificateServiceClient(conn), nil
46+
}
47+
48+
func (c *ServiceClientImpl) ListCertificates(ctx context.Context, query *certificate.RepositoryCertificateQuery, opts ...grpc.CallOption) (*v1alpha1.RepositoryCertificateList, error) {
49+
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
50+
defer cancel()
51+
client, err := c.getService(ctx)
52+
if err != nil {
53+
return nil, err
54+
}
55+
return client.ListCertificates(ctx, query)
56+
}
57+
58+
func (c *ServiceClientImpl) CreateCertificate(ctx context.Context, query *certificate.RepositoryCertificateCreateRequest) (*v1alpha1.RepositoryCertificateList, error) {
59+
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
60+
defer cancel()
61+
client, err := c.getService(ctx)
62+
if err != nil {
63+
return nil, err
64+
}
65+
return client.CreateCertificate(ctx, query)
66+
}
67+
68+
func (c *ServiceClientImpl) DeleteCertificate(ctx context.Context, query *certificate.RepositoryCertificateQuery, opts ...grpc.CallOption) (*v1alpha1.RepositoryCertificateList, error) {
69+
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
70+
defer cancel()
71+
client, err := c.getService(ctx)
72+
if err != nil {
73+
return nil, err
74+
}
75+
return client.DeleteCertificate(ctx, query, opts...)
76+
}
+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright (c) 2020-2024. Devtron Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package repository
18+
19+
import (
20+
"context"
21+
"errors"
22+
repocreds "github.com/argoproj/argo-cd/v2/pkg/apiclient/repocreds"
23+
"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
24+
argoApplication "github.com/devtron-labs/devtron/client/argocdServer/bean"
25+
"github.com/devtron-labs/devtron/client/argocdServer/connection"
26+
"go.uber.org/zap"
27+
)
28+
29+
type ServiceClient interface {
30+
CreateRepoCreds(ctx context.Context, query *repocreds.RepoCredsCreateRequest) (*v1alpha1.RepoCreds, error)
31+
}
32+
33+
type ServiceClientImpl struct {
34+
logger *zap.SugaredLogger
35+
argoCDConnectionManager connection.ArgoCDConnectionManager
36+
}
37+
38+
func NewServiceClientImpl(logger *zap.SugaredLogger, argoCDConnectionManager connection.ArgoCDConnectionManager) *ServiceClientImpl {
39+
return &ServiceClientImpl{
40+
logger: logger,
41+
argoCDConnectionManager: argoCDConnectionManager,
42+
}
43+
}
44+
45+
func (r ServiceClientImpl) getService(ctx context.Context) (repocreds.RepoCredsServiceClient, error) {
46+
token, ok := ctx.Value("token").(string)
47+
if !ok {
48+
return nil, errors.New("Unauthorized")
49+
}
50+
conn := r.argoCDConnectionManager.GetConnection(token)
51+
//defer conn.Close()
52+
return repocreds.NewRepoCredsServiceClient(conn), nil
53+
}
54+
55+
func (r ServiceClientImpl) CreateRepoCreds(ctx context.Context, query *repocreds.RepoCredsCreateRequest) (*v1alpha1.RepoCreds, error) {
56+
ctx, cancel := context.WithTimeout(ctx, argoApplication.TimeoutSlow)
57+
defer cancel()
58+
client, err := r.getService(ctx)
59+
if err != nil {
60+
return nil, err
61+
}
62+
return client.CreateRepositoryCredentials(ctx, query)
63+
}

client/argocdServer/repository/Repository.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type ServiceClient interface {
3636
GetAppDetails(ctx context.Context, query *repository2.RepoAppDetailsQuery) (*apiclient.RepoAppDetailsResponse, error)
3737
// Create creates a repo
3838
Create(ctx context.Context, query *repository2.RepoCreateRequest) (*v1alpha1.Repository, error)
39-
// Update updates a repo
39+
// Create creates a repo
4040
Update(ctx context.Context, query *repository2.RepoUpdateRequest) (*v1alpha1.Repository, error)
4141
// Delete deletes a repo
4242
Delete(ctx context.Context, query *repository2.RepoQuery) (*repository2.RepoResponse, error)

client/gitSensor/GitSensorGrpcClient.go

+13-9
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,19 @@ func (client *GrpcApiClientImpl) SaveGitProvider(ctx context.Context, provider *
114114
}
115115
// map req
116116
req := &pb.GitProvider{
117-
Id: int64(provider.Id),
118-
Name: provider.Name,
119-
Url: provider.Url,
120-
UserName: provider.UserName,
121-
Password: provider.Password,
122-
AccessToken: provider.AccessToken,
123-
SshPrivateKey: provider.SshPrivateKey,
124-
AuthMode: string(provider.AuthMode),
125-
Active: provider.Active,
117+
Id: int64(provider.Id),
118+
Name: provider.Name,
119+
Url: provider.Url,
120+
UserName: provider.UserName,
121+
Password: provider.Password,
122+
SshPrivateKey: provider.SshPrivateKey,
123+
AccessToken: provider.AccessToken,
124+
AuthMode: string(provider.AuthMode),
125+
Active: provider.Active,
126+
TlsCert: provider.TlsCert,
127+
TlsKey: provider.TlsKey,
128+
CaCert: provider.CaCert,
129+
EnableTLSVerification: provider.EnableTlsVerification,
126130
}
127131

128132
// fetch

client/gitSensor/GitSensorRestClient.go

+13-9
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,19 @@ type GitMaterial struct {
9090
CloningMode string
9191
}
9292
type GitProvider struct {
93-
Id int
94-
Name string
95-
Url string
96-
UserName string
97-
Password string
98-
SshPrivateKey string
99-
AccessToken string
100-
Active bool
101-
AuthMode repository.AuthMode
93+
Id int
94+
Name string
95+
Url string
96+
UserName string
97+
Password string
98+
SshPrivateKey string
99+
AccessToken string
100+
Active bool
101+
AuthMode repository.AuthMode
102+
EnableTlsVerification bool
103+
CaCert string
104+
TlsCert string
105+
TlsKey string
102106
}
103107

104108
type GitCommit struct {

go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ require (
2222
github.com/davecgh/go-spew v1.1.1
2323
github.com/deckarep/golang-set v1.8.0
2424
github.com/devtron-labs/authenticator v0.4.35-0.20240607135426-c86e868ecee1
25-
github.com/devtron-labs/common-lib v0.0.25-0.20240726165557-8dad78ef6731
25+
github.com/devtron-labs/common-lib v0.0.25-0.20240802103040-a6b975ffa69e
2626
github.com/devtron-labs/go-bitbucket v0.9.60-beta
27-
github.com/devtron-labs/protos v0.0.3-0.20240726064057-dd2990c91e41
27+
github.com/devtron-labs/protos v0.0.3-0.20240802105333-92ee9bb85d80
2828
github.com/evanphx/json-patch v5.7.0+incompatible
2929
github.com/gammazero/workerpool v1.1.3
3030
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32

go.sum

+4-4
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,12 @@ github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc h1:VRRKCwnzq
197197
github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU=
198198
github.com/devtron-labs/authenticator v0.4.35-0.20240607135426-c86e868ecee1 h1:qdkpTAo2Kr0ZicZIVXfNwsGSshpc9OB9j9RzmKYdIwY=
199199
github.com/devtron-labs/authenticator v0.4.35-0.20240607135426-c86e868ecee1/go.mod h1:IkKPPEfgLCMR29he5yv2OCC6iM2R7K5/0AA3k8b9XNc=
200-
github.com/devtron-labs/common-lib v0.0.25-0.20240726165557-8dad78ef6731 h1:BF6RTdwkT0qVqLvvJHZ6CaRV94GxlOj+n6JkEExEKyo=
201-
github.com/devtron-labs/common-lib v0.0.25-0.20240726165557-8dad78ef6731/go.mod h1:UZGPt1ep9Tnd9Ak2sibGSiLr7p3ijO2/JLT+h+pqBuU=
200+
github.com/devtron-labs/common-lib v0.0.25-0.20240802103040-a6b975ffa69e h1:oC1KJ4jeIebSRWtBarETQPmSVhbK06EWAE49g9VukEY=
201+
github.com/devtron-labs/common-lib v0.0.25-0.20240802103040-a6b975ffa69e/go.mod h1:3GN9TABx4D+hVuF69vGYUUx+H8/WelcKw0lUt8aELok=
202202
github.com/devtron-labs/go-bitbucket v0.9.60-beta h1:VEx1jvDgdtDPS6A1uUFoaEi0l1/oLhbr+90xOwr6sDU=
203203
github.com/devtron-labs/go-bitbucket v0.9.60-beta/go.mod h1:GnuiCesvh8xyHeMCb+twm8lBR/kQzJYSKL28ZfObp1Y=
204-
github.com/devtron-labs/protos v0.0.3-0.20240726064057-dd2990c91e41 h1:tIoWy1PDAC6enSBohRt0qroiRXq+bR7qlqk73JlQ9R4=
205-
github.com/devtron-labs/protos v0.0.3-0.20240726064057-dd2990c91e41/go.mod h1:ypUknVph8Ph4dxSlrFoouf7wLedQxHku2LQwgRrdgS4=
204+
github.com/devtron-labs/protos v0.0.3-0.20240802105333-92ee9bb85d80 h1:xwbTeijNTf4/j1v+tSfwVqwLVnReas/NqEKeQHvSTys=
205+
github.com/devtron-labs/protos v0.0.3-0.20240802105333-92ee9bb85d80/go.mod h1:ypUknVph8Ph4dxSlrFoouf7wLedQxHku2LQwgRrdgS4=
206206
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
207207
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
208208
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=

internal/constants/InternalErrorCode.go

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ const (
6565
DockerRegDeleteFailedInDb string = "3009"
6666
DockerRegDeleteFailedInGocd string = "3010"
6767
GitProviderUpdateFailedInSync string = "3011"
68+
GitProviderUpdateRequestIsInvalid string = "3012"
6869
// For conflicts use 900 series
6970
GitOpsConfigValidationConflict string = "3900"
7071

internal/sql/repository/GitOpsConfigRepository.go

+4
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ type GitOpsConfig struct {
5454
BitBucketWorkspaceId string `sql:"bitbucket_workspace_id"`
5555
BitBucketProjectKey string `sql:"bitbucket_project_key"`
5656
EmailId string `sql:"email_id"`
57+
EnableTLSVerification bool `sql:"enable_tls_verification"`
58+
TlsCert string `sql:"tls_cert"`
59+
TlsKey string `sql:"tls_key"`
60+
CaCert string `sql:"ca_cert"`
5761
sql.AuditLog
5862
}
5963

internal/sql/repository/GitProviderRepository.go

+16-12
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,22 @@ const (
3131
)
3232

3333
type GitProvider struct {
34-
tableName struct{} `sql:"git_provider" pg:",discard_unknown_columns"`
35-
Id int `sql:"id,pk"`
36-
Name string `sql:"name,notnull"`
37-
Url string `sql:"url,notnull"`
38-
UserName string `sql:"user_name"`
39-
Password string `sql:"password"`
40-
SshPrivateKey string `sql:"ssh_private_key"`
41-
AccessToken string `sql:"access_token"`
42-
AuthMode AuthMode `sql:"auth_mode,notnull"`
43-
Active bool `sql:"active,notnull"`
44-
Deleted bool `sql:"deleted,notnull"`
45-
GitHostId int `sql:"git_host_id"` //id stored in db git_host( foreign key)
34+
tableName struct{} `sql:"git_provider" pg:",discard_unknown_columns"`
35+
Id int `sql:"id,pk"`
36+
Name string `sql:"name,notnull"`
37+
Url string `sql:"url,notnull"`
38+
UserName string `sql:"user_name"`
39+
Password string `sql:"password"`
40+
SshPrivateKey string `sql:"ssh_private_key"`
41+
AccessToken string `sql:"access_token"`
42+
AuthMode AuthMode `sql:"auth_mode,notnull"`
43+
Active bool `sql:"active,notnull"`
44+
Deleted bool `sql:"deleted,notnull"`
45+
GitHostId int `sql:"git_host_id"` //id stored in db git_host( foreign key)
46+
TlsCert string `sql:"tls_cert"`
47+
TlsKey string `sql:"tls_key"`
48+
CaCert string `sql:"ca_cert"`
49+
EnableTLSVerification bool `sql:"enable_tls_verification"`
4650
sql.AuditLog
4751
}
4852

0 commit comments

Comments
 (0)