Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
itminedu
synnefo
Commits
eb16ce84
Commit
eb16ce84
authored
Jan 03, 2013
by
Sofia Papagiannaki
Browse files
Migrate username to uuid in pithos permissions
parent
8bd1b76d
Changes
1
Hide whitespace changes
Inline
Side-by-side
snf-pithos-backend/pithos/backends/lib/sqlalchemy/alembic/versions/165ba3fbfe53_update_path_account.py
View file @
eb16ce84
...
...
@@ -11,10 +11,11 @@ revision = '165ba3fbfe53'
down_revision
=
'3dd56e750a3'
from
alembic
import
op
from
sqlalchemy.sql
import
table
,
column
from
sqlalchemy.sql
import
table
,
column
,
literal
,
and_
from
synnefo.lib.astakos
import
get_user_uuid
,
get_username
as
get_user_username
from
pithos.api.settings
import
SERVICE_TOKEN
,
USER_INFO_URL
from
pithos.api.settings
import
(
SERVICE_TOKEN
,
USER_INFO_URL
,
AUTHENTICATION_USERS
)
import
sqlalchemy
as
sa
...
...
@@ -25,7 +26,8 @@ def get_uuid(account):
if
uuid
:
return
uuid
try
:
uuid
=
get_user_uuid
(
SERVICE_TOKEN
,
account
,
USER_INFO_URL
)
uuid
=
get_user_uuid
(
SERVICE_TOKEN
,
account
,
USER_INFO_URL
,
AUTHENTICATION_USERS
)
except
Exception
,
e
:
print
'Unable to retrieve uuid for %s: %s'
%
(
account
,
e
)
return
...
...
@@ -41,7 +43,8 @@ def get_username(account):
if
username
:
return
username
try
:
username
=
get_user_username
(
SERVICE_TOKEN
,
account
,
USER_INFO_URL
)
username
=
get_user_username
(
SERVICE_TOKEN
,
account
,
USER_INFO_URL
,
AUTHENTICATION_USERS
)
except
Exception
,
e
:
print
'Unable to retrieve username for %s: %s'
%
(
account
,
e
)
return
...
...
@@ -68,6 +71,14 @@ x = table(
column
(
'path'
,
sa
.
String
(
2048
))
)
xvals
=
table
(
'xfeaturevals'
,
column
(
'feature_id'
,
sa
.
Integer
),
column
(
'key'
,
sa
.
Integer
),
column
(
'value'
,
sa
.
String
(
256
))
)
def
upgrade
():
connection
=
op
.
get_bind
()
...
...
@@ -104,6 +115,23 @@ def upgrade():
u
=
x
.
update
().
where
(
x
.
c
.
feature_id
==
id
).
values
({
'path'
:
path
})
connection
.
execute
(
u
)
s
=
sa
.
select
([
xvals
.
c
.
feature_id
,
xvals
.
c
.
key
,
xvals
.
c
.
value
])
s
=
s
.
where
(
xvals
.
c
.
value
!=
'*'
)
xfeaturevals
=
connection
.
execute
(
s
).
fetchall
()
for
feature_id
,
key
,
value
in
xfeaturevals
:
account
,
sep
,
group
=
value
.
partition
(
':'
)
uuid
=
get_uuid
(
account
)
if
not
uuid
:
continue
new_value
=
sep
.
join
([
uuid
,
group
])
u
=
xvals
.
update
()
u
=
u
.
where
(
and_
(
xvals
.
c
.
feature_id
==
feature_id
,
xvals
.
c
.
key
==
key
,
xvals
.
c
.
value
==
value
))
u
=
u
.
values
({
'value'
:
new_value
})
connection
.
execute
(
u
)
def
downgrade
():
connection
=
op
.
get_bind
()
...
...
@@ -140,3 +168,20 @@ def downgrade():
path
=
sep
.
join
([
username
,
rest
])
u
=
x
.
update
().
where
(
x
.
c
.
feature_id
==
id
).
values
({
'path'
:
path
})
connection
.
execute
(
u
)
s
=
sa
.
select
([
xvals
.
c
.
feature_id
,
xvals
.
c
.
key
,
xvals
.
c
.
value
])
s
=
s
.
where
(
xvals
.
c
.
value
!=
'*'
)
xfeaturevals
=
connection
.
execute
(
s
).
fetchall
()
for
feature_id
,
key
,
value
in
xfeaturevals
:
account
,
sep
,
group
=
value
.
partition
(
':'
)
username
=
get_username
(
account
)
if
not
username
:
continue
new_value
=
sep
.
join
([
username
,
group
])
u
=
xvals
.
update
()
u
=
u
.
where
(
and_
(
xvals
.
c
.
feature_id
==
feature_id
,
xvals
.
c
.
key
==
key
,
xvals
.
c
.
value
==
value
))
u
=
u
.
values
({
'value'
:
new_value
})
connection
.
execute
(
u
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment