~ubuntuone-hackers/capomastro/trunk

« back to all changes in this revision

Viewing changes to credentials/admin.py

"Password encryption for swift credentials.
This includes decryption when accessing an archive, encryption when creating credentials in the admin, updates to the command-line tool to create credentials (which are also encrypted), an encryption key generator to be used when configuring (and friendly messages if the key is not configured), and copious tests. [r=roadmr,codersquid,caio1982][bug=][author=roadmr]"

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
from django.conf import settings
4
4
 
5
5
from credentials.models import SshKeyPair, SwiftCredential
 
6
from credentials.encryption_helper import (
 
7
    encrypt,
 
8
    NO_PASSWORD_ENCRYPTION_KEY_ERROR)
6
9
 
7
10
 
8
11
class SwiftCredentialAdminForm(forms.ModelForm):
40
43
        elif self.instance.password and not cleaned_data['password']:
41
44
            return self.instance.password
42
45
        else:
43
 
            return cleaned_data['password']
 
46
            if not hasattr(settings, 'PASSWORD_ENCRYPTION_KEY'):
 
47
                err = NO_PASSWORD_ENCRYPTION_KEY_ERROR
 
48
                raise forms.ValidationError(err)
 
49
            return encrypt(cleaned_data['password'],
 
50
                           settings.PASSWORD_ENCRYPTION_KEY)
 
51
 
44
52
 
45
53
class SwiftCredentialAdmin(admin.ModelAdmin):
46
54
    list_display = ('label', 'auth_url', 'username',