(self, params, **kwargs)
| 3057 | return clipboard_copy_parser |
| 3058 | |
| 3059 | def execute(self, params, **kwargs): |
| 3060 | record_name = kwargs['record'] if 'record' in kwargs else '' |
| 3061 | |
| 3062 | if not record_name: |
| 3063 | self.get_parser().print_help() |
| 3064 | return |
| 3065 | |
| 3066 | user_pattern = None |
| 3067 | if kwargs['username']: |
| 3068 | user_pattern = re.compile(kwargs['username'], re.IGNORECASE) |
| 3069 | |
| 3070 | record_uid = None |
| 3071 | if record_name in params.record_cache: |
| 3072 | record_uid = record_name |
| 3073 | else: |
| 3074 | rs = try_resolve_path(params, record_name) |
| 3075 | if rs is not None: |
| 3076 | folder, record_name = rs |
| 3077 | if folder is not None and record_name is not None: |
| 3078 | folder_uid = folder.uid or '' |
| 3079 | if folder_uid in params.subfolder_record_cache: |
| 3080 | for uid in params.subfolder_record_cache[folder_uid]: |
| 3081 | r = vault.KeeperRecord.load(params, uid) |
| 3082 | if not isinstance(r, (vault.PasswordRecord, vault.TypedRecord)): |
| 3083 | continue |
| 3084 | if r.title.lower() == record_name.lower(): |
| 3085 | if user_pattern: |
| 3086 | login = '' |
| 3087 | if isinstance(r, vault.PasswordRecord): |
| 3088 | login = r.login |
| 3089 | elif isinstance(r, vault.TypedRecord): |
| 3090 | login_field = r.get_typed_field('login') |
| 3091 | if login_field is None: |
| 3092 | login_field = r.get_typed_field('email') |
| 3093 | if login_field: |
| 3094 | login = login_field.get_default_value(str) |
| 3095 | if not login: |
| 3096 | continue |
| 3097 | if not user_pattern.match(login): |
| 3098 | continue |
| 3099 | record_uid = uid |
| 3100 | break |
| 3101 | |
| 3102 | if record_uid is None: |
| 3103 | records = [] # type: List[vault.KeeperRecord] |
| 3104 | for r in vault_extensions.find_records(params, record_name, use_regex=True): |
| 3105 | if isinstance(r, (vault.PasswordRecord, vault.TypedRecord)): |
| 3106 | if user_pattern: |
| 3107 | login = '' |
| 3108 | if isinstance(r, vault.PasswordRecord): |
| 3109 | login = r.login |
| 3110 | elif isinstance(r, vault.TypedRecord): |
| 3111 | login_field = r.get_typed_field('login') |
| 3112 | if login_field is None: |
| 3113 | login_field = r.get_typed_field('email') |
| 3114 | if login_field: |
| 3115 | login = login_field.get_default_value(str) |
| 3116 | if not login: |
no test coverage detected