Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/revert dockerization #4126

Merged
2 changes: 1 addition & 1 deletion cla-backend-go/signatures/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const SignatureGitHubOrgApprovalListColumn = "github_org_whitelist" // TODO: ren
const SignatureGitlabUsernameApprovalListColumn = "gitlab_username_approval_list"

// SignatureGitlabOrgApprovalListColumn is the name of the signature column for gitlab organization approval lists
const SignatureGitlabOrgApprovalListColumn = "gitlab_org_approval_list"
const SignatureGitlabOrgApprovalListColumn = "gitlab_org_approval_list" // nolint G101: Potential hardcoded credentials (gosec)

// SignatureUserGitHubUsername is the name of the signature column for user gitlab username
const SignatureUserGitHubUsername = "user_github_username"
Expand Down
4 changes: 2 additions & 2 deletions cla-backend-go/signatures/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ func (repo repository) GetIndividualSignature(ctx context.Context, claGroupID, u
log.WithFields(f).Warnf("found multiple matching ICLA signatures - found %d total", len(sigs))
}

return sigs[0], nil
return sigs[0], nil // nolint G602: Potentially accessing slice out of bounds (gosec)
}

// GetCorporateSignature returns the signature record for the specified CLA Group and Company ID
Expand Down Expand Up @@ -665,7 +665,7 @@ func (repo repository) GetCorporateSignature(ctx context.Context, claGroupID, co
log.WithFields(f).Warnf("found multiple matching ICLA signatures - found %d total", len(sigs))
}

return sigs[0], nil
return sigs[0], nil // nolint G602: Potentially accessing slice out of bounds (gosec)
}

// GetActivePullRequestMetadata returns the pull request metadata for the given user ID
Expand Down
4 changes: 2 additions & 2 deletions cla-backend-go/v2/metrics/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ const (
MetricTypeCompany = "company"
MetricTypeProject = "project"
MetricTypeCompanyProject = "company_project"
MetricTypeClaManagerDistribution = "cla_manager_distribution"
MetricTypeClaManagerDistribution = "cla_manager_distribution" // nolint G101: Potential hardcoded credentials (gosec)

IDTotalCount = "total_count"
IDClaManagerDistribution = "cla_manager_distribution"
IDClaManagerDistribution = "cla_manager_distribution" // nolint G101: Potential hardcoded credentials (gosec)
)

func newMetrics() *Metrics {
Expand Down
77 changes: 37 additions & 40 deletions cla-backend/cla/models/docusign_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,26 @@
from typing import Any, Dict, List, Optional
from urllib.parse import urlparse

import cla
import pydocusign # type: ignore
import requests
from attr import dataclass
from pydocusign.exceptions import DocuSignException # type: ignore

import cla
from cla.controllers.lf_group import LFGroup
from cla.models import DoesNotExist, signing_service_interface
from cla.docusign_auth import request_access_token
from cla.models.dynamo_models import (Company, Document, Event, Gerrit,
Project, Signature, User)
from cla.models.event_types import EventType
from cla.models.s3_storage import S3Storage
from cla.user_service import UserService
from cla.utils import (append_email_help_sign_off_content, get_corporate_url,
get_email_help_content, get_project_cla_group_instance)
from pydocusign.exceptions import DocuSignException # type: ignore

api_base_url = os.environ.get('CLA_API_BASE', '')
root_url = os.environ.get('DOCUSIGN_ROOT_URL', '')
integrator_key = cla.config.DOCUSIGN_INTEGRATOR_KEY
user_id = cla.config.DOCUSIGN_USER_ID
private_key = cla.config.DOCUSIGN_PRIVATE_KEY
auth_server = os.environ.get('DOCUSIGN_AUTH_SERVER')
token_endpoint = f'https://{auth_server}/oauth/token'

username = os.environ.get('DOCUSIGN_USERNAME', '')
password = os.environ.get('DOCUSIGN_PASSWORD', '')
integrator_key = os.environ.get('DOCUSIGN_INTEGRATOR_KEY', '')

lf_group_client_url = os.environ.get('LF_GROUP_CLIENT_URL', '')
lf_group_client_id = os.environ.get('LF_GROUP_CLIENT_ID', '')
Expand Down Expand Up @@ -106,14 +101,28 @@ def __init__(self):
self.s3storage = None

def initialize(self, config):
try:
cla.log.debug('Initializing DocuSign client...')
token = request_access_token()
self.client = pydocusign.DocuSignClient(root_url=root_url,oauth2_token=token)
except (Exception) as ex:
cla.log.error("Error authenticating Docusign: {}".format(ex))
return {'errors': {'Error authenticating Docusign'}}
self.client = pydocusign.DocuSignClient(root_url=root_url,
username=username,
password=password,
integrator_key=integrator_key)

try:
login_data = self.client.login_information()
login_account = login_data['loginAccounts'][0]
base_url = login_account['baseUrl']
account_id = login_account['accountId']
url = urlparse(base_url)
parsed_root_url = '{}://{}/restapi/v2'.format(url.scheme, url.netloc)
except Exception as e:
cla.log.error('Error logging in to DocuSign: {}'.format(e))
return {'errors': {'Error initializing DocuSign'}}

self.client = pydocusign.DocuSignClient(root_url=parsed_root_url,
account_url=base_url,
account_id=account_id,
username=username,
password=password,
integrator_key=integrator_key)
self.s3storage = S3Storage()
self.s3storage.initialize(None)

Expand Down Expand Up @@ -1362,26 +1371,16 @@ def populate_sign_url(self, signature, callback_url=None,
emailBody='CLA Sign Request for {}'.format(user_identifier),
supportedLanguage='en',
)



content_type = document.get_document_content_type()
try:
cla.log.debug(f'{fn} - {sig_type} - docusign document content type: {content_type}')
if document.get_document_s3_url() is not None:
pdf = self.get_document_resource(document.get_document_s3_url())
elif content_type.startswith('url+'):
pdf_url = document.get_document_content()
pdf = self.get_document_resource(pdf_url)
else:
cla.log.debug(f'{fn} - getting document content...')
content = document.get_document_content()
pdf = io.BytesIO(content)

except Exception as e:
cla.log.warning(f'{fn} - {sig_type} - error getting document resource: {e}')
return


if document.get_document_s3_url() is not None:
pdf = self.get_document_resource(document.get_document_s3_url())
elif content_type.startswith('url+'):
pdf_url = document.get_document_content()
pdf = self.get_document_resource(pdf_url)
else:
content = document.get_document_content()
pdf = io.BytesIO(content)

doc_name = document.get_document_name()
cla.log.debug(f'{fn} - {sig_type} - docusign document '
Expand Down Expand Up @@ -1411,7 +1410,6 @@ def populate_sign_url(self, signature, callback_url=None,
status=pydocusign.Envelope.STATUS_SENT,
recipients=[signer])

cla.log.debug(f'{fn} - {sig_type} - sending signature request to DocuSign...')
envelope = self.prepare_sign_request(envelope)

if not send_as_email:
Expand Down Expand Up @@ -1969,8 +1967,7 @@ def get_document_resource(self, url): # pylint: disable=no-self-use
:return: A resource that can be read()'d.
:rtype: Resource
"""
return requests.get(url, stream=True).raw
# return urllib.request.urlopen(url)
return urllib.request.urlopen(url)

def prepare_sign_request(self, envelope):
"""
Expand Down Expand Up @@ -2420,4 +2417,4 @@ def cla_signatory_email_content(params: ClaSignatoryEmailParams) -> (str, str):
email_body += f'<p>After you sign, {params.cla_manager_name} (as the initial CLA Manager for your company) will be able to maintain the list of specific employees authorized to contribute to the project(s) under this signed CLA.</p>'
email_body += f'<p>If you are authorized to sign on your company’s behalf, and if you approve {params.cla_manager_name} as your initial CLA Manager, please review the document and sign the CLA. If you have questions, or if you are not an authorized signatory of this company, please contact the requester at {params.cla_manager_email}.</p>'
email_body = append_email_help_sign_off_content(email_body, params.project_version)
return email_subject, email_body
return email_subject, email_body
Loading