Skip to content

Commit 1f2f678

Browse files
WIP
Signed-off-by: Lukasz Gryglicki <[email protected]>
1 parent 861d430 commit 1f2f678

File tree

6 files changed

+107
-3
lines changed

6 files changed

+107
-3
lines changed

cla-backend-go/swagger/cla.v2.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2485,7 +2485,7 @@ paths:
24852485
'404':
24862486
$ref: '#/responses/not-found'
24872487
tags:
2488-
- signatures
2488+
- sign
24892489

24902490
/signatures/project/{projectSFID}/company/{companyID}/employee:
24912491
get:

cla-backend-go/swagger/common/user-active-signature.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,16 @@ properties:
1717
repository_id:
1818
type: string
1919
description: The unique ID of the associated repository
20-
example: repo-abc123
20+
example: '168926425'
2121
pull_request_id:
2222
type: string
2323
description: The pull request ID related to the signature
2424
example: '456'
25+
merge_request_id:
26+
type: string
27+
description: The merge request ID related to the signature
28+
example: '456'
29+
x-nullable: true
2530
return_url:
2631
type: string
2732
format: uri

cla-backend-go/v2/sign/handlers.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,26 @@ func Configure(api *operations.EasyclaAPI, service Service, userService users.Se
248248
return sign.NewCclaCallbackOK()
249249
})
250250

251+
api.SignGetUserActiveSignatureHandler = sign.GetUserActiveSignatureHandlerFunc(
252+
func(params sign.GetUserActiveSignatureParams) middleware.Responder {
253+
reqId := utils.GetRequestID(params.XREQUESTID)
254+
ctx := context.WithValue(params.HTTPRequest.Context(), utils.XREQUESTIDKey, reqId)
255+
f := logrus.Fields{
256+
"functionName": "v2.sign.handlers.SignGetUserActiveSignatureHandler",
257+
utils.XREQUESTID: ctx.Value(utils.XREQUESTID),
258+
"userID": params.UserID,
259+
}
260+
var resp *models.UserActiveSignature
261+
var err error
262+
263+
log.WithFields(f).Debug("getting user active signature")
264+
resp, err = service.GetUserActiveSignature(ctx, params.UserID)
265+
if err != nil {
266+
return sign.NewGetUserActiveSignatureBadRequest().WithPayload(errorResponse(reqId, err))
267+
}
268+
return sign.NewGetUserActiveSignatureOK().WithPayload(resp)
269+
})
270+
251271
}
252272

253273
type codedResponse interface {

cla-backend-go/v2/sign/service.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ type Service interface {
9090
SignedIndividualCallbackGitlab(ctx context.Context, payload []byte, userID, organizationID, repositoryID, mergeRequestID string) error
9191
SignedIndividualCallbackGerrit(ctx context.Context, payload []byte, userID string) error
9292
SignedCorporateCallback(ctx context.Context, payload []byte, companyID, projectID string) error
93+
GetUserActiveSignature(ctx context.Context, userID string) (*models.UserActiveSignature, error)
9394
}
9495

9596
// service
@@ -2769,3 +2770,52 @@ func claSignatoryEmailContent(params ClaSignatoryEmailParams) (string, string) {
27692770

27702771
return emailSubject, emailBody
27712772
}
2773+
2774+
func (s *service) GetUserActiveSignature(ctx context.Context, userID string) (*models.UserActiveSignature, error) {
2775+
f := logrus.Fields{
2776+
"functionName": "sign.GetUserActiveSignature",
2777+
utils.XREQUESTID: ctx.Value(utils.XREQUESTID),
2778+
"userID": userID,
2779+
}
2780+
activeSignatureMetadata, err := s.storeRepository.GetActiveSignatureMetaData(ctx, userID)
2781+
if err != nil {
2782+
log.WithFields(f).WithError(err).Warnf("unable to get active signature meta data for user: %s", userID)
2783+
return nil, err
2784+
}
2785+
2786+
log.WithFields(f).Debugf("active signature metadata: %+v", activeSignatureMetadata)
2787+
isGitlab := false
2788+
var mergeRequestId *string
2789+
if mrId, ok := activeSignatureMetadata["merge_request_id"].(string); ok {
2790+
isGitlab = true
2791+
mergeRequestId = &mrId
2792+
}
2793+
log.WithFields(f).Debugf("generating signature callback url gitlab=%v...", isGitlab)
2794+
2795+
var callBackURL string
2796+
if isGitlab {
2797+
callBackURL, err = s.getIndividualSignatureCallbackURLGitlab(ctx, userID, activeSignatureMetadata)
2798+
if err != nil {
2799+
log.WithFields(f).WithError(err).Warnf("unable to get gitlab signature callback url for user: %s", userID)
2800+
return nil, err
2801+
}
2802+
} else {
2803+
callBackURL, err = s.getIndividualSignatureCallbackURL(ctx, userID, activeSignatureMetadata)
2804+
if err != nil {
2805+
log.WithFields(f).WithError(err).Warnf("unable to get github signature callback url for user: %s", userID)
2806+
return nil, err
2807+
}
2808+
}
2809+
log.WithFields(f).Debugf("signature callback url: %s", callBackURL)
2810+
projectId, _ := activeSignatureMetadata["project_id"].(string)
2811+
pullRequestId, _ := activeSignatureMetadata["pull_request_id"].(string)
2812+
repositoryId, _ := activeSignatureMetadata["repository_id"].(string)
2813+
return &models.UserActiveSignature{
2814+
MergeRequestID: mergeRequestId,
2815+
ProjectID: projectId,
2816+
PullRequestID: pullRequestId,
2817+
RepositoryID: repositoryId,
2818+
ReturnURL: strfmt.URI(callBackURL),
2819+
UserID: userID,
2820+
}, nil
2821+
}

utils/active_signature_go.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
# user_id='9dcf5bbc-2492-11ed-97c7-3e2a23ea20b5'
3+
# select key, data:expire from fivetran_ingest.dynamodb_product_us_east1_dev.cla_dev_store where key like 'active_signature:%' order by data:expire desc limit 1;
4+
# select key, data:expire from fivetran_ingest.dynamodb_product_us_east_1.cla_prod_store where key like 'active_signature:%' order by data:expire desc limit 1;
5+
# API_URL=https://api-gw.dev.platform.linuxfoundation.org/cla-service DEBUG=1 ./utils/active_signature_go.sh '4b344ac4-f8d9-11ed-ac9b-b29c4ace74e9'
6+
# API_URL=https://api-gw.dev.platform.linuxfoundation.org/cla-service DEBUG=1 ./utils/active_signature_go.sh '4b344ac4-f8d9-11ed-ac9b-b29c4ace74e9'
7+
# API_URL=http://localhost:5001 DEBUG='' ./utils/active_signature_go.sh '564e571e-12d7-4857-abd4-898939accdd7'
8+
# ./utils/add_store_active_signature.sh b817eb57-045a-4fe0-8473-fbb416a01d70 d8cead54-92b7-48c5-a2c8-b1e295e8f7f1
9+
# DEBUG='' ./utils/active_signature_go.sh b817eb57-045a-4fe0-8473-fbb416a01d70 | jq '.'
10+
11+
if [ -z "$1" ]
12+
then
13+
echo "$0: you need to specify user_id as a 1st parameter"
14+
exit 1
15+
fi
16+
export user_id="$1"
17+
18+
if [ -z "$API_URL" ]
19+
then
20+
export API_URL="http://localhost:5001"
21+
fi
22+
23+
if [ ! -z "$DEBUG" ]
24+
then
25+
echo "curl -s -XGET -H 'Content-Type: application/json' \"${API_URL}/v4/user/${user_id}/active-signature\""
26+
curl -s -XGET -H "Content-Type: application/json" "${API_URL}/v4/user/${user_id}/active-signature"
27+
else
28+
curl -s -XGET -H "Content-Type: application/json" "${API_URL}/v4/user/${user_id}/active-signature" | jq -r '.'
29+
fi

utils/add_store_active_signature.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ aws --profile "lfproduct-${STAGE}" dynamodb put-item --table-name "cla-${STAGE}-
2020
"S": "active_signature:'"${1}"'"
2121
},
2222
"value": {
23-
"S": "{\"user_id\": \"'"${1}"'\", \"project_id\": \"'"${2}"'\", \"repository_id\": 466156917, \"pull_request_id\": 3}"
23+
"S": "{\"user_id\": \"'"${1}"'\", \"project_id\": \"'"${2}"'\", \"repository_id\": \"466156917\", \"pull_request_id\": \"3\"}"
2424
},
2525
"expire": {
2626
"N": "'"${EXPIRE_TS}"'"

0 commit comments

Comments
 (0)