8
9
from charmhelpers import fetch
9
from charmhelpers.core import hookenv
10
from charmhelpers.core.host import mkdir
10
from charmhelpers.core import (hookenv, host)
11
11
from charmhelpers.payload import execd
13
13
SERVICE_NAME = 'jenkaas'
14
14
SERVICE_CONFIGNAME = 'jenkaas.conf'
15
DEPS_PKGES = ["daemon", "adduser", "psmisc", "default-jre"]
15
DEPS_PKGES = ["daemon", "adduser", "psmisc", "default-jre", "pwgen"]
17
17
config = hookenv.config()
41
41
plugins = glob.glob(os.path.join(charm_plugins_dir, '*.hpi'))
42
42
service_plugin_dir = os.path.join(_service_dir(), 'plugins')
43
43
if not os.path.exists(service_plugin_dir):
44
mkdir(service_plugin_dir, 'jenkins', 'jenkins', 0o755)
44
host.mkdir(service_plugin_dir, 'jenkins', 'jenkins', 0o755)
45
45
uid = pwd.getpwnam("jenkins").pw_uid
46
46
gid = grp.getgrnam("jenkins").gr_gid
47
47
for plugin in plugins:
56
56
fetch.apt_install(DEPS_PKGES, options=['--fix-broken', ], fatal=True)
59
def install_jenkins_config(service_name):
60
hookenv.log('Installing jenkins config')
61
in_config = os.path.join(hookenv.charm_dir(),
62
'files/templates/config.xml')
63
shutil.copy(in_config, _service_dir())
66
def configure_default_user(service_name):
67
hookenv.log('Configuring default user')
68
username = config['username']
69
password = config['password']
70
salt = subprocess.check_output(['pwgen', '-N1', '6']).strip()
71
csum = hashlib.sha256('{}{{{}}}'.format(password, salt)).hexdigest()
72
salty_password = '{}:{}'.format(salt, csum)
74
users_path = os.path.join(_service_dir(), 'users', username)
75
if not os.path.exists(users_path):
76
host.mkdir(users_path, 'jenkins', 'jenkins', 0o755)
78
in_config = os.path.join(hookenv.charm_dir(),
79
'files/templates/user/config.xml')
80
out_config = os.path.join(users_path, 'config.xml')
81
with open(in_config) as in_file, open(out_config, 'w') as out_file:
83
if '<fullName>' in line:
84
line = ' <fullName>{}</fullName>\n'.format(username)
85
if '<passwordHash>' in line:
86
line = ' <passwordHash>{}</passwordHash>\n'.format(
89
host.chownr(out_config, 'jenkins', 'jenkins')
90
os.chmod(out_config, 0o644)
59
93
def install_slaves(service_name):
60
94
hookenv.log('Installing slaves')
61
95
hookenv.log(hookenv.relations())