def test_put_dry_run_doesnt_call(mocker, capsys): requests = mocker.patch('cdb.http.req') with silent(capsys), dry_run({}): http_put_payload("https://www.example.com", {}, "") requests.put.assert_not_called()
def test_503_put_retries_5_times_then_raises_HttpRetryExhausted(capsys): url, payload, api_token = stub_http_503('PUT', 1 + MAX_RETRY_COUNT) with retry_backoff_factor(0.001), raises(HttpRetryExhausted) as exc_info: http_put_payload(url, payload, api_token) assert exc_info.value.url() == url assert len(responses.calls) == 1 + MAX_RETRY_COUNT verify_approval(capsys)
def __call__(self): self._print_compliance() payload = { "evidence_type": self.evidence_type.value, "user_data": self.user_data.value, "contents": { "is_compliant": self.is_compliant.value == "TRUE", "url": self.ci_build_url.value, "description": self.description.value } } url = ApiSchema.url_for_artifact(self.host.value, self.merkelypipe, self.fingerprint.sha) http_put_payload(url, payload, self.api_token.value) return 'Putting', url, payload
def __call__(self): self._print_compliance() payload = { "sha256": self.fingerprint.sha, "filename": self.fingerprint.artifact_basename, "description": f"Created by build {self.ci_build_number.value}", "git_commit": self.artifact_git_commit.value, "commit_url": self.artifact_git_url.value, "build_url": self.ci_build_url.value, "is_compliant": self.is_compliant.value == 'TRUE', "user_data": self.user_data.value } url = ApiSchema.url_for_artifacts(self.host.value, self.merkelypipe) http_put_payload(url, payload, self.api_token.value) return 'Putting', url, payload
def create_artifact(api_token, host, project_config_file, sha256, filename, description, git_commit, commit_url, build_url, is_compliant): project_data = load_project_configuration(project_config_file) create_artifact_payload = { "sha256": sha256, "filename": filename, "description": description, "git_commit": git_commit, "commit_url": commit_url, "build_url": build_url, "is_compliant": is_compliant } url = ApiSchema.url_for_artifacts(host, project_data) http_put_payload(url, create_artifact_payload, api_token)
def __call__(self): is_compliant, pull_requests = get_pull_request_for_current_commit(self.env) payload = { "evidence_type": self.evidence_type.value, "contents": { "is_compliant": is_compliant, "description": self.description.value, "url": self.ci_build_url.value, "source": pull_requests, } } url = ApiSchema.url_for_artifact(self.host.value, self.merkelypipe, self.fingerprint.sha) http_put_payload(url, payload, self.api_token.value) if not is_compliant: raise ChangeError(f"Artifact with sha {self.fingerprint.sha} is not compliant") return 'Putting', url, payload
def __call__(self): junit_results_dir = self.test_results_dir.value is_compliant, message = is_compliant_tests_directory(junit_results_dir) description = "JUnit results xml verified by merkely/change: " + message payload = { "evidence_type": self.evidence_type.value, "user_data": self.user_data.value, "contents": { "is_compliant": is_compliant, "url": self.ci_build_url.value, "description": description } } url = ApiSchema.url_for_artifact(self.host.value, self.merkelypipe, self.fingerprint.sha) http_put_payload(url, payload, self.api_token.value) return 'Putting', url, payload
def test_put_stops_retrying_when_non_503_and_returns_None(capsys): url, payload, api_token = stub_http_503('PUT', 1 + 1) with retry_backoff_factor(0.001): response = http_put_payload(url, payload, api_token) assert response is None assert len(responses.calls) == 1 + 1 + 1 verify_approval(capsys)
def put_pipeline(project_file, env=os.environ): print("Ensure Project - loading " + project_file) with open(project_file) as json_data_file: project_data = load_project_configuration(json_data_file) host = env.get('CDB_HOST', CDB_SERVER) projects_url = ApiSchema.url_for_owner_projects(host, project_data) api_token = env.get('CDB_API_TOKEN', 'NO_API_TOKEN_DEFINED') print("Put pipeline") create_response = http_put_payload(url=projects_url, payload=project_data, api_token=api_token)
def __call__(self): url = ApiSchema.url_for_pipelines(self.host.value, self.merkelypipe) payload = self.merkelypipe http_put_payload(url, payload, self.api_token.value) return 'Putting', url, payload
def add_evidence(api_token, host, project_file_contents, sha256_digest, evidence): project_data = load_project_configuration(project_file_contents) url = ApiSchema.url_for_artifact(host, project_data, sha256_digest) http_put_payload(url, evidence, api_token)