Skip to content
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

Merged
merged 2 commits into from
Jul 26, 2018

Conversation

frankban
Copy link
Member

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.

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
Copy link
Contributor

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.

Copy link
Member Author

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};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

module.exports = {connect, connectAndLogin};

Copy link
Member Author

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this re-assignment?

Copy link
Member Author

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A

Copy link
Member Author

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,
Copy link
Contributor

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}

Copy link
Member Author

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 + ' = {};')]
Copy link
Contributor

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...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up!

@frankban frankban merged commit 4718f36 into juju:master Jul 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants