Skip to content
This repository has been archived by the owner on Jul 1, 2020. It is now read-only.

Commit

Permalink
item_download: Fix types of attribute defaults
Browse files Browse the repository at this point in the history
With bw 3.7, the type of an attribute's default matters a great deal.
You can't just use random stuff that evaluates to a boolean "False"
anymore (and IMHO that shouldn't have been done in the first place).

Also unify/clarify the ".get()" calls. There is no need for them, since
we validate attributes in "validate_attributes()". Nor is there a need
to introduce new types (i.e., "None") via ".get()".
  • Loading branch information
phosei committed Oct 8, 2019
1 parent 3e2b686 commit 472ce41
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions index.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"item_download": {
"checksum": "367aa0f86cb68d42d77f340da74d803368213f90",
"checksum": "084d801a07e7d5a888a3859ecbf6e64cd7e03629",
"desc": "Download a file from a webserver and verifies its Hash",
"version": 3
"version": 4
},
"item_git_deploy": {
"checksum": "63ee7962325d88ce8bc056d6bb3fde9ab7104074",
Expand Down
14 changes: 7 additions & 7 deletions item_download/items/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class Download(Item):
"pkg_zypper:",
]
ITEM_ATTRIBUTES = {
'url': {},
'sha256': {},
'url': "",
'sha256': "",
'verifySSL': True,
}
ITEM_TYPE_NAME = "download"
Expand Down Expand Up @@ -54,13 +54,13 @@ def fix(self, status):
self.node.run("curl -L {verify}-s -o {file} -- {url}".format(
verify="" if self.attributes.get('verifySSL', True) else "-k ",
file=quote(self.name),
url=quote(self.attributes.get('url'))
url=quote(self.attributes['url'])
))

# check hash
sha256 = self.__hash_remote_file(self.name)

if sha256 != self.attributes.get('sha256'):
if sha256 != self.attributes['sha256']:
# unlink file
self.node.run("rm -rf -- {}".format(quote(self.name)))

Expand All @@ -70,7 +70,7 @@ def cdict(self):
"""This is how the world should be"""
cdict = {
'type': 'download',
'sha256': self.attributes.get('sha256'),
'sha256': self.attributes['sha256'],
}

return cdict
Expand All @@ -90,15 +90,15 @@ def sdict(self):

@classmethod
def validate_attributes(cls, bundle, item_id, attributes):
if not attributes.get('sha256', None):
if 'sha256' not in attributes:
raise BundleError(_(
"at least one hash must be set on {item} in bundle '{bundle}'"
).format(
bundle=bundle.name,
item=item_id,
))

if not attributes.get('url', None):
if 'url' not in attributes:
raise BundleError(_(
"you need to specify the url on {item} in bundle '{bundle}'"
).format(
Expand Down
2 changes: 1 addition & 1 deletion item_download/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"provides": [
"items/download.py"
],
"version": 3
"version": 4
}

0 comments on commit 472ce41

Please sign in to comment.