Skip to content

Commit

Permalink
Merge pull request #4151 from nickmango/feature/private-key-docsign
Browse files Browse the repository at this point in the history
fixed private key lambda issue
  • Loading branch information
nickmango authored Oct 12, 2023
2 parents e06f3ef + c3a7ce4 commit 0396413
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 17 deletions.
2 changes: 1 addition & 1 deletion cla-backend-go/cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ func server(localMode bool) http.Handler {
v2GithubActivityService := v2GithubActivity.NewService(gitV1Repository, githubOrganizationsRepo, eventsService, autoEnableService, emailService)

v2ClaGroupService := cla_groups.NewService(v1ProjectService, templateService, v1ProjectClaGroupRepo, v1ClaManagerService, v1SignaturesService, metricsRepo, gerritService, v1RepositoriesService, eventsService)
v2SignService := sign.NewService(configFile.ClaV1ApiURL, v1CompanyRepo, v1CLAGroupRepo, v1ProjectClaGroupRepo, v1CompanyService, v2ClaGroupService)
v2SignService := sign.NewService(configFile.ClaV1ApiURL, v1CompanyRepo, v1CLAGroupRepo, v1ProjectClaGroupRepo, v1CompanyService, v2ClaGroupService, configFile.DocuSignPrivateKey)

sessionStore, err := dynastore.New(dynastore.Path("/"), dynastore.HTTPOnly(), dynastore.TableName(configFile.SessionStoreTableName), dynastore.DynamoDB(dynamodb.New(awsSession)))
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions cla-backend-go/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ type Config struct {

// MetricsReport has the transport config to send the metrics data
MetricsReport MetricsReport `json:"metrics_report"`

// DocuSignPrivateKey is the private key for the DocuSign API
DocuSignPrivateKey string `json:"docuSignPrivateKey"`
}

// Auth0 model
Expand Down
3 changes: 3 additions & 0 deletions cla-backend-go/config/ssm.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func loadSSMConfig(awsSession *session.Session, stage string) Config { //nolint
fmt.Sprintf("cla-api-v4-base-%s", stage),
fmt.Sprintf("cla-landing-page-%s", stage),
fmt.Sprintf("cla-logo-url-%s", stage),
fmt.Sprintf("cla-docusign-private-key-%s", stage),
}

// For each key to lookup
Expand Down Expand Up @@ -263,6 +264,8 @@ func loadSSMConfig(awsSession *session.Session, stage string) Config { //nolint
} else {
config.SignatureQueryDefault = resp.value
}
case fmt.Sprintf("cla-docusign-private-key-%s", stage):
config.DocuSignPrivateKey = resp.value
}
}

Expand Down
1 change: 0 additions & 1 deletion cla-backend-go/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ provider:
DOCUSIGN_PASSWORD: ${file(./env.json):docusign-password, ssm:/cla-docusign-password-${opt:stage}}
DOCUSIGN_INTEGRATOR_KEY: ${file(./env.json):docusign-integrator-key, ssm:/cla-docusign-integrator-key-${opt:stage}}
DOCUSIGN_AUTH_SERVER: ${file(./env.json):docusign-auth-server, ssm:/cla-docusign-auth-server-${opt:stage}}
DOCUSIGN_PRIVATE_KEY: ${file(./env.json):docusign-auth-server, ssm:/cla-docusign-private-key-${opt:stage}}
DOCUSIGN_USER_ID: ${file(./env.json):docusign-auth-server, ssm:/cla-docusign-user-id-${opt:stage}}
CLA_API_BASE: ${file(./env.json):cla-api-base, ssm:/cla-api-base-${opt:stage}}
CLA_CONTRIBUTOR_BASE: ${file(./env.json):cla-contributor-base, ssm:/cla-contributor-base-${opt:stage}}
Expand Down
2 changes: 1 addition & 1 deletion cla-backend-go/v2/sign/docusign.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (s *service) getAccessToken(ctx context.Context) (string, error) {
utils.XREQUESTID: ctx.Value(utils.XREQUESTID),
}

jwtAssertion, err := jwtToken()
jwtAssertion, err := jwtToken(s.docsignPrivateKey)
if err != nil {
log.WithFields(f).WithError(err).Warnf("problem generating the JWT token")
return "", err
Expand Down
15 changes: 2 additions & 13 deletions cla-backend-go/v2/sign/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/sirupsen/logrus"
)

func jwtToken() (string, error) {
func jwtToken(docusignPrivateKey string) (string, error) {
f := logrus.Fields{
"functionName": "v2.sign.jwtToken",
}
Expand All @@ -29,21 +29,10 @@ func jwtToken() (string, error) {

token := jwt.NewWithClaims(jwt.SigningMethodRS256, claims)

// DEBUG - remove
// log.WithFields(f).Debugf("integration key (iss) : %s", utils.GetProperty("DOCUSIGN_INTEGRATION_KEY"))
// log.WithFields(f).Debugf("integration user (sub) : %s", utils.GetProperty("DOCUSIGN_INTEGRATION_USER_ID"))
// log.WithFields(f).Debugf("integration host : %s", getDocuSignAccountHost())

token.Header["alg"] = "RS256"
token.Header["typ"] = "JWT"

//publicKey, publicKeyErr := jwt.ParseRSAPublicKeyFromPEM([]byte(utils.GetProperty("DOCUSIGN_RSA_PUBLIC_KEY")))
//if publicKeyErr != nil {
// log.WithFields(f).WithError(publicKeyErr).Warnf("problem decoding docusign public key")
// return "", publicKeyErr
//}
privateKey, privateKeyErr := jwt.ParseRSAPrivateKeyFromPEM([]byte(utils.GetProperty("DOCUSIGN_RSA_PRIVATE_KEY")))
// privateKey, privateKeyErr := jwt.ParseRSAPrivateKeyFromPEM([]byte(docusignPrivateKey))
privateKey, privateKeyErr := jwt.ParseRSAPrivateKeyFromPEM([]byte(docusignPrivateKey))
if privateKeyErr != nil {
log.WithFields(f).WithError(privateKeyErr).Warnf("problem decoding docusign private key")
return "", privateKeyErr
Expand Down
4 changes: 3 additions & 1 deletion cla-backend-go/v2/sign/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,19 @@ type service struct {
projectClaGroupsRepo projects_cla_groups.Repository
companyService company.IService
claGroupService cla_groups.Service
docsignPrivateKey string
}

// NewService returns an instance of v2 project service
func NewService(apiURL string, compRepo company.IRepository, projectRepo ProjectRepo, pcgRepo projects_cla_groups.Repository, compService company.IService, claGroupService cla_groups.Service) Service {
func NewService(apiURL string, compRepo company.IRepository, projectRepo ProjectRepo, pcgRepo projects_cla_groups.Repository, compService company.IService, claGroupService cla_groups.Service, docsignPrivateKey string) Service {
return &service{
ClaV1ApiURL: apiURL,
companyRepo: compRepo,
projectRepo: projectRepo,
projectClaGroupsRepo: pcgRepo,
companyService: compService,
claGroupService: claGroupService,
docsignPrivateKey: docsignPrivateKey,
}
}

Expand Down

0 comments on commit 0396413

Please sign in to comment.