Jakub Josef | e01cf3c | 2017-03-16 13:27:16 +0100 | [diff] [blame] | 1 | import logging |
| 2 | logger = logging.getLogger(__name__) |
| 3 | |
| 4 | set_theme_groovy = """\ |
| 5 | try{{ |
| 6 | if(Class.forName("org.codefirst.SimpleThemeDecorator")){{ |
| 7 | def state; |
| 8 | for (pd in PageDecorator.all()) {{ |
| 9 | if (pd instanceof org.codefirst.SimpleThemeDecorator) {{ |
| 10 | if(!pd.cssUrl.equals("{css_url}") || !pd.jsUrl.equals("{js_url}")){{ |
| 11 | pd.cssUrl = "{css_url}" |
| 12 | pd.jsUrl = "{js_url}" |
| 13 | state="SUCCESS" |
| 14 | }}else{{ |
| 15 | state="EXISTS" |
| 16 | }} |
| 17 | }} |
| 18 | }} |
| 19 | print(state) |
| 20 | }} |
| 21 | }}catch(ClassNotFoundException e){{ |
| 22 | print("Cannot user SimpleThemeDecorator, maybe Simple Theme Plugin not installed") |
| 23 | }} |
| 24 | """ # noqa |
| 25 | |
| 26 | def config(name, css_url, js_url): |
| 27 | """ |
| 28 | Jenkins theme config state method |
| 29 | |
| 30 | :param name: configuration name |
| 31 | :param css_url: URL to theme CSS |
| 32 | :param js_url: URL to theme JS |
| 33 | :returns: salt-specified state dict |
| 34 | """ |
| 35 | test = __opts__['test'] # noqa |
| 36 | ret = { |
| 37 | 'name': name, |
| 38 | 'changes': {}, |
| 39 | 'result': False, |
| 40 | 'comment': '', |
| 41 | } |
| 42 | result = False |
| 43 | if test: |
| 44 | status = "SUCCESS" |
| 45 | ret['changes'][name] = status |
| 46 | ret['comment'] = 'Jenkins Theme config %s %s' % (name, status.lower()) |
| 47 | else: |
| 48 | call_result = __salt__['jenkins_common.call_groovy_script']( |
| 49 | set_theme_groovy, {"css_url": css_url, "js_url": js_url}) |
| 50 | if call_result["code"] == 200 and call_result["msg"] in ["SUCCESS", "EXISTS"]: |
| 51 | status = call_result["msg"] |
| 52 | if status == "SUCCESS": |
| 53 | ret['changes'][name] = status |
| 54 | ret['comment'] = 'Jenkins theme config %s %s' % (name, status.lower()) |
| 55 | result = True |
| 56 | else: |
| 57 | status = 'FAILED' |
| 58 | logger.error( |
| 59 | "Jenkins theme API call failure: %s", call_result["msg"]) |
| 60 | ret['comment'] = 'Jenkins theme API call failure: %s' % (call_result[ |
| 61 | "msg"]) |
| 62 | ret['result'] = None if test else result |
| 63 | return ret |