Skip to content

Commit

Permalink
fix: [CDS-38863]: Use masking list for Update API call (argoproj#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
shubham-banthia authored Jun 15, 2022
1 parent 8229165 commit 2d1b490
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 33 deletions.
134 changes: 101 additions & 33 deletions pkg/apiclient/repocreds/repocreds.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions pkg/apiclient/repocreds/repocreds.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions server/repocreds/repocreds.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package repocreds

import (
"github.com/argoproj/argo-cd/v2/util/grpc"
protov1 "github.com/golang/protobuf/proto"
"github.com/mennanov/fmutils"
"reflect"

"github.com/argoproj/argo-cd/v2/util/argo"
Expand Down Expand Up @@ -117,6 +120,17 @@ func (s *Server) UpdateRepositoryCredentials(ctx context.Context, q *repocredspk
if err := s.enf.EnforceErr(ctx.Value("claims"), rbacpolicy.ResourceRepositories, rbacpolicy.ActionUpdate, q.Creds.URL); err != nil {
return nil, err
}

if q.UpdateMask != nil && len(q.UpdateMask.Paths) != 0 {
existing, err := s.db.GetRepositoryCredentials(ctx, q.Creds.URL)
if err != nil {
return nil, err
}

grpc.Mask(protov1.MessageV2(existing), protov1.MessageV2(q.Creds), fmutils.NestedMaskFromPaths(q.UpdateMask.Paths))
q.Creds = existing
}

_, err := s.db.UpdateRepositoryCredentials(ctx, q.Creds)
return q.Creds, err
}
Expand Down
2 changes: 2 additions & 0 deletions server/repocreds/repocreds.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package repocreds;

import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "google/protobuf/field_mask.proto";
import "k8s.io/api/core/v1/generated.proto";
import "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1/generated.proto";

Expand Down Expand Up @@ -35,6 +36,7 @@ message RepoCredsCreateRequest {
// RepoCredsUpdateRequest is a request for updating existing repository credentials config
message RepoCredsUpdateRequest {
github.com.argoproj.argo_cd.v2.pkg.apis.application.v1alpha1.RepoCreds creds = 1;
google.protobuf.FieldMask updateMask = 3001;
}

// RepoCredsService implements CRUD actions for managing repository credentials config
Expand Down

0 comments on commit 2d1b490

Please sign in to comment.