Returns the API key of the current logged-in user.
()
| 18 | |
| 19 | |
| 20 | def get_api_key(): |
| 21 | '''Returns the API key of the current logged-in user.''' |
| 22 | shodan_dir = os.path.expanduser(SHODAN_CONFIG_DIR) |
| 23 | keyfile = shodan_dir + '/api_key' |
| 24 | |
| 25 | # If the file doesn't yet exist let the user know that they need to |
| 26 | # initialize the shodan cli |
| 27 | if not os.path.exists(keyfile): |
| 28 | raise click.ClickException('Please run "shodan init <api key>" before using this command') |
| 29 | |
| 30 | # Make sure it is a read-only file |
| 31 | if not oct(os.stat(keyfile).st_mode).endswith("600"): |
| 32 | os.chmod(keyfile, 0o600) |
| 33 | |
| 34 | with open(keyfile, 'r') as fin: |
| 35 | return fin.read().strip() |
| 36 | |
| 37 | |
| 38 | def escape_data(args): |
no outgoing calls
no test coverage detected