-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OTWO-6954 api for create scan project
- Loading branch information
1 parent
79a16d4
commit 8f9cf97
Showing
12 changed files
with
387 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# frozen_string_literal: true | ||
|
||
class ScanCoverityApi | ||
URL = ENV['COVERITY_SCAN_URL'] | ||
|
||
class << self | ||
def resource_uri(path = nil, _query = {}) | ||
URI("#{URL}/#{path}.json") | ||
end | ||
|
||
def get_response(path = nil, query = {}) | ||
uri = resource_uri(path, query) | ||
response = Net::HTTP.get_response(uri) | ||
handle_errors(response) { JSON.parse(response.body) } | ||
end | ||
|
||
def save(path = nil, query = {}) | ||
uri = resource_uri(path, query) | ||
response = Net::HTTP.post_form(uri, query) | ||
handle_errors(response) do | ||
hsh = JSON.parse(response.body) | ||
set_attributes_or_errors(response, hsh) | ||
end | ||
rescue JSON::ParserError | ||
response.body | ||
end | ||
|
||
private | ||
|
||
def handle_errors(response) | ||
case response | ||
when Net::HTTPServerError | ||
raise ScanCoverityApiError, "#{response.message} => #{response.body}" | ||
else | ||
yield | ||
end | ||
end | ||
|
||
def save_success?(response) | ||
response.is_a?(Net::HTTPSuccess) | ||
end | ||
|
||
def set_errors(hsh) | ||
@errors = hsh.key?('error') ? hsh['error'].with_indifferent_access : hsh | ||
false | ||
end | ||
|
||
def set_attributes(hsh) | ||
@attributes = hsh | ||
hsh.each do |key, value| | ||
instance_variable_set("@#{key}", value) | ||
end | ||
end | ||
|
||
def set_attributes_or_errors(response, hsh) | ||
save_success?(response) ? set_attributes(hsh) : set_errors(hsh) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# frozen_string_literal: true | ||
|
||
class ScanCoverityApiError < StandardError | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
fixtures/vcr_cassettes/CreateProjectFromMatchURL_record_none.yml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
--- | ||
http_interactions: | ||
- request: | ||
method: post | ||
uri: http://vcrlocalhost.org:5008/api/projects.json | ||
body: | ||
encoding: US-ASCII | ||
string: name=Dummytestdata&repo_url=https%3A%2F%2Fgithub.com%2Frails%2Frails&user_id=e1dc08285095f4ff99199c3436532768&language=JAVA | ||
headers: | ||
Accept-Encoding: | ||
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3 | ||
Accept: | ||
- "*/*" | ||
User-Agent: | ||
- Ruby | ||
Host: | ||
- vcrlocalhost.org:5008 | ||
Content-Type: | ||
- application/x-www-form-urlencoded | ||
response: | ||
status: | ||
code: 201 | ||
message: success | ||
headers: | ||
Date: | ||
- Tue, 14 Mar 2023 11:09:01 GMT | ||
Content-Type: | ||
- text/plain | ||
Transfer-Encoding: | ||
- chunked | ||
Connection: | ||
- keep-alive | ||
X-Request-Id: | ||
- 83ba289fe76f4ed9a882a2a823be6d87 | ||
X-Runtime: | ||
- '0.006584' | ||
X-Powered-By: | ||
- Phusion Passenger 5.0.30 | ||
Status: | ||
- 201 | ||
Strict-Transport-Security: | ||
- max-age=15724800; includeSubDomains | ||
Set-Cookie: | ||
- incap_ses_1559_941207=QCvHB5yXehqCVRkBiK6iFc1VEGQAAAAA7G/+9TvEcxaAWzmLbgQZBg==; | ||
path=/; Domain=.coverity.com | ||
- nlbi_941207=bJ7MAhEsdhG1ODi7vBlnAwAAAAA3GPUJcWfVnLBF6Cb2d22Z; path=/; Domain=.coverity.com | ||
- visid_incap_941207=QJfhtfo9QgiltzVrch2GzcxVEGQAAAAAQUIPAAAAAAD7Vbp21tN9wMYyJIC789MH; | ||
expires=Tue, 12 Mar 2024 15:15:25 GMT; HttpOnly; path=/; Domain=.coverity.com | ||
X-Cdn: | ||
- Imperva | ||
X-Iinfo: | ||
- 12-49168636-49168647 NNYN CT(229 230 0) RT(1678792140667 100) q(0 0 5 5) r(7 | ||
7) U24 | ||
body: | ||
encoding: ASCII-8BIT | ||
string: '{"scan_project_id": 1 }' | ||
recorded_at: Tue, 14 Mar 2023 11:09:02 GMT | ||
--- | ||
http_interactions: | ||
- request: | ||
method: post | ||
uri: http://vcrlocalhost.org:5008/api/projects.json | ||
body: | ||
encoding: US-ASCII | ||
string: name=&repo_url=https%3A%2F%2Fgithub.com%2Frails%2Frails&user_id=d1224324214 | ||
headers: | ||
Accept-Encoding: | ||
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3 | ||
Accept: | ||
- "*/*" | ||
User-Agent: | ||
- Ruby | ||
Host: | ||
- vcrlocalhost.org:5008 | ||
Content-Type: | ||
- application/x-www-form-urlencoded | ||
response: | ||
status: | ||
code: 401 | ||
message: unauthorized | ||
headers: | ||
Date: | ||
- Tue, 14 Mar 2023 11:09:01 GMT | ||
Content-Type: | ||
- text/plain | ||
Transfer-Encoding: | ||
- chunked | ||
Connection: | ||
- keep-alive | ||
X-Request-Id: | ||
- 83ba289fe76f4ed9a882a2a823be6d87 | ||
X-Runtime: | ||
- '0.006584' | ||
X-Powered-By: | ||
- Phusion Passenger 5.0.30 | ||
Status: | ||
- 401 | ||
Strict-Transport-Security: | ||
- max-age=15724800; includeSubDomains | ||
Set-Cookie: | ||
- incap_ses_1559_941207=QCvHB5yXehqCVRkBiK6iFc1VEGQAAAAA7G/+9TvEcxaAWzmLbgQZBg==; | ||
path=/; Domain=.coverity.com | ||
- nlbi_941207=bJ7MAhEsdhG1ODi7vBlnAwAAAAA3GPUJcWfVnLBF6Cb2d22Z; path=/; Domain=.coverity.com | ||
- visid_incap_941207=QJfhtfo9QgiltzVrch2GzcxVEGQAAAAAQUIPAAAAAAD7Vbp21tN9wMYyJIC789MH; | ||
expires=Tue, 12 Mar 2024 15:15:25 GMT; HttpOnly; path=/; Domain=.coverity.com | ||
X-Cdn: | ||
- Imperva | ||
X-Iinfo: | ||
- 12-49168636-49168647 NNYN CT(229 230 0) RT(1678792140667 100) q(0 0 5 5) r(7 | ||
7) U24 | ||
body: | ||
encoding: ASCII-8BIT | ||
string: '{"message": "unauthorized"}' | ||
recorded_at: Tue, 14 Mar 2023 11:09:02 GMT | ||
recorded_with: VCR 6.0.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
--- | ||
http_interactions: | ||
- request: | ||
method: post | ||
uri: http://vcrlocalhost.org:5008/api/projects.json | ||
body: | ||
encoding: US-ASCII | ||
string: name=&repo_url=https%3A%2F%2Fgithub.com%2Frails%2Frails&user_id=d1224324214 | ||
headers: | ||
Accept-Encoding: | ||
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3 | ||
Accept: | ||
- "*/*" | ||
User-Agent: | ||
- Ruby | ||
Host: | ||
- vcrlocalhost.org:5008 | ||
Content-Type: | ||
- application/x-www-form-urlencoded | ||
response: | ||
status: | ||
code: 400 | ||
message: bad_request | ||
headers: | ||
Date: | ||
- Tue, 14 Mar 2023 11:09:01 GMT | ||
Content-Type: | ||
- text/plain | ||
Transfer-Encoding: | ||
- chunked | ||
Connection: | ||
- keep-alive | ||
X-Request-Id: | ||
- 83ba289fe76f4ed9a882a2a823be6d87 | ||
X-Runtime: | ||
- '0.006584' | ||
X-Powered-By: | ||
- Phusion Passenger 5.0.30 | ||
Status: | ||
- 400 | ||
Strict-Transport-Security: | ||
- max-age=15724800; includeSubDomains | ||
Set-Cookie: | ||
- incap_ses_1559_941207=QCvHB5yXehqCVRkBiK6iFc1VEGQAAAAA7G/+9TvEcxaAWzmLbgQZBg==; | ||
path=/; Domain=.coverity.com | ||
- nlbi_941207=bJ7MAhEsdhG1ODi7vBlnAwAAAAA3GPUJcWfVnLBF6Cb2d22Z; path=/; Domain=.coverity.com | ||
- visid_incap_941207=QJfhtfo9QgiltzVrch2GzcxVEGQAAAAAQUIPAAAAAAD7Vbp21tN9wMYyJIC789MH; | ||
expires=Tue, 12 Mar 2024 15:15:25 GMT; HttpOnly; path=/; Domain=.coverity.com | ||
X-Cdn: | ||
- Imperva | ||
X-Iinfo: | ||
- 12-49168636-49168647 NNYN CT(229 230 0) RT(1678792140667 100) q(0 0 5 5) r(7 | ||
7) U24 | ||
body: | ||
encoding: ASCII-8BIT | ||
string: '{"message": "Language cant be blank"}' | ||
recorded_at: Tue, 14 Mar 2023 11:09:02 GMT | ||
recorded_with: VCR 6.0.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.