本文整理汇总了Python中nova.api.ec2.ec2utils.is_ec2_timestamp_expired函数的典型用法代码示例。如果您正苦于以下问题:Python is_ec2_timestamp_expired函数的具体用法?Python is_ec2_timestamp_expired怎么用?Python is_ec2_timestamp_expired使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了is_ec2_timestamp_expired函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_validate_ec2_timestamp_advanced_time
def test_validate_ec2_timestamp_advanced_time(self):
# EC2 request with Timestamp in advanced time
timestamp = timeutils.utcnow() + datetime.timedelta(seconds=250)
params = {"Timestamp": timeutils.strtime(timestamp, "%Y-%m-%dT%H:%M:%SZ")}
expired = ec2utils.is_ec2_timestamp_expired(params, expires=300)
self.assertFalse(expired)
示例2: test_validate_ec2_timestamp_advanced_time
def test_validate_ec2_timestamp_advanced_time(self):
# EC2 request with Timestamp in advanced time
timestamp = timeutils.utcnow() + datetime.timedelta(seconds=250)
params = {'Timestamp': utils.isotime(timestamp)}
expired = ec2utils.is_ec2_timestamp_expired(params, expires=300)
self.assertFalse(expired)
示例3: __call__
def __call__(self, req):
non_args = ['Action', 'Signature', 'AWSAccessKeyId', 'SignatureMethod',
'SignatureVersion', 'Version', 'Timestamp']
args = dict(req.params)
try:
expired = ec2utils.is_ec2_timestamp_expired(req.params,
expires=CONF.ec2_timestamp_expiry)
if expired:
msg = _("Timestamp failed validation.")
LOG.exception(msg)
raise webob.exc.HTTPForbidden(detail=msg)
# Raise KeyError if omitted
action = req.params['Action']
# Fix bug lp:720157 for older (version 1) clients
version = req.params['SignatureVersion']
if int(version) == 1:
non_args.remove('SignatureMethod')
if 'SignatureMethod' in args:
args.pop('SignatureMethod')
for non_arg in non_args:
# Remove, but raise KeyError if omitted
args.pop(non_arg)
except KeyError, e:
raise webob.exc.HTTPBadRequest()
示例4: __call__
def __call__(self, req):
# Not all arguments are mandatory with v4 signatures, as some data is
# passed in the header, not query arguments.
required_args = ["Action", "Version"]
non_args = [
"Action",
"Signature",
"AWSAccessKeyId",
"SignatureMethod",
"SignatureVersion",
"Version",
"Timestamp",
]
args = dict(req.params)
try:
expired = ec2utils.is_ec2_timestamp_expired(req.params, expires=CONF.ec2_timestamp_expiry)
if expired:
msg = _("Timestamp failed validation.")
LOG.debug("Timestamp failed validation")
raise webob.exc.HTTPForbidden(explanation=msg)
# Raise KeyError if omitted
action = req.params["Action"]
# Fix bug lp:720157 for older (version 1) clients
# If not present assume v4
version = req.params.get("SignatureVersion", 4)
if int(version) == 1:
non_args.remove("SignatureMethod")
if "SignatureMethod" in args:
args.pop("SignatureMethod")
for non_arg in non_args:
if non_arg in required_args:
# Remove, but raise KeyError if omitted
args.pop(non_arg)
else:
args.pop(non_arg, None)
except KeyError:
raise webob.exc.HTTPBadRequest()
except exception.InvalidRequest as err:
raise webob.exc.HTTPBadRequest(explanation=six.text_type(err))
LOG.debug("action: %s", action)
for key, value in args.items():
LOG.debug("arg: %(key)s\t\tval: %(value)s", {"key": key, "value": value})
# Success!
api_request = apirequest.APIRequest(self.controller, action, req.params["Version"], args)
req.environ["ec2.request"] = api_request
return self.application
示例5: __call__
def __call__(self, req):
non_args = [
"Action",
"Signature",
"AWSAccessKeyId",
"SignatureMethod",
"SignatureVersion",
"Version",
"Timestamp",
]
args = dict(req.params)
try:
expired = ec2utils.is_ec2_timestamp_expired(req.params, expires=CONF.ec2_timestamp_expiry)
if expired:
msg = _("Timestamp failed validation.")
LOG.exception(msg)
raise webob.exc.HTTPForbidden(detail=msg)
# Raise KeyError if omitted
action = req.params["Action"]
# Fix bug lp:720157 for older (version 1) clients
version = req.params["SignatureVersion"]
if int(version) == 1:
non_args.remove("SignatureMethod")
if "SignatureMethod" in args:
args.pop("SignatureMethod")
for non_arg in non_args:
# Remove, but raise KeyError if omitted
args.pop(non_arg)
except KeyError:
raise webob.exc.HTTPBadRequest()
except exception.InvalidRequest as err:
raise webob.exc.HTTPBadRequest(explanation=unicode(err))
LOG.debug(_("action: %s"), action)
for key, value in args.items():
LOG.debug(_("arg: %(key)s\t\tval: %(value)s"), {"key": key, "value": value})
# Success!
api_request = apirequest.APIRequest(self.controller, action, req.params["Version"], args)
req.environ["ec2.request"] = api_request
return self.application
示例6: __call__
def __call__(self, req):
non_args = ['Action', 'Signature', 'AWSAccessKeyId', 'SignatureMethod',
'SignatureVersion', 'Version', 'Timestamp']
args = dict(req.params)
try:
expired = ec2utils.is_ec2_timestamp_expired(req.params,
expires=CONF.ec2_timestamp_expiry)
if expired:
msg = _("Timestamp failed validation.")
LOG.debug("Timestamp failed validation")
raise webob.exc.HTTPForbidden(explanation=msg)
# Raise KeyError if omitted
action = req.params['Action']
# Fix bug lp:720157 for older (version 1) clients
version = req.params['SignatureVersion']
if int(version) == 1:
non_args.remove('SignatureMethod')
if 'SignatureMethod' in args:
args.pop('SignatureMethod')
for non_arg in non_args:
# Remove, but raise KeyError if omitted
args.pop(non_arg)
except KeyError:
raise webob.exc.HTTPBadRequest()
except exception.InvalidRequest as err:
raise webob.exc.HTTPBadRequest(explanation=six.text_type(err))
LOG.debug('action: %s', action)
for key, value in args.items():
LOG.debug('arg: %(key)s\t\tval: %(value)s',
{'key': key, 'value': value})
# Success!
api_request = apirequest.APIRequest(self.controller, action,
req.params['Version'], args)
req.environ['ec2.request'] = api_request
return self.application
示例7: test_validate_ec2_req_not_expired
def test_validate_ec2_req_not_expired(self):
expire = timeutils.utcnow() + datetime.timedelta(seconds=350)
params = {'Expires': utils.isotime(expire)}
expired = ec2utils.is_ec2_timestamp_expired(params)
self.assertFalse(expired)
示例8: test_validate_Expires_timestamp_invalid_format
def test_validate_Expires_timestamp_invalid_format(self):
# EC2 request with invalid Expires
params = {'Expires': '2011-04-22T11:29:49'}
expired = ec2utils.is_ec2_timestamp_expired(params)
self.assertTrue(expired)
示例9: test_validate_ec2_req_timestamp_expired
def test_validate_ec2_req_timestamp_expired(self):
params = {'Timestamp': '2011-04-22T12:00:00Z'}
compare = ec2utils.is_ec2_timestamp_expired(params, expires=300)
self.assertTrue(compare)
示例10: test_validate_ec2_req_expired
def test_validate_ec2_req_expired(self):
params = {'Expires': utils.isotime()}
expired = ec2utils.is_ec2_timestamp_expired(params)
self.assertTrue(expired)
示例11: test_validate_ec2_timestamp_advanced_time_expired
def test_validate_ec2_timestamp_advanced_time_expired(self):
timestamp = timeutils.utcnow() + datetime.timedelta(seconds=350)
params = {'Timestamp': utils.isotime(timestamp)}
expired = ec2utils.is_ec2_timestamp_expired(params, expires=300)
self.assertTrue(expired)
示例12: test_validate_ec2_req_timestamp_not_expired
def test_validate_ec2_req_timestamp_not_expired(self):
params = {'Timestamp': utils.isotime()}
expired = ec2utils.is_ec2_timestamp_expired(params, expires=15)
self.assertFalse(expired)
示例13: test_validate_ec2_timestamp_invalid_format
def test_validate_ec2_timestamp_invalid_format(self):
params = {'Timestamp': '2011-04-22T11:29:49.000P'}
expired = ec2utils.is_ec2_timestamp_expired(params)
self.assertTrue(expired)
示例14: test_validate_ec2_timestamp_old_format
def test_validate_ec2_timestamp_old_format(self):
params = {"Timestamp": "2011-04-22T11:29:49"}
expired = ec2utils.is_ec2_timestamp_expired(params)
self.assertTrue(expired)
示例15: test_validate_ec2_timestamp_aws_sdk_format
def test_validate_ec2_timestamp_aws_sdk_format(self):
params = {'Timestamp': '2011-04-22T11:29:49.123Z'}
expired = ec2utils.is_ec2_timestamp_expired(params)
self.assertFalse(expired)
expired = ec2utils.is_ec2_timestamp_expired(params, expires=300)
self.assertTrue(expired)