Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Disable user tokens #186

Merged
merged 9 commits into from
Mar 25, 2015
Merged

Conversation

djmitche
Copy link
Contributor

@Callek, @jvehent

This, along with #175, should finish off the user-token work described in #163.

@djmitche djmitche modified the milestone: v1.2.0 Mar 16, 2015
@djmitche
Copy link
Contributor Author

Any comments on this?

@Callek
Copy link
Contributor

Callek commented Mar 24, 2015

(I didn't realize this was pending review) that said, I'm curious the use case for getting a users permissions outside of a request context....

@djmitche
Copy link
Contributor Author

The use is in this patch, in fact -- disable user tokens when the user no longer has the permissions embodied in the token.

@djmitche
Copy link
Contributor Author

I'd very much like to deploy this soon, since we'll need user tokens for tooltool uploads. Any chance of an r?

@djmitche djmitche added the r? label Mar 25, 2015
elif not disable and token.disabled:
job_status.log_message("Re-enabling token %d for user %s" % (token.id, token.user))
token.disabled = False
session.commit()
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this task is scheduled for an hour now, but I am slightly concerned that there will be a time where this takes longer than an hour. And then we have two copies doing duplicate work (the session as it stands means we'll have the same results each cycle).

My ideal would be something like, but it also may be overkill for this use case, I leave that up to you.

user_ids = [tok.user for tok in tables.Token.query.filter(tables.Token.typ == 'usr')]
for id in user_ids:
    session = current_app.db.session('relengapi')
    token = session.query(tables.Token).get(id)
    if not token:
      continue  # if the token was deleted while this was executing, do nothing.
   # ...
   session.commit()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As I understand it, committing a session with an iterator open will cause that iteration to fail.

I'm not too worried about overlaps -- we might get exceptions if both runs try to make changes, but the operations are idempotent so that won't hurt anything. The real fix is to use badpenny to run no more than one instance at a time (#132).

@Callek
Copy link
Contributor

Callek commented Mar 25, 2015

Only 1 line is missing from tokenauth/init imho might as well test it (at least partly);

https://coveralls.io/builds/2172898/source?filename=relengapi%2Fblueprints%2Ftokenauth%2F__init__.py#L49

That said, if you address my nits 👍 feel free to ping me here if you want a second pass at any new csets. (or need me for any followup to my comments)

djmitche added a commit to djmitche/build-relengapi that referenced this pull request Mar 25, 2015
@moz-v2v-gh moz-v2v-gh merged commit 52eb4bb into mozilla:master Mar 25, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants