Skip to content

Commit

Permalink
fix(middleawre/iscsi): do not allow duplicate tags for iSCCI Auth
Browse files Browse the repository at this point in the history
Ticket:	#80085
  • Loading branch information
william-gr committed Mar 13, 2019
1 parent 33aa836 commit 13a1206
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/middlewared/middlewared/plugins/iscsi.py
Expand Up @@ -367,7 +367,7 @@ class Config:

@accepts(Dict(
'iscsi_auth_create',
Int('tag'),
Int('tag', required=True),
Str('user', required=True),
Str('secret', required=True),
Str('peeruser'),
Expand Down Expand Up @@ -399,15 +399,13 @@ async def do_create(self, data):
)
)
async def do_update(self, id, data):
verrors = ValidationErrors()
old = await self._get_instance(id)

new = old.copy()
new.update(data)

await self.validate(
new, 'iscsi_auth_update', verrors
)
verrors = ValidationErrors()
await self.validate(new, 'iscsi_auth_update', verrors, old)

if verrors:
raise verrors
Expand All @@ -428,7 +426,15 @@ async def do_delete(self, id):
)

@private
async def validate(self, data, schema_name, verrors):
async def validate(self, data, schema_name, verrors, old=None):

filters = [('tag', '=', data['tag'])]
if old:
filters.append(('id', '!=', old['id']))

if await self.middleware.call('iscsi.auth.query', filters):
verrors.add(f'{schema_name}.tag', f'Tag {data["tag"]!r} is already in use.')

secret = data.get('secret')
peer_secret = data.get('peersecret')
peer_user = data.get('peeruser', '')
Expand Down

0 comments on commit 13a1206

Please sign in to comment.