How to get Sonarqube Metrics (i.e. vulnerabilities: A; B; C; D; E) Ratings via the web api - sonarqube-web

Please assist with the above. I have successfully implemented a web api to sonarqube and I am able to get values for the metrics I specify in the web api (ref: https://gazelle.ihe.net/sonar/web_api/api/measures)
The problem I have is, I want to get the metrics ratings (i.e A; B; C; D) for each metric. and the api only returns the values and not the ratings.
I also tried using component_tree and type by the ratings are not returned.
Please assist:)

The answer to this question is as follows:
The 'vulnerabilities' ratings (A,B,C,D,E) are represented by the metricKey 'security_rating', as vulnerabilities are under Security in sonarqube
Web API Request call: sonarqubeurl/api/measures/component?metricKeys=security_rating
The 'security_rating' is structured as follows: (1=A,2=B,3=C,4=D,5=E), it returns numbers (corresponding to the alphabets) instead of alphabets.
I hope this helps others as well

Related

How to fix a query in functions within foundry which is hiting ObjectSet:PagingAboveConfiguredLimitNotAllowed?

I have phonorgraph object with billions of rows and we are querying it through object set service
for example, I want to get all DriverLicences from certain city.
#Function()
public getDriverLicences(city: string): ObjectSet<DriverLicences> {
let drivers = Objects.search().DriverLicences().filter(row => row.city.exactMatch(city));
return drivers ;
}
I am facing this error when I am trying query it from slate:
ERROR 400: {"errorCode":"INVALID_ARGUMENT","errorName":"ObjectSet:PagingAboveConfiguredLimitNotAllowed","errorInstanceId":"0000-000","parameters":{}}
I understand that I am probably retrieving more than 100 000 results but I need all the results because of the implemented logic in the front is a complex slate dashboard built by another team that we cannot re-factor.
The issue here is that, specifically in the Slate <> Function connector, there is a "translation layer" that serializes the contents of the object set and provides a response data structure that materializes the property:value pairs for each object in the set.
This clearly doesn't work for large object sets where throwing so much data into the browser is likely to overwhelm the resources allocated to the tab.
From context it seems like you might be migrating an existing Slate app over to Functions; in the current version, how is the query limiting the number of results returned? It certainly must not be returning several 100 thousand results for further processing on the front end? (And if so, that might be an anti-pattern to consider addressing).
As for options that you could currently explore, you can sort your object set and then specify a smaller limit to return:
Objects.search().DriverLicences().filter(row => row.city.exactMatch(city)).orderBy(date_of_issue).take(100)
You'll find a few more details in the Functions documentation Reference entry on Ontology API: Object Sets in the section on Ordering and limiting.
You can even make a work around for the (current) lack of paging when return an ObjectSet to Slate by using the last value from the property ordered on (i.e. date_of_issue) as a filter in the subsequent request and return the next N objects.
This can work if you need a Slate table or HTML widget that renders on set of results then, on a user action, gets the next page.

Simperium Data Dictionary or Decoder Ring for Return Value on "all" call?

I've looked through all of the Simperium API docs for all of the different programming languages and can't seem to find this. Is there any documentation for the data returned from an ".all" call (e.g. api.todo.all(:cv=>nil, :data=>false, :username=>false, :most_recent=>false, :timeout=>nil) )?
For example, this is some data returned:
{"ccid"=>"10101010101010101010101010110101010",
"o"=>"M",
"cv"=>"232323232323232323232323232",
"clientid"=>"ab-123123123123123123123123",
"v"=>{
"date"=>{"o"=>"+", "v"=>"2015-08-20T00:00:00-07:00"},
"calendar"=>{"o"=>"+", "v"=>false},
"desc"=>{"o"=>"+", "v"=>"<p>test</p>\r\n"},
"location"=>{"o"=>"+", "v"=>"Los Angeles"},
"id"=>{"o"=>"+", "v"=>43}
},
"ev"=>1,
"id"=>"abababababababababababababab/10101010101010101010101010110101010"}
I can figure out some of it just from context or from the name of the key but a lot of it is guesswork and trial and error. The one that concerns me is the value returned for the "o" key. I assume that a value of "M" is modify and a value of "+" is add. I've also run into "-" for delete and just recently discovered that there is also a "! '-'" which is also a delete but don't know what else it signifies. What other values can be returned in the "o" key? Are there other keys/values that can be returned but are rare? Is there documentation that details what can be returned (that would be the most helpful)?
If it matters, I am using the Ruby API but I think this is a question that, if answered, can be helpful for all APIs.
The response you are seeing is a list of all of the changes which have occurred in the given bucket since some point in its history. In the case where cv is blank, it tries to get the full history.
You can find some of the details in the protocol documentation though it's incomplete and focused on the WebSocket message syntax (the operations are the same however as with the HTTP API).
The information provided by the v parameter is the result of applying the JSON-diff algorithm to the data between changes. With this diff information you can reconstruct the data at any given version as the changes stream in.

Do Couchbase reactive clients guarantee order of rows in view query result

I use Couchbase Java SDK 2.2.6 with Couchbase server 4.1.
I query my view with the following code
public <T> List<T> findDocuments(ViewQuery query, String bucketAlias, Class<T> clazz) {
// We specifically set reduce false and include docs to retrieve docs
query.reduce(false).includeDocs();
log.debug("Find all documents, query = {}", decode(query));
return getBucket(bucketAlias)
.query(query)
.allRows()
.stream()
.map(row -> fromJsonDocument(row.document(), clazz))
.collect(Collectors.toList());
}
private static <A> A fromJsonDocument(JsonDocument saved, Class<A> clazz) {
log.debug("Retrieved json document -> {}", saved);
A object = fromJson(saved.content(), clazz);
return object;
}
In the logs from the fromJsonDocument method I see that rows are not always sorted by the row key. Usually they are, but sometimes they are not.
If I just run this query in browser couchbase GUI, I always receive results in expected order. Is it a bug or expected that view query results are not sorted when queried with async client?
What is the behaviour in different clients, not java?
This is due to the asynchronous nature of your call in the Java client + the fact that you used includeDocs.
What includeDocs will do is that it will weave in a call to get for each document id received from the view. So when you look at the asynchronous sequence of AsyncViewRow with includeDocs, you're actually looking at a composition of a row returned by the view and an asynchronous retrieval of the whole document.
If a document retrieval has a little bit of latency compared to the one for the previous row, it could reorder the (row+doc) emission.
But good news everyone! There is a includeDocsOrdered alternative in the ViewQuery that takes exactly the same parameters as includeDocs but will ensure that AsyncViewRow come in the same order returned by the view.
This is done by eagerly triggering the get retrievals but then buffering those that arrive out of order, so as to maintain the original order without sacrificing too much performance.
That is quite specific to the Java client, with its usage of RxJava. I'm not even sure other clients have the notion of includeDocs...

Most "popular" Python repos on GitHub

Based on the v3 documentation I would have thought that this:
$ curl https://api.github.com/legacy/repos/search/python?language=Python&sort=forks&order=desc
would return the top 100 Python repositories in descending order of number of forks. It actually returns an empty (json) list of repositories.
This:
$ curl https://api.github.com/legacy/repos/search/python?language=Python&sort=forks
returns a list of repositories (in json), but many of them are not listed as Python repositories.
So, clearly I have misunderstood the Github API. What is the accepted way of retrieving the top N repositories for a particular language?
As pengwynn said -- currently this is not easily doable via GitHub's API alone. However, have a look at this alternative way of querying using the GitHub Archive project: How to find the 100 largest GitHub repositories for a past date?
In essence, you can query GitHub's historical data using an SQL-like language. So, if having real-time results is not something that is important for you, you could execute the following query on https://bigquery.cloud.google.com/?pli=1 to get the top 100 Python repos as on April 1st 2013 (yesterday), descending by the number of forks:
SELECT MAX(repository_forks) as forks, repository_url
FROM [githubarchive:github.timeline]
WHERE (created_at CONTAINS "2013-04-01" and repository_language = "Python")
GROUP BY repository_url
ORDER BY forks
DESC LIMIT 100
I've put the results of the query in this Gist in CSV format, and the top few repos are:
forks repository_url
1913 https://github.com/django/django
1100 https://github.com/facebook/tornado
994 https://github.com/mitsuhiko/flask
...
The intent of Repository Search API is to find Repositories by keyword and then further filter those results by the other optional query string parameters.
Since you're missing a ?, you're passing the entire intended query string as the :keyword. I'm sorry, we do not support your intended search via the GitHub API at this time.
Try this:
https://api.github.com/search/repositories?q=language:Python&sort=forks&order=desc
It is searching over repositories.

Couchbase strange view behavior with keys with zero

I hava a database, that contains chat messages between users (1 message copy per user: 1 message for sender and one for recepient). Running Couchbase server 2.0 cluster with 2 machines (1 linux and 1 windows).
I use such map function to retreive messages betwen users:
function (doc) {
if (doc.type == "msg"){
emit([doc.OwnerId, doc.SndrId, doc.Date], {"Date":doc.Date, "OwnerId":doc.OwnerId, "RcptId":doc.RcptId, "SndrId":doc.SndrId, "Text":doc.Text, "Unread":doc.Unread, "id": doc.id, "type":doc.type});
emit([doc.OwnerId, doc.RcptId, doc.Date], {"Date":doc.Date, "OwnerId":doc.OwnerId, "RcptId":doc.RcptId, "SndrId":doc.SndrId, "Text":doc.Text, "Unread":doc.Unread, "id": doc.id, "type":doc.type});
}
}
So if I try to receive some messages (ordered decending by date) from the beggining I used such startkey & endkey:
startkey=[1,2,{}]
endkey=[1,2,0]
But in this way I get not all messages. To get all messages I need to use
startkey=[1,2,{}]
endkey=[1,2]
Here is an example. For key with zero:
{"total_rows":1106,"rows":[
{"id":"msg_8aaca454-5580-4e49-a081-918d8eaba9d6","key":[8,75,1342200837278],"value":{"Date":1342200837278,"OwnerId":8,"RcptId":8,"SndrId":75,"Text":"02","Unread":false,"id":"8aaca454-5580-4e49-a081-918d8eaba9d6","type":"msg"}},
{"id":"msg_49417551-bdc9-477b-b8c2-1f36051bb930","key":[8,75,1342199880920],"value":{"Date":1342199880920,"OwnerId":8,"RcptId":75,"SndrId":8,"Text":"4","Unread":false,"id":"49417551-bdc9-477b-b8c2-1f36051bb930","type":"msg"}},
{"id":"msg_2724f077-1e76-4fbc-9a4b-f34cb71e2db0","key":[8,75,1342108023448],"value":{"Date":1342108023448,"OwnerId":8,"RcptId":75,"SndrId":8,"Text":"55","Unread":false,"id":"2724f077-1e76-4fbc-9a4b-f34cb71e2db0","type":"msg"}},
{"id":"msg_9cc91327-4ba3-45b5-ab64-f2ca63510e8d","key":[8,75,1341413650113],"value":{"Date":1341413650113,"OwnerId":8,"RcptId":75,"SndrId":8,"Text":"3","Unread":false,"id":"9cc91327-4ba3-45b5-ab64-f2ca63510e8d","type":"msg"}},
{"id":"msg_9a386663-8a2b-42d9-ae30-0634a98fe574","key":[8,75,1341413648335],"value":{"Date":1341413648335,"OwnerId":8,"RcptId":75,"SndrId":8,"Text":"1","Unread":false,"id":"9a386663-8a2b-42d9-ae30-0634a98fe574","type":"msg"}}
]
}
With keys without zero:
{"total_rows":1106,"rows":[
{"id":"msg_dc4b7758-1f0e-491c-a80d-bf3124dc0ad7","key":[8,75,1342200856186],"value":{"Date":1342200856186,"OwnerId":8,"RcptId":8,"SndrId":75,"Text":"03","Unread":false,"id":"dc4b7758-1f0e-491c-a80d-bf3124dc0ad7","type":"msg"}},
{"id":"msg_8aaca454-5580-4e49-a081-918d8eaba9d6","key":[8,75,1342200837278],"value":{"Date":1342200837278,"OwnerId":8,"RcptId":8,"SndrId":75,"Text":"02","Unread":false,"id":"8aaca454-5580-4e49-a081-918d8eaba9d6","type":"msg"}},
{"id":"msg_b2fe9ca0-aa28-41a6-ab3c-09ece6a5e14a","key":[8,75,1342200787811],"value":{"Date":1342200787811,"OwnerId":8,"RcptId":8,"SndrId":75,"Text":"01","Unread":true,"id":"b2fe9ca0-aa28-41a6-ab3c-09ece6a5e14a","type":"msg"}},
{"id":"msg_49417551-bdc9-477b-b8c2-1f36051bb930","key":[8,75,1342199880920],"value":{"Date":1342199880920,"OwnerId":8,"RcptId":75,"SndrId":8,"Text":"4","Unread":false,"id":"49417551-bdc9-477b-b8c2-1f36051bb930","type":"msg"}},
{"id":"msg_0d7dc822-b76c-42f9-87ba-3dc486100526","key":[8,75,1342180778835],"value":{"Date":1342180778835,"OwnerId":8,"RcptId":75,"SndrId":8,"Text":"Gcgjvv6gvvbnbvvbh B2B bb cb B2B","Unread":false,"id":"0d7dc822-b76c-42f9-87ba-3dc486100526","type":"msg"}},
{"id":"msg_6b26a65f-68e1-4728-87f1-59ea5e0f0c5d","key":[8,75,1342114611144],"value":{"Date":1342114611144,"OwnerId":8,"RcptId":75,"SndrId":8,"Text":"546546546546546546546546546546","Unread":false,"id":"6b26a65f-68e1-4728-87f1-59ea5e0f0c5d","type":"msg"}},
{"id":"msg_f89b09ac-ccf1-4958-85c0-259b0b68752b","key":[8,75,1342108583566],"value":{"Date":1342108583566,"OwnerId":8,"RcptId":75,"SndrId":8,"Text":"123","Unread":false,"id":"f89b09ac-ccf1-4958-85c0-259b0b68752b","type":"msg"}},
{"id":"msg_2724f077-1e76-4fbc-9a4b-f34cb71e2db0","key":[8,75,1342108023448],"value":{"Date":1342108023448,"OwnerId":8,"RcptId":75,"SndrId":8,"Text":"55","Unread":false,"id":"2724f077-1e76-4fbc-9a4b-f34cb71e2db0","type":"msg"}},
{"id":"msg_9cc91327-4ba3-45b5-ab64-f2ca63510e8d","key":[8,75,1341413650113],"value":{"Date":1341413650113,"OwnerId":8,"RcptId":75,"SndrId":8,"Text":"3","Unread":false,"id":"9cc91327-4ba3-45b5-ab64-f2ca63510e8d","type":"msg"}},
{"id":"msg_847b2901-95e3-49b9-8756-e495872558a8","key":[8,75,1341413649161],"value":{"Date":1341413649161,"OwnerId":8,"RcptId":75,"SndrId":8,"Text":"2","Unread":false,"id":"847b2901-95e3-49b9-8756-e495872558a8","type":"msg"}}
]
}
Can anyone explain why it not binds all messages in first case?
Thanks to Filipe Manana from couchbase team, who answered this question.
This issue is caused by Erlang OTP R14B03 (and all prior versions) on 64 bits platforms.
Here is Filipe's commit that fixes this bug https://github.com/erlang/otp/commit/03d8c2877342d5ed57596330a61ec0374092f136
For more details see http://www.couchbase.com/forums/thread/couchbase-view-not-rerurning-all-values
NB CouchDB and CouchBase are as similar as Membase and MySQL = products that start with the same prefix. Best not to get them confused!
It might be related to whether sorting is done via ASCII (what you are expecting) vs via unicode collation. Some more information here http://wiki.apache.org/couchdb/View_collation but that applies to CouchDB, not CouchBase. Maybe that helps?