API Versioning in SailsJS - sails.js

Based on this issue, I have nested controllers and blueprints are disabled. My issue is something like
api/Controllers :
v1/UserController.js
routes.js
'POST /v1/user/register': 'v1/UserController.createUser'
Policies.js
'v1/UserController': {
'*': [ 'passport'],
createUser: ['ModelPolicy','AuditPolicy','reqBodyValidation']
If it is nested controller: while accessing the endpoint :
Output is something :
error: Sending 500 ("Server Error") response:
Error: Invalid route option, "model".
I don't know about any models named: `v1/user`
Appreciate to resolve.

We actually did this in our project, and you can actually do this if you specify a string literal as the key for the controller in the JSON object like so:
'v1/UserController' : {
'*': [ 'passport'],
createUser: ['ModelPolicy','AuditPolicy','reqBodyValidation']
}

Related

How to pass owner attribute when creating user story using Rally API?

I am trying to pass the owner attribute to create a user story in rally using rally API But I am encountering below error.
{
"CreateResult": {
"_rallyAPIMajor": "2",
"_rallyAPIMinor": "0",
"Errors": [
"Cannot parse object reference from \"{\"Owner\": {\"_refObjectName\": \"Ron\"}}\""
],
"Warnings": [
"Ignored JSON element HierarchicalRequirement.PortfolioItem during the processing of this request."
]
}
}
My request payload
{
"HierarchicalRequirement":{
"Name": "hello Wrold",
"Description":" 123 test description",
"Workspace": "/workspace/18686460234",
"Project":"/project/1025697468602323",
"PortfolioItem":"",
"Owner":{"_refObjectName":"Ron"},
"ScheduleState":"Defined"
}
}
Any thoughts?
In general, when referring to an object property that itself is an object (as in this case with the User object), you pass in the actual value of _ref, not another object. If you have previously been passed the reference to the user as a full blown URI, then you can still pass that in and the SDK will convert it to a _ref.
If you go to the webservice docs (https://rally1.rallydev.com/slm/doc/webservice/) for your subscription and go down to the User section, you can get the docs to fetch you some examples of users. The _ref will come back something like:
https://rally1.rallydev.com/slm/webservice/v2.0/user/39776836851
I believe that you can either use that, or just truncate it to the number at the end. So the code will need to be changed so that the Owner line reads:
"Owner" : "https://rally1.rallydev.com/slm/webservice/v2.0/user/39776836851"

Firebase Database REST get with orderBy value and parameters

database.rules.json
{
"rules": {
"meetings" : {
".read": true,
".write": true,
".indexOn" : ["date"]
}
}
}
Request URL
"https://{baseURL}/meetings.json?orderBy=date&equalTo=20181005"
Error Message
error: "orderBy must be a valid JSON encoded path"
But
"https://{baseURL}/meetings.json"
No Error.
What did I do wrong? Plz help me.
The value of the name parameter in your URL needs to be enclosed in " quotes. So:
https://{baseURL}/meetings.json?orderBy="date"&equalTo=20181005
Depending on the way you store the values of the date property, the value of the equalTo parameter may also need be enclosed in " quotes. If you store date as a string, it needs to be:
https://{baseURL}/meetings.json?orderBy="date"&equalTo="20181005"
For more on this, read the Firebase documentation on querying using the REST API.
I have faced the exact issue.. and the trick is..the passing value should be "string " encode,
as example below..
searchRecordById(recordId: string) {
return this.http.get(
`https://your-app.firebaseio.com/skdocs.json`,
{
params: {
**orderBy: '"folder"',
equalTo: '"Panchla-2"',**
},
}
);
}
You'll need to escape the quotes for it to work. E.g.
"https://{baseURL}/meetings.json?orderBy=\"date\"&equalTo=\"20181005\""
If you are using curl then try this:
curl 'https://{baseURL}/meetings.json?orderBy="date"&equalTo=20181005'
If you fetch url from web or etc then url should be :
https://{baseURL}/meetings.json?orderBy="date"&equalTo=20181005

Creating JWT custom claims in DataPower

Running on DataPower 7.5.2.0
I created a JWT Generator as part of a AAA Policy and it is working fine, I am able to generate, sign and then externally verify the JWT with no issues.
Now I want to add a custom claim to the JWT, so I ticked the box for Custom and then uploaded this Gateway script file:
var claim = {
"result" : {
"user" : "hardcode"
}
};
session.output.write(claim);
and it generates the correct JWT with the user attribute. However when I try to add a second value to it like so:
var claim = {
"result" : {
"user" : "hardcode",
"name" : "myname"
}
};
session.output.write(claim);
I now get this error:
[Error: Required CustomClaim Name or Value field missing] errorMessage: 'Required CustomClaim Name or Value field missing', errorCode: '0x8580005c', errorDescription: 'GatewayScript console log message.', errorSuggestion: 'GatewayScript console log message. Refer to the message for more information.'
Which is the same message I got before I realized I had to set the output to result from the InfoCenter's vague documentation.
How do I add multiple custom claims in the JWT Generator Gateway script??
It would appear that DataPower only allows you to add a single custom claim, so you just need to make that a complex object like so:
var claim = {
"result" : {
"claim" : {
"user" : "hardcode",
"one" : true,
"clientId" : "asdf-asdf-asdf",
"endpoint" : "http://192.168.142:8080/member/ws"
}
}
};
session.output.write(claim);
This then generates the correct JWT with a nest claim.
eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJhcGljIiwic3ViIjoiYWRtaW4iLCJleHAiOjE0ODIyNjU5ODQsImlhdCI6MTQ4MjI2MjM4NCwianRpIjoiZDhjNTE1ZDEtZmVjMS00ZGVmLThiNDctZmYzY2E2OWVjOWRiIiwibm9uY2UiOiJtN2lVZlBqTCIsImF1ZCI6ImlkMSIsImNsYWltIjp7InVzZXIiOiJmcmVkIiwib25lIjp0cnVlLCJjbGllbnRJZCI6ImFzZGYtYXNkZi1hc2RmIiwiZW5kcG9pbnQiOiJodHRwOi8vMTkyLjE2OC4xNDI6ODA4MC9tZW1iZXIvd3MifX0.viakwnM5bhhmGIn0QmDJTmsWCuIciO2BOdUVyxYpsFA

Issue with mondogb-morphia in grails application to store Map correctly in database

I'm using the plugin mongodb-morphia (0.7.8) in a grails (2.0.3) application and I experiment an issue with the type Map.
I want to store in my database a map of type Map but when I put that in my groovy file :
class ServiceInfo {
String name
Map<String,?> args
Date dateCreated // autoset by plugin
Date lastUpdated // autoset by plugin
static constraints = {
name nullable:false
}
}
I obtain the following error :
2012-04-29 14:39:43,876 [pool-2-thread-3] ERROR MongodbMorphiaGrailsPlugin - Error processing mongodb domain Artefact > fr.unice.i3s.modalis.yourcast.provider.groovy.ServiceInfo: Unknown type... pretty bad... call for help, wave your hands... yeah!
I tried just to specify Map in my file:
Map args
In that case I obtain the following simple warning:
INFO: MapKeyDifferentFromString complained about fr.unice.i3s.modalis.yourcast.provider.groovy.ServiceInfo.args : Maps cannot be keyed by Object (Map); Use a parametrized type that is supported (Map)
and when I try to save an object, the attribute args is simply omitted in the database.
For information my objects have this kind of representation:
def icalReader= new ServiceInfo(name:"IcalReader", args:['uri':DEFAULT_URL, 'path':"fr.unice.i3s.modalis.yourcast.sources.calendar.icalreader/"])
icalReader.save()
Finally, if I just say that args is a List:
List args
And I change my objects to take a List with only one Map, I just have a warning:
ATTENTION: The multi-valued field 'fr.unice.i3s.modalis.yourcast.provider.groovy.ServiceInfo.args' is a possible heterogenous collection. It cannot be verified. Please declare a valid type to get rid of this warning. null
but everything works fine and I've my map correctly stored in the database:
{ "_id" : ObjectId("4f9be39f0364bf4002cd48ad"), "name" : "IcalReader", "args" : [ { "path" : "fr.unice.i3s.modalis.yourcast.sources.calendar.icalreader/", "uri" : "http://localhost:8080/" } ], "dateCreated" : ISODate("2012-04-28T12:33:35.838Z"), "lastUpdated" : ISODate("2012-04-28T12:33:35.838Z") }
So is there something I forget in defining my map?
My service does work but I don't like hacks like "encapsulate a map in a list to serialize it" ;)
I don't know about Map, but could you use embedded datamodel instead?
class ServiceInfo {
...
#Embedded
MyArgs args
...
}
class MyArgs {
String key
String value
}

How to modify ajax response before jsTree creation?

How can I modify ajax response before jsTree creation? I would like to access each node ID and add prefix to it. On jsTree page the only clue is this: the function will receive two arguments - the node being loaded & a function". I need to do that before the tree is actually created, to avoid duplicate ID in the document.
"json_data" : {
"ajax" : {
"type": "GET",
"url" : "tree.json"
},
"data" : function(node, func){
//how to use that?
}}
I have expected to get JSON data here, modify it and return? But this will explode.
I have successfully manipulated data using the success callback in the instantiation of the jsTree. In my case, I am parsing XML data returned as JSON from a .NET webmethod. It should work for your case in a similar manner.
"ajax": {
"type": "GET"
"url": "tree.json",
"success": function (x) {
//manipulate string x to change id's here
return x;
}, ...
Another method is to use the "complete" callback function to manipulate the jsTree in its final form. I don't recommend it in your case of duplicate id's, however.