Skip to content

Commit

Permalink
Merge branch 'main' into config-diff-phase-2-oss
Browse files Browse the repository at this point in the history
  • Loading branch information
prakash100198 committed Aug 6, 2024
2 parents cf5ce0b + 17c870c commit dacfd8b
Show file tree
Hide file tree
Showing 75 changed files with 5,857 additions and 558 deletions.
3 changes: 2 additions & 1 deletion .gitbook.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,5 @@ redirects:
user-guide/creating-application/workflow/ci-pipeline2: user-guide/creating-application/workflow/ci-pipeline.md
user-guide/clusters: user-guide/resource-browser.md
usage/clusters: user-guide/resource-browser.md
global-configurations/authorization/sso-login/okta: user-guide/global-configurations/authorization/sso/okta.md
global-configurations/authorization/sso-login/okta: user-guide/global-configurations/authorization/sso/okta.md
usage/applications/creating-application/ci-pipeline/ci-build-pre-post-plugins: user-guide/creating-application/workflow/ci-build-pre-post-plugins.md
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@
.env
/cmd/external-app/devtron-ea
devtron
/vendor/github.com/argoproj/argo-cd/assets
8 changes: 8 additions & 0 deletions Wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ import (
"github.com/devtron-labs/devtron/cel"
"github.com/devtron-labs/devtron/client/argocdServer"
"github.com/devtron-labs/devtron/client/argocdServer/application"
"github.com/devtron-labs/devtron/client/argocdServer/certificate"
cluster2 "github.com/devtron-labs/devtron/client/argocdServer/cluster"
"github.com/devtron-labs/devtron/client/argocdServer/connection"
repocreds "github.com/devtron-labs/devtron/client/argocdServer/repocreds"
repository2 "github.com/devtron-labs/devtron/client/argocdServer/repository"
session2 "github.com/devtron-labs/devtron/client/argocdServer/session"
"github.com/devtron-labs/devtron/client/cron"
Expand Down Expand Up @@ -981,6 +983,9 @@ func InitializeApp() (*App, error) {
imageDigestPolicy.NewImageDigestPolicyServiceImpl,
wire.Bind(new(imageDigestPolicy.ImageDigestPolicyService), new(*imageDigestPolicy.ImageDigestPolicyServiceImpl)),

certificate.NewServiceClientImpl,
wire.Bind(new(certificate.Client), new(*certificate.ServiceClientImpl)),

appStoreRestHandler.AppStoreWireSet,

cel.NewCELServiceImpl,
Expand All @@ -991,6 +996,9 @@ func InitializeApp() (*App, error) {

common.NewDeploymentConfigServiceImpl,
wire.Bind(new(common.DeploymentConfigService), new(*common.DeploymentConfigServiceImpl)),

repocreds.NewServiceClientImpl,
wire.Bind(new(repocreds.ServiceClient), new(*repocreds.ServiceClientImpl)),
)
return &App{}, nil
}
35 changes: 22 additions & 13 deletions api/bean/gitOps/GitOpsConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,30 @@

package gitOps

import "time"
import (
"github.com/devtron-labs/devtron/api/bean"
"time"
)

type GitOpsConfigDto struct {
Id int `json:"id,omitempty"`
Provider string `json:"provider" validate:"oneof=GITLAB GITHUB AZURE_DEVOPS BITBUCKET_CLOUD"`
Username string `json:"username"`
Token string `json:"token"`
GitLabGroupId string `json:"gitLabGroupId"`
GitHubOrgId string `json:"gitHubOrgId"`
Host string `json:"host"`
Active bool `json:"active"`
AzureProjectName string `json:"azureProjectName"`
BitBucketWorkspaceId string `json:"bitBucketWorkspaceId"`
BitBucketProjectKey string `json:"bitBucketProjectKey"`
AllowCustomRepository bool `json:"allowCustomRepository"`
Id int `json:"id,omitempty"`
Provider string `json:"provider" validate:"oneof=GITLAB GITHUB AZURE_DEVOPS BITBUCKET_CLOUD"`
Username string `json:"username"`
Token string `json:"token"`
GitLabGroupId string `json:"gitLabGroupId"`
GitHubOrgId string `json:"gitHubOrgId"`
Host string `json:"host"`
Active bool `json:"active"`
AzureProjectName string `json:"azureProjectName"`
BitBucketWorkspaceId string `json:"bitBucketWorkspaceId"`
BitBucketProjectKey string `json:"bitBucketProjectKey"`
AllowCustomRepository bool `json:"allowCustomRepository"`
EnableTLSVerification bool `json:"enableTLSVerification"`
TLSConfig *bean.TLSConfig `json:"tlsConfig"`

IsCADataPresent bool `json:"isCADataPresent"`
IsTLSCertDataPresent bool `json:"isTLSCertDataPresent"`
IsTLSKeyDataPresent bool `json:"isTLSKeyDataPresent"`

// TODO refactoring: create different struct for internal fields
GitRepoName string `json:"-"`
Expand Down
7 changes: 7 additions & 0 deletions api/bean/tlsConfig.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package bean

type TLSConfig struct {
CaData string `json:"caData"`
TLSCertData string `json:"tlsCertData"`
TLSKeyData string `json:"tlsKeyData"`
}
76 changes: 76 additions & 0 deletions client/argocdServer/certificate/Certificate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package certificate

import (
"context"
"errors"
"github.com/argoproj/argo-cd/v2/pkg/apiclient/certificate"
"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
"github.com/devtron-labs/devtron/client/argocdServer/connection"
"github.com/devtron-labs/devtron/util/argo"
"go.uber.org/zap"
"google.golang.org/grpc"
"time"
)

type Client interface {
ListCertificates(ctx context.Context, query *certificate.RepositoryCertificateQuery, opts ...grpc.CallOption) (*v1alpha1.RepositoryCertificateList, error)
CreateCertificate(ctx context.Context, query *certificate.RepositoryCertificateCreateRequest) (*v1alpha1.RepositoryCertificateList, error)
DeleteCertificate(ctx context.Context, query *certificate.RepositoryCertificateQuery, opts ...grpc.CallOption) (*v1alpha1.RepositoryCertificateList, error)
}

type ServiceClientImpl struct {
logger *zap.SugaredLogger
argoCDConnectionManager connection.ArgoCDConnectionManager
argoUserService argo.ArgoUserService
}

func NewServiceClientImpl(
logger *zap.SugaredLogger,
argoCDConnectionManager connection.ArgoCDConnectionManager,
argoUserService argo.ArgoUserService) *ServiceClientImpl {
return &ServiceClientImpl{
logger: logger,
argoCDConnectionManager: argoCDConnectionManager,
argoUserService: argoUserService,
}
}

func (c *ServiceClientImpl) getService(ctx context.Context) (certificate.CertificateServiceClient, error) {
token, ok := ctx.Value("token").(string)
if !ok {
return nil, errors.New("Unauthorized")
}
conn := c.argoCDConnectionManager.GetConnection(token)
//defer conn.Close()
return certificate.NewCertificateServiceClient(conn), nil
}

func (c *ServiceClientImpl) ListCertificates(ctx context.Context, query *certificate.RepositoryCertificateQuery, opts ...grpc.CallOption) (*v1alpha1.RepositoryCertificateList, error) {
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel()
client, err := c.getService(ctx)
if err != nil {
return nil, err
}
return client.ListCertificates(ctx, query)
}

func (c *ServiceClientImpl) CreateCertificate(ctx context.Context, query *certificate.RepositoryCertificateCreateRequest) (*v1alpha1.RepositoryCertificateList, error) {
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel()
client, err := c.getService(ctx)
if err != nil {
return nil, err
}
return client.CreateCertificate(ctx, query)
}

func (c *ServiceClientImpl) DeleteCertificate(ctx context.Context, query *certificate.RepositoryCertificateQuery, opts ...grpc.CallOption) (*v1alpha1.RepositoryCertificateList, error) {
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel()
client, err := c.getService(ctx)
if err != nil {
return nil, err
}
return client.DeleteCertificate(ctx, query, opts...)
}
63 changes: 63 additions & 0 deletions client/argocdServer/repocreds/repocreds.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright (c) 2020-2024. Devtron Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package repository

import (
"context"
"errors"
repocreds "github.com/argoproj/argo-cd/v2/pkg/apiclient/repocreds"
"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
argoApplication "github.com/devtron-labs/devtron/client/argocdServer/bean"
"github.com/devtron-labs/devtron/client/argocdServer/connection"
"go.uber.org/zap"
)

type ServiceClient interface {
CreateRepoCreds(ctx context.Context, query *repocreds.RepoCredsCreateRequest) (*v1alpha1.RepoCreds, error)
}

type ServiceClientImpl struct {
logger *zap.SugaredLogger
argoCDConnectionManager connection.ArgoCDConnectionManager
}

func NewServiceClientImpl(logger *zap.SugaredLogger, argoCDConnectionManager connection.ArgoCDConnectionManager) *ServiceClientImpl {
return &ServiceClientImpl{
logger: logger,
argoCDConnectionManager: argoCDConnectionManager,
}
}

func (r ServiceClientImpl) getService(ctx context.Context) (repocreds.RepoCredsServiceClient, error) {
token, ok := ctx.Value("token").(string)
if !ok {
return nil, errors.New("Unauthorized")
}
conn := r.argoCDConnectionManager.GetConnection(token)
//defer conn.Close()
return repocreds.NewRepoCredsServiceClient(conn), nil
}

func (r ServiceClientImpl) CreateRepoCreds(ctx context.Context, query *repocreds.RepoCredsCreateRequest) (*v1alpha1.RepoCreds, error) {
ctx, cancel := context.WithTimeout(ctx, argoApplication.TimeoutSlow)
defer cancel()
client, err := r.getService(ctx)
if err != nil {
return nil, err
}
return client.CreateRepositoryCredentials(ctx, query)
}
2 changes: 1 addition & 1 deletion client/argocdServer/repository/Repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type ServiceClient interface {
GetAppDetails(ctx context.Context, query *repository2.RepoAppDetailsQuery) (*apiclient.RepoAppDetailsResponse, error)
// Create creates a repo
Create(ctx context.Context, query *repository2.RepoCreateRequest) (*v1alpha1.Repository, error)
// Update updates a repo
// Create creates a repo
Update(ctx context.Context, query *repository2.RepoUpdateRequest) (*v1alpha1.Repository, error)
// Delete deletes a repo
Delete(ctx context.Context, query *repository2.RepoQuery) (*repository2.RepoResponse, error)
Expand Down
22 changes: 13 additions & 9 deletions client/gitSensor/GitSensorGrpcClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,19 @@ func (client *GrpcApiClientImpl) SaveGitProvider(ctx context.Context, provider *
}
// map req
req := &pb.GitProvider{
Id: int64(provider.Id),
Name: provider.Name,
Url: provider.Url,
UserName: provider.UserName,
Password: provider.Password,
AccessToken: provider.AccessToken,
SshPrivateKey: provider.SshPrivateKey,
AuthMode: string(provider.AuthMode),
Active: provider.Active,
Id: int64(provider.Id),
Name: provider.Name,
Url: provider.Url,
UserName: provider.UserName,
Password: provider.Password,
SshPrivateKey: provider.SshPrivateKey,
AccessToken: provider.AccessToken,
AuthMode: string(provider.AuthMode),
Active: provider.Active,
TlsCert: provider.TlsCert,
TlsKey: provider.TlsKey,
CaCert: provider.CaCert,
EnableTLSVerification: provider.EnableTlsVerification,
}

// fetch
Expand Down
22 changes: 13 additions & 9 deletions client/gitSensor/GitSensorRestClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,19 @@ type GitMaterial struct {
CloningMode string
}
type GitProvider struct {
Id int
Name string
Url string
UserName string
Password string
SshPrivateKey string
AccessToken string
Active bool
AuthMode repository.AuthMode
Id int
Name string
Url string
UserName string
Password string
SshPrivateKey string
AccessToken string
Active bool
AuthMode repository.AuthMode
EnableTlsVerification bool
CaCert string
TlsCert string
TlsKey string
}

type GitCommit struct {
Expand Down
Loading

0 comments on commit dacfd8b

Please sign in to comment.