summaryrefslogtreecommitdiffstats
path: root/gluster
diff options
context:
space:
mode:
Diffstat (limited to 'gluster')
-rw-r--r--gluster/swift/common/middleware/gswauth/swauth/middleware.py46
-rw-r--r--gluster/swift/obj/diskfile.py37
2 files changed, 45 insertions, 38 deletions
diff --git a/gluster/swift/common/middleware/gswauth/swauth/middleware.py b/gluster/swift/common/middleware/gswauth/swauth/middleware.py
index 6388aa2..996228d 100644
--- a/gluster/swift/common/middleware/gswauth/swauth/middleware.py
+++ b/gluster/swift/common/middleware/gswauth/swauth/middleware.py
@@ -40,13 +40,9 @@ from swift.common.utils import cache_from_env, get_logger, get_remote_client, \
import swift.common.wsgi
-from gluster.swift.common.middleware.gswauth.swauth import swift_version
from gluster.swift.common.middleware.gswauth.swauth import authtypes
-MEMCACHE_TIME = swift_version.newer_than('1.7.7-dev')
-
-
class Swauth(object):
"""
Scalable authentication and authorization system that uses Swift as its
@@ -349,14 +345,9 @@ class Swauth(object):
expires_from_now = float(resp.getheader('x-auth-ttl'))
groups = resp.getheader('x-auth-groups')
if memcache_client:
- if MEMCACHE_TIME:
- memcache_client.set(
- memcache_key, (time() + expires_from_now, groups),
- time=expires_from_now)
- else:
- memcache_client.set(
- memcache_key, (time() + expires_from_now, groups),
- timeout=expires_from_now)
+ memcache_client.set(
+ memcache_key, (time() + expires_from_now, groups),
+ timeout=expires_from_now)
else:
path = quote('/v1/%s/.token_%s/%s' %
(self.auth_account, token[-1], token))
@@ -375,16 +366,10 @@ class Swauth(object):
groups.append(detail['account_id'])
groups = ','.join(groups)
if memcache_client:
- if MEMCACHE_TIME:
- memcache_client.set(
- memcache_key,
- (detail['expires'], groups),
- time=float(detail['expires'] - time()))
- else:
- memcache_client.set(
- memcache_key,
- (detail['expires'], groups),
- timeout=float(detail['expires'] - time()))
+ memcache_client.set(
+ memcache_key,
+ (detail['expires'], groups),
+ timeout=float(detail['expires'] - time()))
return groups
def authorize(self, req):
@@ -1369,18 +1354,11 @@ class Swauth(object):
if not memcache_client:
raise Exception(
'No memcache set up; required for Swauth middleware')
- if MEMCACHE_TIME:
- memcache_client.set(
- memcache_key,
- (self.itoken_expires,
- '.auth,.reseller_admin,%s.auth' % self.reseller_prefix),
- time=self.token_life)
- else:
- memcache_client.set(
- memcache_key,
- (self.itoken_expires,
- '.auth,.reseller_admin,%s.auth' % self.reseller_prefix),
- timeout=self.token_life)
+ memcache_client.set(
+ memcache_key,
+ (self.itoken_expires,
+ '.auth,.reseller_admin,%s.auth' % self.reseller_prefix),
+ timeout=self.token_life)
return self.itoken
def get_admin_detail(self, req):
diff --git a/gluster/swift/obj/diskfile.py b/gluster/swift/obj/diskfile.py
index 6e6856d..cccd5e6 100644
--- a/gluster/swift/obj/diskfile.py
+++ b/gluster/swift/obj/diskfile.py
@@ -44,7 +44,8 @@ from gluster.swift.common.utils import read_metadata, write_metadata, \
get_object_metadata
from gluster.swift.common.utils import X_CONTENT_TYPE, \
X_TIMESTAMP, X_TYPE, X_OBJECT_TYPE, FILE, OBJECT, DIR_TYPE, \
- FILE_TYPE, DEFAULT_UID, DEFAULT_GID, DIR_NON_OBJECT, DIR_OBJECT
+ FILE_TYPE, DEFAULT_UID, DEFAULT_GID, DIR_NON_OBJECT, DIR_OBJECT, \
+ X_ETAG, X_CONTENT_LENGTH
from ConfigParser import ConfigParser, NoSectionError, NoOptionError
# FIXME: Hopefully we'll be able to move to Python 2.7+ where O_CLOEXEC will
@@ -260,7 +261,8 @@ def _adjust_metadata(metadata):
# Fix up the metadata to ensure it has a proper value for the
# Content-Type metadata, as well as an X_TYPE and X_OBJECT_TYPE
# metadata values.
- content_type = metadata[X_CONTENT_TYPE]
+ content_type = metadata.get(X_CONTENT_TYPE, '')
+
if not content_type:
# FIXME: How can this be that our caller supplied us with metadata
# that has a content type that evaluates to False?
@@ -983,12 +985,39 @@ class DiskFile(object):
:raises DiskFileError: this implementation will raise the same
errors as the `create()` method.
"""
- # FIXME: we need to validate system metadata is preserved
- metadata = _adjust_metadata(metadata)
+ metadata = self._keep_sys_metadata(metadata)
data_file = os.path.join(self._put_datadir, self._obj)
self._threadpool.run_in_thread(
write_metadata, data_file, metadata)
+ def _keep_sys_metadata(self, metadata):
+ """
+ Make sure system metadata is not lost when writing new user metadata
+
+ This method will read the existing metadata and check for system
+ metadata. If there are any, it should be appended to the metadata obj
+ the user is trying to write.
+ """
+ orig_metadata = self.read_metadata()
+
+ sys_keys = [X_CONTENT_TYPE, X_ETAG, 'name', X_CONTENT_LENGTH,
+ X_OBJECT_TYPE, X_TYPE]
+
+ for key in sys_keys:
+ if key in orig_metadata:
+ metadata[key] = orig_metadata[key]
+
+ if X_OBJECT_TYPE not in orig_metadata:
+ if metadata[X_CONTENT_TYPE].lower() == DIR_TYPE:
+ metadata[X_OBJECT_TYPE] = DIR_OBJECT
+ else:
+ metadata[X_OBJECT_TYPE] = FILE
+
+ if X_TYPE not in orig_metadata:
+ metadata[X_TYPE] = OBJECT
+
+ return metadata
+
def _unlinkold(self):
if self._is_dir:
# Marker, or object, directory.