python-provy / provy

provy is a provisioning system in python.

Home Page:http://docs.provy.me

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

What is role of "owner" context variable

jbzdak opened this issue · comments

Is it OK to place code like this in most of the role functions:

if owner is None:
       owner = self.context.get('owner', None)

such snippets were present on some functions, and I put it in some more, in this case I could log in to remote as user X, and put have every file I change be labeled as user Y.

When I was provisioning my web server it seemed a good idea at the time, but now I'm not sure.

I think the Roles that require a user (internally use it to specify the
owner of any resource) should allow the provy script to override it passing
it as a parameter.

That said, I think a sensible default is the user that was created during
provisioning (the script you are using).

What do you guys think?

Cheers,
Bernardo Heynemann

On Mon, Oct 15, 2012 at 4:46 PM, Jacek Bzdak notifications@github.comwrote:

Is it OK to place code like this in most of the role functions:

if owner is None:
owner = self.context.get('owner', None)

such snippets were present on some functions, and I put it in some more,
in this case I could log in to remote as user X, and put have every file I
change be labeled as user Y.

When I was provisioning my web server it seemed a good idea at the time,
but now I'm not sure.


Reply to this email directly or view it on GitHubhttps://github.com/heynemann/provy/issues/63.

Well, I didn't quite get why you need this for, but if it makes sense to you, go for it. My hint, though, is that

owner = self.context.get('owner', None)

is exactly the same as

owner = self.context.get('owner')

@heynemann agreed. Is this what you wanted, @jbzdak ?

I really have no idea. I'd either put this on most of the functions thay update files, or drop it altogether. When I provisioned student's lab I would rather than pass owner parameters just chmod everything, and it worked well, and it was less fuss.

Owner variaviable is also set by UserRole when ensure_user is called, which may be not what I want. So I have no clear preference, and looking for decision.

I can either add it to everything that takes owner argument or just drop from places I added it to Role.

I've felt the need to have an easier way to change the context user in a certain block myself, but haven't thought of a clean way to do this myself. What if we have a context manager that, say, changes the user and restores it after the exit? What do you guys think? Would this be a possible solution to you, @jbzdak ?

Context manager would definetely be OK.

+1

Cheers,
Bernardo Heynemann

On Mon, Oct 15, 2012 at 5:26 PM, Jacek Bzdak notifications@github.comwrote:

Context manager would definetely be OK.


Reply to this email directly or view it on GitHubhttps://github.com/heynemann/provy/issues/63#issuecomment-9460228.

While we are at it maybe do context manager also for file modifiers?

like:

with self.file_mode(700, owner="foo:bar"): 
    self.ensure_dir("/home/foo/.ssh")
    self.put_file("something", "/home/foo/.ssh/authorized_keys")

when doing ssh od sudo i had used too much chown and chmod (linux can be picky).

+1 as well

We just need to make sure to have a place in the docs website that explains
the context managers thoroughly.

On Mon, Oct 15, 2012 at 5:31 PM, Jacek Bzdak notifications@github.comwrote:

While we are at it maybe do context manager also for file modifiers?

like:

with self.file_mode(700, owner="foo:bar"):
self.ensure_dir("/home/foo/.ssh")
self.put_file("something", "/home/foo/.ssh/authorized_keys")

when doing ssh od sudo i had used too much chown and chmod (linux can be
picky).


Reply to this email directly or view it on GitHubhttps://github.com/heynemann/provy/issues/63#issuecomment-9460399.

+1 for me too, and +1 for explicit explanation in the docs

Will be done this way.