(self, params, **kwargs)
| 3134 | return clipboard_copy_parser |
| 3135 | |
| 3136 | def execute(self, params, **kwargs): |
| 3137 | record_name = kwargs['record'] if 'record' in kwargs else '' |
| 3138 | |
| 3139 | if not record_name: |
| 3140 | self.get_parser().print_help() |
| 3141 | return |
| 3142 | |
| 3143 | user_pattern = None |
| 3144 | if kwargs['username']: |
| 3145 | user_pattern = re.compile(kwargs['username'], re.IGNORECASE) |
| 3146 | |
| 3147 | record_uid = None |
| 3148 | if record_name in params.record_cache: |
| 3149 | record_uid = record_name |
| 3150 | else: |
| 3151 | rs = try_resolve_path(params, record_name) |
| 3152 | if rs is not None: |
| 3153 | folder, record_name = rs |
| 3154 | if folder is not None and record_name is not None: |
| 3155 | folder_uid = folder.uid or '' |
| 3156 | if folder_uid in params.subfolder_record_cache: |
| 3157 | for uid in params.subfolder_record_cache[folder_uid]: |
| 3158 | r = vault.KeeperRecord.load(params, uid) |
| 3159 | if not isinstance(r, (vault.PasswordRecord, vault.TypedRecord)): |
| 3160 | continue |
| 3161 | if r.title.lower() == record_name.lower(): |
| 3162 | if user_pattern: |
| 3163 | login = '' |
| 3164 | if isinstance(r, vault.PasswordRecord): |
| 3165 | login = r.login |
| 3166 | elif isinstance(r, vault.TypedRecord): |
| 3167 | login_field = r.get_typed_field('login') |
| 3168 | if login_field is None: |
| 3169 | login_field = r.get_typed_field('email') |
| 3170 | if login_field: |
| 3171 | login = login_field.get_default_value(str) |
| 3172 | if not login: |
| 3173 | continue |
| 3174 | if not user_pattern.match(login): |
| 3175 | continue |
| 3176 | record_uid = uid |
| 3177 | break |
| 3178 | |
| 3179 | if record_uid is None: |
| 3180 | records = [] # type: List[vault.KeeperRecord] |
| 3181 | for r in vault_extensions.find_records(params, record_name, use_regex=True): |
| 3182 | if isinstance(r, (vault.PasswordRecord, vault.TypedRecord)): |
| 3183 | if user_pattern: |
| 3184 | login = '' |
| 3185 | if isinstance(r, vault.PasswordRecord): |
| 3186 | login = r.login |
| 3187 | elif isinstance(r, vault.TypedRecord): |
| 3188 | login_field = r.get_typed_field('login') |
| 3189 | if login_field is None: |
| 3190 | login_field = r.get_typed_field('email') |
| 3191 | if login_field: |
| 3192 | login = login_field.get_default_value(str) |
| 3193 | if not login: |
no test coverage detected