Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cla-backend-go/auth/auth0.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type Validator struct {
}

// NewAuthValidator creates a new auth0 validator based on the specified parameters
func NewAuthValidator(domain, clientID, usernameClaim, algorithm string) (Validator, error) { // nolint
func NewAuthValidator(domain, clientID, usernameClaim, nameClaim, emailClaim, algorithm string) (Validator, error) { // nolint
if domain == "" {
return Validator{}, errors.New("missing Domain")
}
Expand All @@ -43,8 +43,8 @@ func NewAuthValidator(domain, clientID, usernameClaim, algorithm string) (Valida
usernameClaim: usernameClaim,
algorithm: algorithm,
wellKnownURL: "https://" + path.Join(domain, ".well-known/jwks.json"),
nameClaim: "name",
emailClaim: "email",
nameClaim: nameClaim,
emailClaim: emailClaim,
}

return validator, nil
Expand Down
19 changes: 12 additions & 7 deletions cla-backend-go/cmd/response_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package cmd

import (
"sync"
"time"

"github.com/linuxfoundation/easycla/cla-backend-go/utils"
Expand All @@ -18,32 +19,36 @@ type responseMetrics struct {
expire time.Time
}

var reqMap = make(map[string]*responseMetrics, 5)
var reqMap sync.Map

// requestStart holds the request ID, method and timing information in a small structure
func requestStart(reqID, method string) {
now, _ := utils.CurrentTime()
reqMap[reqID] = &responseMetrics{
rm := &responseMetrics{
reqID: reqID,
method: method,
start: now,
elapsed: 0,
expire: now.Add(time.Minute * 5),
}
reqMap.Store(reqID, rm)
}

// getRequestMetrics returns the response metrics based on the request id value
func getRequestMetrics(reqID string) *responseMetrics {
if x, found := reqMap[reqID]; found {
if val, found := reqMap.Load(reqID); found {
rm, ok := val.(*responseMetrics)
if !ok {
return nil
}
now, _ := utils.CurrentTime()
x.elapsed = now.Sub(x.start)
return x
rm.elapsed = now.Sub(rm.start)
return rm
}

return nil
}

// clearRequestMetrics removes the request from the map
func clearRequestMetrics(reqID string) {
delete(reqMap, reqID)
reqMap.Delete(reqID)
}
17 changes: 15 additions & 2 deletions cla-backend-go/cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,24 @@ func server(localMode bool) http.Handler {
}

// LG: to test with manual tokens
// configFile.Auth0.UsernameClaim = "http://lfx.dev/claims/username"
customClaimUsername := os.Getenv("AUTH0_USERNAME_CLAIM_CLI")
if customClaimUsername != "" {
configFile.Auth0.UsernameClaim = customClaimUsername
}
nameClaimName := os.Getenv("AUTH0_NAME_CLAIM_CLI")
if nameClaimName == "" {
nameClaimName = "name"
}
emailClaimName := os.Getenv("AUTH0_EMAIL_CLAIM_CLI")
if emailClaimName == "" {
emailClaimName = "email"
}
authValidator, err := auth.NewAuthValidator(
configFile.Auth0.Domain,
configFile.Auth0.ClientID,
configFile.Auth0.UsernameClaim,
nameClaimName,
emailClaimName,
configFile.Auth0.Algorithm)
if err != nil {
logrus.Panic(err)
Expand Down Expand Up @@ -336,7 +349,7 @@ func server(localMode bool) http.Handler {
// Setup our API handlers
users.Configure(api, usersService, eventsService)
project.Configure(api, v1ProjectService, eventsService, gerritService, v1RepositoriesService, v1SignaturesService)
v2Project.Configure(v2API, v1ProjectService, v2ProjectService, eventsService)
v2Project.Configure(v2API, v1ProjectService, v2ProjectService, eventsService, v1ProjectClaGroupService, v2RepositoriesService, gerritService)
health.Configure(api, healthService)
v2Health.Configure(v2API, healthService)
template.Configure(api, templateService, eventsService)
Expand Down
15 changes: 15 additions & 0 deletions cla-backend-go/project/mocks/mock_repo.go

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

15 changes: 15 additions & 0 deletions cla-backend-go/project/mocks/mock_service.go

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

26 changes: 22 additions & 4 deletions cla-backend-go/project/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const (
type ProjectRepository interface { //nolint
CreateCLAGroup(ctx context.Context, claGroupModel *models.ClaGroup) (*models.ClaGroup, error)
GetCLAGroupByID(ctx context.Context, claGroupID string, loadRepoDetails bool) (*models.ClaGroup, error)
GetCLAGroupByIDCompat(ctx context.Context, claGroupID string, loadRepoDetails bool) (*models.ClaGroup, error)
GetCLAGroupsByExternalID(ctx context.Context, params *project.GetProjectsByExternalIDParams, loadRepoDetails bool) (*models.ClaGroups, error)
GetCLAGroupByName(ctx context.Context, claGroupName string) (*models.ClaGroup, error)
GetExternalCLAGroup(ctx context.Context, claGroupExternalID string) (*models.ClaGroup, error)
Expand Down Expand Up @@ -149,7 +150,7 @@ func (repo *repo) CreateCLAGroup(ctx context.Context, claGroupModel *models.ClaG
return claGroupModel, nil
}

func (repo *repo) getCLAGroupByID(ctx context.Context, claGroupID string, loadCLAGroupDetails bool) (*models.ClaGroup, error) {
func (repo *repo) getCLAGroupByID(ctx context.Context, claGroupID string, loadCLAGroupDetails bool, claEnabledDefaultIsTrue bool) (*models.ClaGroup, error) {
f := logrus.Fields{
"functionName": "project.repository.getCLAGroupByID",
utils.XREQUESTID: ctx.Value(utils.XREQUESTID),
Expand Down Expand Up @@ -188,19 +189,36 @@ func (repo *repo) getCLAGroupByID(ctx context.Context, claGroupID string, loadCL
return nil, &utils.CLAGroupNotFound{CLAGroupID: claGroupID}
}
var dbModel models2.DBProjectModel
err = dynamodbattribute.UnmarshalMap(results.Items[0], &dbModel)
rawItem := results.Items[0]
err = dynamodbattribute.UnmarshalMap(rawItem, &dbModel)
if err != nil {
log.WithFields(f).Warnf("error unmarshalling db cla group model, error: %+v", err)
return nil, err
}
if claEnabledDefaultIsTrue {
// If missing, assume true like Pynamo default=True
if _, ok := rawItem["project_icla_enabled"]; !ok {
dbModel.ProjectIclaEnabled = true
}
if _, ok := rawItem["project_ccla_enabled"]; !ok {
dbModel.ProjectCclaEnabled = true
}
}

// Convert the database model to an API response model
return repo.buildCLAGroupModel(ctx, dbModel, loadCLAGroupDetails), nil
}

// GetCLAGroupByID returns the cla group model associated for the specified claGroupID
func (repo *repo) GetCLAGroupByID(ctx context.Context, claGroupID string, loadRepoDetails bool) (*models.ClaGroup, error) {
return repo.getCLAGroupByID(ctx, claGroupID, loadRepoDetails)
return repo.getCLAGroupByID(ctx, claGroupID, loadRepoDetails, false)
}

// GetCLAGroupByIDCompat returns the cla group model associated for the specified claGroupID
func (repo *repo) GetCLAGroupByIDCompat(ctx context.Context, claGroupID string, loadRepoDetails bool) (*models.ClaGroup, error) {
// Uses compatible mode (with python v2): claEnabledDefaultIsTrue - means if project_ccla_enabled or project_icla_enabled
// aren't set on dynamoDB item - they will default to true as in Py V2 API
return repo.getCLAGroupByID(ctx, claGroupID, loadRepoDetails, true)
}

// GetCLAGroupsByExternalID queries the database and returns a list of the cla groups
Expand Down Expand Up @@ -383,7 +401,7 @@ func (repo *repo) GetClaGroupByProjectSFID(ctx context.Context, projectSFID stri

log.WithFields(f).Debugf("found CLA Group ID: %s for project SFID: %s", claGroupProject.ClaGroupID, projectSFID)

return repo.getCLAGroupByID(ctx, claGroupProject.ClaGroupID, loadRepoDetails)
return repo.getCLAGroupByID(ctx, claGroupProject.ClaGroupID, loadRepoDetails, false)
}

// GetCLAGroupByName returns the project model associated for the specified project name
Expand Down
21 changes: 20 additions & 1 deletion cla-backend-go/project/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type Service interface {
CreateCLAGroup(ctx context.Context, project *models.ClaGroup) (*models.ClaGroup, error)
GetCLAGroups(ctx context.Context, params *project.GetProjectsParams) (*models.ClaGroups, error)
GetCLAGroupByID(ctx context.Context, claGroupID string) (*models.ClaGroup, error)
GetCLAGroupByIDCompat(ctx context.Context, claGroupID string) (*models.ClaGroup, error)
GetCLAGroupsByExternalSFID(ctx context.Context, projectSFID string) (*models.ClaGroups, error)
GetCLAGroupsByExternalID(ctx context.Context, params *project.GetProjectsByExternalIDParams) (*models.ClaGroups, error)
GetCLAGroupByName(ctx context.Context, projectName string) (*models.ClaGroup, error)
Expand Down Expand Up @@ -75,6 +76,16 @@ func (s ProjectService) GetCLAGroups(ctx context.Context, params *project.GetPro

// GetCLAGroupByID service method
func (s ProjectService) GetCLAGroupByID(ctx context.Context, claGroupID string) (*models.ClaGroup, error) {
return s.getCLAGroupByID(ctx, claGroupID, false)
}

// GetCLAGroupByIDCompat service method
func (s ProjectService) GetCLAGroupByIDCompat(ctx context.Context, claGroupID string) (*models.ClaGroup, error) {
return s.getCLAGroupByID(ctx, claGroupID, true)
}

// getCLAGroupByID service method
func (s ProjectService) getCLAGroupByID(ctx context.Context, claGroupID string, claEnabledDefaultIsTrue bool) (*models.ClaGroup, error) {
f := logrus.Fields{
"functionName": "GetCLAGroupByID",
utils.XREQUESTID: ctx.Value(utils.XREQUESTID),
Expand All @@ -83,7 +94,15 @@ func (s ProjectService) GetCLAGroupByID(ctx context.Context, claGroupID string)
}

log.WithFields(f).Debug("locating CLA Group by ID...")
project, err := s.repo.GetCLAGroupByID(ctx, claGroupID, repository.LoadRepoDetails)
var (
project *models.ClaGroup
err error
)
if claEnabledDefaultIsTrue {
project, err = s.repo.GetCLAGroupByIDCompat(ctx, claGroupID, repository.LoadRepoDetails)
} else {
project, err = s.repo.GetCLAGroupByID(ctx, claGroupID, repository.LoadRepoDetails)
}
if err != nil {
return nil, err
}
Expand Down
35 changes: 35 additions & 0 deletions cla-backend-go/swagger/cla.v2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,38 @@ paths:
tags:
- project

/project-compat/{projectID}:
parameters:
- $ref: "#/parameters/x-request-id"
- name: projectID
in: path
type: string
required: true
pattern: '^[a-fA-F0-9]{8}-?[a-fA-F0-9]{4}-?4[a-fA-F0-9]{3}-?[89ab][a-fA-F0-9]{3}-?[a-fA-F0-9]{12}$' # uuidv4
get:
summary: Get project by ID (returns data in the same format as Py V2 API)
security: [ ]
operationId: getProjectCompat
responses:
'200':
description: 'Success'
headers:
x-request-id:
type: string
description: The unique request ID value - assigned/set by the API Gateway based on the session
schema:
$ref: '#/definitions/project-compat'
'400':
$ref: '#/responses/invalid-request'
'401':
$ref: '#/responses/unauthorized'
'403':
$ref: '#/responses/forbidden'
'404':
$ref: '#/responses/not-found'
tags:
- project

/events/recent:
get:
summary: List recent events - requires Admin-level access
Expand Down Expand Up @@ -4956,6 +4988,9 @@ definitions:
sf-project-summary:
$ref: './common/sf-project-summary.yaml'

project-compat:
$ref: './common/project-compat.yaml'

# ---------------------------------------------------------------------------
# CLA Template Definitions
# ---------------------------------------------------------------------------
Expand Down
Loading
Loading