-
Notifications
You must be signed in to change notification settings - Fork 7
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
Fix API errors when handling nil pointers to structs. #14
Conversation
Previously the API was sending empty JSON maps every time, which can confuse the Juju API. This branch also includes nice to have wrappers (controller.watch for watching all models and client.addMachine for adding a single machine). Also fix the AllModelWatcher by overriding the facade in wrappers so taht it accepts a watcher id. Finally, implement connectAndLogin as many clients will never want the former without the latter, and they don;t have to reimplement the connect and login dance including handling redirections every time.
juju.logout(); | ||
for (let i = 0; i < err.servers.length; i++) { | ||
const srv = err.servers[i]; | ||
// TODO(frankban): we should really try to connect to all servers and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you create an issue for this task so that we don't forget about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done: #15
api/client.js
Outdated
@@ -392,4 +465,4 @@ function uncapitalize(string) { | |||
} | |||
|
|||
|
|||
module.exports = {connect: connect}; | |||
module.exports = {connect: connect, connectAndLogin: connectAndLogin}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
module.exports = {connect, connectAndLogin};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -72,7 +72,14 @@ function wrapAdmin(cls) { | |||
port: srv.port, | |||
type: srv.type, | |||
scope: srv.scope, | |||
url: uuid => `wss://${srv.value}:${srv.port}/model/${uuid}/api` | |||
url: uuidOrURL => { | |||
let uuid = uuidOrURL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this re-assignment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make it more clear that first we are assuming a uuid is passed.
api/wrappers.js
Outdated
} | ||
@returns {Object} and handle that can be used to stop watching, via its stop | ||
@returns {Object} An handle that can be used to stop watching, via its stop |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
api/wrappers.js
Outdated
@@ -370,8 +603,10 @@ function wrapPinger(cls) { | |||
|
|||
module.exports = { | |||
wrapAdmin: wrapAdmin, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the key and value are the same you can drop one of them and js will expand it automagically for you
{foo} is the same as {foo: foo}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -202,19 +202,25 @@ def __str__(self): | |||
return '{' + text + '}' | |||
|
|||
def generate_request(self, key, value): | |||
parts = [key + ' = {};', value + ' = ' + value + ' || {};'] | |||
parts.extend(t.generate_request(key, value) for t in self.types) | |||
parts = ['if ({}) {{'.format(value), _indent(1, key + ' = {};')] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These curlies are warping my mind being for the replacement and for JS, maybe we should use %s
. A follow-up in any event...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Follow-up!
Previously the API was sending empty JSON maps every time, which can confuse the Juju API.
This branch also includes nice to have wrappers (controller.watch for watching all models and client.addMachine for adding a single machine).
Also fix the AllModelWatcher by overriding the facade in wrappers so taht it accepts a watcher id.
Finally, implement connectAndLogin as many clients will never want the former without the latter, and they don't have to reimplement the connect and login dance including handling redirections every time.