-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/cliff' into develop
- Loading branch information
Showing
73 changed files
with
3,514 additions
and
526 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[run] | ||
branch = True | ||
include = serverauditor_sshconfig/**.py | ||
|
||
[report] | ||
precision = 2 | ||
show_missing = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
*~ | ||
\#* | ||
.DS_Store | ||
|
||
.idea | ||
.tox | ||
.coverage | ||
|
||
*.pyc | ||
*.pyo | ||
dist | ||
*.egg-info | ||
/build | ||
.ropeproject |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[nosetests] | ||
with-coverage=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
inherits: | ||
- strictness_veryhigh | ||
- full_pep8 | ||
- doc_warnings | ||
|
||
ignore-paths: | ||
- .git | ||
|
||
pylint: | ||
options: | ||
max-parents: 12 | ||
disable: | ||
# - broad-except | ||
# - pointless-except | ||
# - bad-super-call | ||
# - nonstandard-exception |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
#!/bin/sh | ||
tar_url='https://github.com/EvgeneOskin/serverauditor-sshconfig/archive/feature/cliff.tar.gz' | ||
|
||
command_exists() { | ||
command -v "$@" > /dev/null 2>&1 | ||
} | ||
|
||
eval_sh_c() { | ||
user="$(id -un 2>/dev/null || true)" | ||
|
||
_sh_c='sh -c' | ||
if [ "$user" != 'root' ]; then | ||
if command_exists sudo; then | ||
_sh_c='sudo -E sh -c' | ||
elif command_exists su; then | ||
_sh_c='su -c' | ||
else | ||
cat >&2 <<-'EOF' | ||
Error: this installer needs the ability to run commands as root. | ||
We are unable to find either "sudo" or "su" available to make this happen. | ||
EOF | ||
exit 1 | ||
fi | ||
fi | ||
echo $_sh_c | ||
} | ||
|
||
do_install() { | ||
sh_c=$(eval_sh_c) | ||
curl='' | ||
if command_exists curl; then | ||
curl='curl -sSL' | ||
elif command_exists wget; then | ||
curl='wget -qO-' | ||
elif command_exists busybox && busybox --list-modules | grep -q wget; then | ||
curl='busybox wget -qO-' | ||
fi | ||
|
||
requirements='python' | ||
|
||
lsb_dist='' | ||
if command_exists lsb_release; then | ||
lsb_dist="$(lsb_release -si)" | ||
fi | ||
if [ -z "$lsb_dist" ] && [ -r /etc/lsb-release ]; then | ||
lsb_dist="$(. /etc/lsb-release && echo "$DISTRIB_ID")" | ||
fi | ||
if [ -z "$lsb_dist" ] && [ -r /etc/debian_version ]; then | ||
lsb_dist='debian' | ||
fi | ||
if [ -z "$lsb_dist" ] && [ -r /etc/fedora-release ]; then | ||
lsb_dist='fedora' | ||
fi | ||
if [ -z "$lsb_dist" ] && [ -r /etc/os-release ]; then | ||
lsb_dist="$(. /etc/os-release && echo "$ID")" | ||
fi | ||
|
||
lsb_dist="$(echo "$lsb_dist" | tr '[:upper:]' '[:lower:]')" | ||
|
||
case "$lsb_dist" in | ||
amzn|fedora|centos) | ||
( | ||
set -x | ||
$sh_c "sleep 3; yum -y -q install $requirements" | ||
) | ||
;; | ||
|
||
'opensuse project'|opensuse|'suse linux'|sled) | ||
( | ||
set -x | ||
$sh_c "sleep 3; zypper -n install $requirements" | ||
) | ||
;; | ||
|
||
ubuntu|debian|linuxmint|'elementary os'|kali) | ||
export DEBIAN_FRONTEND=noninteractive | ||
|
||
if [ -z "$curl" ]; then | ||
apt_get_update | ||
( set -x; $sh_c 'sleep 3; apt-get install -y -q curl ca-certificates' ) | ||
curl='curl -sSL' | ||
fi | ||
|
||
did_apt_get_update= | ||
apt_get_update() { | ||
if [ -z "$did_apt_get_update" ]; then | ||
( set -x; $sh_c 'sleep 3; apt-get update' ) | ||
did_apt_get_update=1 | ||
fi | ||
} | ||
|
||
|
||
apt_get_update | ||
( | ||
set -x | ||
$sh_c "sleep 3; apt-get install -y -q $requirements" | ||
) | ||
;; | ||
esac | ||
|
||
if !(command_exists easy_install); then | ||
$sh_c "$curl https://bootstrap.pypa.io/ez_setup.py | python" | ||
fi | ||
easy_install -U $tar_url | ||
|
||
if command_exists serverauditor; then | ||
( | ||
set -x | ||
serverauditor --version | ||
) || true | ||
fi | ||
exit 0 | ||
} | ||
|
||
do_install |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# coding: utf-8 | ||
""" | ||
Copyright (c) 2013 Crystalnix. | ||
License BSD, see LICENSE for more details. | ||
""" | ||
import six | ||
from getpass import getpass | ||
from ..core.commands import AbstractCommand | ||
from .managers import AccountManager | ||
|
||
|
||
class BaseAccountCommand(AbstractCommand): | ||
|
||
def __init__(self, app, app_args, cmd_name=None): | ||
super(BaseAccountCommand, self).__init__(app, app_args, cmd_name) | ||
self.manager = AccountManager(self.config) | ||
|
||
|
||
class LoginCommand(BaseAccountCommand): | ||
|
||
"""Sign into serverauditor cloud.""" | ||
|
||
def prompt_username(self): | ||
return six.moves.input("Serverauditor's username: ") | ||
|
||
def get_parser(self, prog_name): | ||
parser = super(LoginCommand, self).get_parser(prog_name) | ||
parser.add_argument('-u', '--username', metavar='USERNAME') | ||
parser.add_argument('-p', '--password', metavar='PASSWORD') | ||
parser.add_argument('--sync-sshconfig', action='store_true') | ||
return parser | ||
|
||
def take_action(self, parsed_args): | ||
username = parsed_args.username or self.prompt_username() | ||
password = parsed_args.password or self.prompt_password() | ||
self.manager.login(username, password) | ||
self.log.info('Sign into serverauditor cloud.') | ||
|
||
|
||
class LogoutCommand(BaseAccountCommand): | ||
|
||
"""Sign out serverauditor cloud.""" | ||
|
||
def get_parser(self, prog_name): | ||
parser = super(LogoutCommand, self).get_parser(prog_name) | ||
parser.add_argument('--clear-sshconfig', action='store_true') | ||
return parser | ||
|
||
def take_action(self, parsed_args): | ||
self.manager.logout() | ||
self.log.info('Sign out serverauditor cloud.') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# coding: utf-8 | ||
|
||
""" | ||
Copyright (c) 2013 Crystalnix. | ||
License BSD, see LICENSE for more details. | ||
""" | ||
|
||
from ..core.api import API | ||
|
||
|
||
class AccountManager(object): | ||
|
||
def __init__(self, config): | ||
self.config = config | ||
self.api = API() | ||
|
||
def login(self, username, password): | ||
response = self.api.login(username, password) | ||
self.config.set('User', 'username', username) | ||
apikey = response['key'] | ||
self.config.set('User', 'apikey', apikey) | ||
hmac_salt = response['hmac_salt'] | ||
self.config.set('User', 'hmac_salt', hmac_salt) | ||
salt = response['salt'] | ||
self.config.set('User', 'salt', salt) | ||
self.config.write() | ||
|
||
def logout(self): | ||
self.config.remove_section('User') | ||
self.config.write() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# coding: utf-8 | ||
import logging | ||
from cliff.app import App | ||
from cliff.commandmanager import CommandManager | ||
|
||
from . import __version__ | ||
|
||
|
||
def get_version(): | ||
return '.'.join(map(str, __version__)) | ||
|
||
|
||
class ServerauditorApp(App): | ||
|
||
def __init__(self): | ||
super(ServerauditorApp, self).__init__( | ||
description='Serverauditor app', | ||
version=get_version(), | ||
command_manager=CommandManager('serverauditor.handlers'), | ||
) | ||
|
||
def configure_logging(self): | ||
super(ServerauditorApp, self).configure_logging() | ||
logging.getLogger('requests').setLevel(logging.WARNING) | ||
return |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from ...core.commands import AbstractCommand | ||
|
||
from .host import HostCommand, HostsCommand | ||
from .group import GroupCommand, GroupsCommand | ||
from .snippet import SnippetCommand, SnippetsCommand | ||
from .pf_rule import PFRuleCommand, PFRulesCommand | ||
from .ssh_identity import SshIdentityCommand, SshIdentitiesCommand | ||
from .tag import TagsCommand | ||
from .sync import PushCommand, PullCommand | ||
|
||
|
||
class InfoCommand(AbstractCommand): | ||
|
||
"""Show info about host or group.""" | ||
|
||
def get_parser(self, prog_name): | ||
parser = super(InfoCommand, self).get_parser(prog_name) | ||
parser.add_argument( | ||
'-G', '--group', dest='entry_type', | ||
action='store_const', const='group', | ||
help='Show info about group.' | ||
) | ||
parser.add_argument( | ||
'-H', '--host', dest='entry_type', | ||
action='store_const', const='host', | ||
help='Show info about host.' | ||
) | ||
parser.add_argument( | ||
'-M', '--no-merge', action='store_true', | ||
help='Do not merge configs.' | ||
) | ||
parser.add_argument( | ||
'--ssh', action='store_true', | ||
help='Show info in ssh_config format' | ||
) | ||
parser.add_argument('id_or_name', metavar='ID or NAME') | ||
return parser | ||
|
||
def take_action(self, parsed_args): | ||
self.log.info('Info about group or host.') | ||
assert False, 'Not implemented' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
from operator import attrgetter | ||
from ...core.exceptions import ( | ||
InvalidArgumentException, TooManyEntriesException, DoesNotExistException, | ||
) | ||
from ...core.commands import DetailCommand, ListCommand | ||
from ..models import Group, SshConfig, SshIdentity | ||
from .ssh_config import SshConfigArgs | ||
|
||
|
||
class GroupCommand(DetailCommand): | ||
|
||
"""Operate with Group object.""" | ||
|
||
allowed_operations = DetailCommand.all_operations | ||
model_class = Group | ||
|
||
def get_parser(self, prog_name): | ||
parser = super(GroupCommand, self).get_parser(prog_name) | ||
parser.add_argument( | ||
'--generate-key', action='store_true', | ||
help='Create and assign automatically a identity file for group.' | ||
) | ||
parser.add_argument( | ||
'--ssh', help='Options in ssh_config format.' | ||
) | ||
parser.add_argument( | ||
'-g', '--parent-group', | ||
metavar='PARENT_GROUP', help="Parent group's id or name." | ||
) | ||
|
||
ssh_config_args = SshConfigArgs() | ||
ssh_config_args.add_agrs(parser) | ||
return parser | ||
|
||
def create(self, parsed_args): | ||
self.create_instance(parsed_args) | ||
|
||
def serialize_args(self, args, instance=None): | ||
if instance: | ||
ssh_identity = (instance.ssh_config and instance.ssh_config.ssh_identity) or SshIdentity() | ||
ssh_config = instance.ssh_config or SshConfig() | ||
group = instance | ||
else: | ||
group, ssh_config, ssh_identity = Group(), SshConfig(), SshIdentity() | ||
|
||
if args.generate_key: | ||
raise NotImplementedError('Not implemented') | ||
if args.parent_group: | ||
raise NotImplementedError('Not implemented') | ||
if args.ssh_identity: | ||
raise NotImplementedError('Not implemented') | ||
|
||
ssh_identity.username = args.username | ||
ssh_identity.password = args.password | ||
|
||
ssh_config.port = args.port | ||
ssh_config.ssh_identity = ssh_identity | ||
|
||
group.label = args.label | ||
group.ssh_config = ssh_config | ||
return group | ||
|
||
|
||
class GroupsCommand(ListCommand): | ||
|
||
"""Manage group objects.""" | ||
|
||
def get_parser(self, prog_name): | ||
parser = super(GroupsCommand, self).get_parser(prog_name) | ||
parser.add_argument( | ||
'-r', '--recursive', action='store_true', | ||
help=('List groups of current group ' | ||
'(default is current group) recursively.') | ||
) | ||
parser.add_argument( | ||
'group', nargs='?', metavar='GROUP_ID or GROUP_NAME', | ||
help='List groups in this group.' | ||
) | ||
return parser | ||
|
||
def take_action(self, parsed_args): | ||
groups = self.storage.get_all(Group) | ||
fields = Group.allowed_fields() | ||
getter = attrgetter(*fields) | ||
return fields, [getter(i) for i in groups] |
Oops, something went wrong.