Merge branch 'devops19_47226' into 'devops19'
* Finish task#47226 See merge request easycorp/zentaopms!1351
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
$config->sonarqube = new stdclass();
|
||||
|
||||
$config->sonarqube->create = new stdclass();
|
||||
$config->sonarqube->create->requiredFields = 'name,url,account,password';
|
||||
@@ -48,4 +48,52 @@ class sonarqube extends control
|
||||
|
||||
$this->display();
|
||||
}
|
||||
|
||||
/**
|
||||
* create a sonarqube.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
if($_POST)
|
||||
{
|
||||
$this->checkToken();
|
||||
$sonarqubeID = $this->loadModel('pipeline')->create('sonarqube');
|
||||
|
||||
if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
|
||||
$this->loadModel('action');
|
||||
$actionID = $this->action->create('sonarqube', $sonarqubeID, 'created');
|
||||
return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browse')));
|
||||
}
|
||||
|
||||
$this->view->title = $this->lang->sonarqube->common . $this->lang->colon . $this->lang->sonarqube->createServer;
|
||||
|
||||
$this->display();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check post info.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function checkToken()
|
||||
{
|
||||
$sonarqube = fixer::input('post')->get();
|
||||
$this->dao->update('sonarqube')->data($sonarqube)->batchCheck($this->config->sonarqube->create->requiredFields, 'notempty');
|
||||
if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
|
||||
if(strpos($sonarqube->url, 'http') !== 0) return $this->send(array('result' => 'fail', 'message' => array('url' => array($this->lang->sonarqube->hostError))));
|
||||
|
||||
/* Check name and url unique. */
|
||||
$isExist = $this->dao->select('*')->from(TABLE_PIPELINE)->where("name='{$sonarqube->name}' or url='{$sonarqube->url}'")->fetch();
|
||||
if($isExist) return $this->send(array('result' => 'fail', 'message' => $this->lang->sonarqube->repeatError));
|
||||
|
||||
$token = base64_encode("{$sonarqube->account}:{$sonarqube->password}");
|
||||
$result = $this->sonarqube->apiValidate($sonarqube->url, $token);
|
||||
|
||||
if(!isset($result->valid) or !$result->valid) return $this->send(array('result' => 'fail', 'message' => array('token' => array($this->lang->sonarqube->validError))));
|
||||
$this->post->set('token', $token);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
.table-form .c-name {width: 130px;}
|
||||
@@ -8,3 +8,24 @@ $lang->sonarqube->edit = 'Edit SonarQube';
|
||||
$lang->sonarqube->delete = 'Delete SonarQube';
|
||||
$lang->sonarqube->confirmDelete = 'Do you want to delete this SonarQube server?';
|
||||
$lang->sonarqube->serverFail = 'Connect to SonarQube server failed, please check the SonarQube server.';
|
||||
|
||||
$lang->sonarqube->id = 'ID';
|
||||
$lang->sonarqube->name = "{$lang->sonarqube->common} Name";
|
||||
$lang->sonarqube->url = 'URL';
|
||||
$lang->sonarqube->account = 'Username';
|
||||
$lang->sonarqube->password = 'Password';
|
||||
$lang->sonarqube->token = 'Token';
|
||||
$lang->sonarqube->defaultProject = 'Default Project';
|
||||
$lang->sonarqube->private = 'MD5 Verify';
|
||||
|
||||
$lang->sonarqube->createServer = 'Create SonarQube Server';
|
||||
$lang->sonarqube->desc = 'Description';
|
||||
$lang->sonarqube->createSuccess = 'Create success';
|
||||
|
||||
$lang->sonarqube->placeholder = new stdclass;
|
||||
$lang->sonarqube->placeholder->name = '';
|
||||
$lang->sonarqube->placeholder->url = "Please fill in the access address of the SonarQube Server homepage, as: https://sonarqube.zentao.net.";
|
||||
|
||||
$lang->sonarqube->repeatError = 'Server name or server address already exists!';
|
||||
$lang->sonarqube->validError = 'Sonarqube user authority authentication failed!';
|
||||
$lang->sonarqube->hostError = "Invalid SonarQube service address.";
|
||||
|
||||
@@ -8,3 +8,24 @@ $lang->sonarqube->edit = '编辑SonarQube';
|
||||
$lang->sonarqube->delete = '删除SonarQube';
|
||||
$lang->sonarqube->confirmDelete = '确认删除该SonarQube吗?';
|
||||
$lang->sonarqube->serverFail = '连接SonarQube服务器异常,请检查SonarQube服务器。';
|
||||
|
||||
$lang->sonarqube->id = 'ID';
|
||||
$lang->sonarqube->name = "{$lang->sonarqube->common}名称";
|
||||
$lang->sonarqube->url = '服务地址';
|
||||
$lang->sonarqube->account = '用户名';
|
||||
$lang->sonarqube->password = '密码';
|
||||
$lang->sonarqube->token = 'Token';
|
||||
$lang->sonarqube->defaultProject = '默认项目';
|
||||
$lang->sonarqube->private = 'MD5验证';
|
||||
|
||||
$lang->sonarqube->createServer = '添加SonarQube服务器';
|
||||
$lang->sonarqube->desc = '描述';
|
||||
$lang->sonarqube->createSuccess = "创建成功";
|
||||
|
||||
$lang->sonarqube->placeholder = new stdclass;
|
||||
$lang->sonarqube->placeholder->name = '';
|
||||
$lang->sonarqube->placeholder->url = "请填写SonarQube Server首页的访问地址,如:https://sonarqube.zentao.net。";
|
||||
|
||||
$lang->sonarqube->repeatError = "服务器名称或服务器地址已存在!";
|
||||
$lang->sonarqube->validError = "SonarQube 用户权限认证失败!";
|
||||
$lang->sonarqube->hostError = "无效的SonarQube服务地址。";
|
||||
|
||||
@@ -27,4 +27,37 @@ class sonarqubeModel extends model
|
||||
|
||||
return $sonarqubeList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sonarqube api base url and header by id.
|
||||
*
|
||||
* @param int $id
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getApiBase($id)
|
||||
{
|
||||
$sonarqube = $this->loadModel('pipeline')->getByID($id);
|
||||
if(!$sonarqube) return '';
|
||||
|
||||
$url = rtrim($sonarqube->url, '/') . '/api/%s';
|
||||
$header[] = 'Authorization: Basic ' . $sonarqube->token;
|
||||
|
||||
return array($url, $header);
|
||||
}
|
||||
|
||||
/**
|
||||
* check sonarqube valid
|
||||
*
|
||||
* @param string $host
|
||||
* @param string $token
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function apiValidate($host, $token)
|
||||
{
|
||||
$url = rtrim($host, '/') . "/api/authentication/validate";
|
||||
$header = 'Authorization: Basic ' . $token;
|
||||
return json_decode(commonModel::http($url, null, array(), $header));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* The create view file of sonarqube module of ZenTaoPMS.
|
||||
*
|
||||
* @copyright Copyright 2009-2022 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
|
||||
* @license ZPL (http://zpl.pub/page/zplv12.html)
|
||||
* @author Gang Zeng <zenggang@cnezsoft.com>
|
||||
* @package sonarqube
|
||||
* @version $Id$
|
||||
* @link http://www.zentao.net
|
||||
*/
|
||||
?>
|
||||
<?php include '../../common/view/header.html.php';?>
|
||||
<div id='mainContent' class='main-row'>
|
||||
<div class='main-col main-content'>
|
||||
<div class='center-block'>
|
||||
<div class='main-header'>
|
||||
<h2><?php echo $lang->sonarqube->createServer;?></h2>
|
||||
</div>
|
||||
<form id='sonarqubeForm' method='post' class='form-ajax'>
|
||||
<table class='table table-form'>
|
||||
<tr>
|
||||
<th class='c-name'><?php echo $lang->sonarqube->name;?></th>
|
||||
<td><?php echo html::input('name', '', "class='form-control' placeholder='{$lang->sonarqube->placeholder->name}'");?></td>
|
||||
<td class="tips-git"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><?php echo $lang->sonarqube->url;?></th>
|
||||
<td><?php echo html::input('url', '', "class='form-control' placeholder='{$lang->sonarqube->placeholder->url}'");?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><?php echo $lang->sonarqube->account;?></th>
|
||||
<td><?php echo html::input('account', '', "class='form-control'");?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><?php echo $lang->sonarqube->password;?></th>
|
||||
<td><?php echo html::password('password', '', "class='form-control'");?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th></th>
|
||||
<td class='text-center form-actions'>
|
||||
<?php echo html::submitButton();?>
|
||||
<?php if(!isonlybody()) echo html::a(inlink('browse', ""), $lang->goback, '', 'class="btn btn-wide"');?>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php include '../../common/view/footer.html.php';?>
|
||||
Reference in New Issue
Block a user