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

ubus: Refresh session on Access denied #8111

Merged
merged 1 commit into from Jun 22, 2017
Merged

Conversation

glance-
Copy link
Contributor

@glance- glance- commented Jun 19, 2017

When a openwrt router reboots, all the session ids gets invalidated.
In that case we need to log in again and get a new session id.

Signed-off-by: Anton Lundin glance@acc.umu.se

@homeassistant homeassistant added merging-to-master This PR is merging into the RC branch and should probably change the branch to `dev`. new-platform platform: calendar.google cla-signed labels Jun 19, 2017
@mention-bot
Copy link

@glance-, thanks for your PR! By analyzing the history of the files in this pull request, we identified @Teagan42, @balloob and @fabaff to be potential reviewers.

@homeassistant
Copy link
Contributor

Hi @glance-,

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@glance- glance- changed the base branch from master to dev June 19, 2017 19:22
@@ -142,6 +165,11 @@ def _req_json_rpc(url, session_id, rpcmethod, subsystem, method, **params):

if res.status_code == 200:
response = res.json()
if 'error' in response:
if 'message' in response['error'] and response['error']['message'] == "Access denied":

Choose a reason for hiding this comment

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

line too long (98 > 79 characters)


self.parse_api_pattern = re.compile(r"(?P<param>\w*) = (?P<value>.*);")
self.lock = threading.Lock()
self.last_results = {}
self.url = 'http://{}/ubus'.format(host)

self.session_id = _get_session_id(self.url, username, password)
self.session_id = _get_session_id(self.url, self.username, self.password)

Choose a reason for hiding this comment

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

line too long (81 > 79 characters)

except PermissionError:
_LOGGER.warn("Invalid session detected." +
" Tryign to refresh session_id and re-run the rpc")
self.session_id = _get_session_id(self.url, self.username, self.password)

Choose a reason for hiding this comment

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

line too long (85 > 79 characters)

return fn(self, *args, **kwargs)
except PermissionError:
_LOGGER.warn("Invalid session detected." +
" Tryign to refresh session_id and re-run the rpc")

Choose a reason for hiding this comment

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

continuation line under-indented for visual indent

@glance-
Copy link
Contributor Author

glance- commented Jun 19, 2017

Wops. Managed to screw up creating the PR. From the wrong branch and to the wrong branch. Tried to fix it upp but sorry for the noise.

def _refresh_on_acccess_denied(func):
"""If remove rebooted, it lost our session so rebuld one and try again."""
# {'error': {'message': 'Access denied', 'code': -32002},
# 'id': 1, 'jsonrpc': '2.0'}
Copy link
Member

Choose a reason for hiding this comment

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

Please cleanup

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

except PermissionError:
_LOGGER.warning("Invalid session detected." +
" Tryign to refresh session_id and re-run the rpc")
self.session_id = _get_session_id(self.url, self.username, self.password)

Choose a reason for hiding this comment

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

line too long (85 > 79 characters)

When a openwrt router reboots, all the session ids gets invalidated.
In that case we need to log in again and get a new session id.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
@pvizeli pvizeli merged commit 5484177 into home-assistant:dev Jun 22, 2017
@balloob balloob mentioned this pull request Jul 1, 2017
glance- added a commit to glance-/home-assistant that referenced this pull request Jul 20, 2017
Back in "ubus: Refresh session on Access denied (home-assistant#8111)" I added the
decorator _refresh_on_acccess_denied. Somehow that stopped multiple ubus
trackers from working in parallel, and only the one first init'ed
worked.

Changing the order of the decorators fixes the issue but, I'm sorry to
say I can't figure out why. There's some magic somewhere which I'm
missing.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
balloob pushed a commit that referenced this pull request Jul 24, 2017
Back in "ubus: Refresh session on Access denied (#8111)" I added the
decorator _refresh_on_acccess_denied. Somehow that stopped multiple ubus
trackers from working in parallel, and only the one first init'ed
worked.

Changing the order of the decorators fixes the issue but, I'm sorry to
say I can't figure out why. There's some magic somewhere which I'm
missing.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
balloob pushed a commit that referenced this pull request Jul 24, 2017
Back in "ubus: Refresh session on Access denied (#8111)" I added the
decorator _refresh_on_acccess_denied. Somehow that stopped multiple ubus
trackers from working in parallel, and only the one first init'ed
worked.

Changing the order of the decorators fixes the issue but, I'm sorry to
say I can't figure out why. There's some magic somewhere which I'm
missing.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
dethpickle pushed a commit to dethpickle/home-assistant that referenced this pull request Aug 18, 2017
When a openwrt router reboots, all the session ids gets invalidated.
In that case we need to log in again and get a new session id.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
dethpickle pushed a commit to dethpickle/home-assistant that referenced this pull request Aug 18, 2017
Back in "ubus: Refresh session on Access denied (home-assistant#8111)" I added the
decorator _refresh_on_acccess_denied. Somehow that stopped multiple ubus
trackers from working in parallel, and only the one first init'ed
worked.

Changing the order of the decorators fixes the issue but, I'm sorry to
say I can't figure out why. There's some magic somewhere which I'm
missing.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
@home-assistant home-assistant locked and limited conversation to collaborators Oct 20, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants