Skip to content

Commit

Permalink
Merge pull request #56 from ansibleguy76/release/v3.0.7
Browse files Browse the repository at this point in the history
v3.0.7 into main
  • Loading branch information
ansibleguy76 authored Sep 26, 2022
2 parents f3e81df + e04a1f9 commit d615c88
Show file tree
Hide file tree
Showing 12 changed files with 144 additions and 42 deletions.
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [3.0.7] - 2022-09-26

### Added

- Allow secure connection for mysql

### Changed

- Updated nodejs packages

## [3.0.6] - 2022-08-10

### Fixed
Expand Down Expand Up @@ -303,7 +313,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Allow change password for current local user
- Start tracking versions

[Unreleased]: https://github.com/ansibleguy76/ansibleforms/compare/3.0.6...HEAD
[Unreleased]: https://github.com/ansibleguy76/ansibleforms/compare/3.0.7...HEAD

[3.0.7]: https://github.com/ansibleguy76/ansibleforms/compare/3.0.6...3.0.7

[3.0.6]: https://github.com/ansibleguy76/ansibleforms/compare/3.0.5...3.0.6

Expand Down
4 changes: 2 additions & 2 deletions app_versions.gradle
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
ext.version_code = 30006
ext.version_name = "3.0.6"
ext.version_code = 30007
ext.version_name = "3.0.7"
4 changes: 2 additions & 2 deletions client/src/components/BulmaSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
icon:{type:[String,Array],default:''},
label:{type:String,required:true},
list:{type:Array,required:true},
valuecol:{type:String,required:true},
labelcol:{type:String,required:true},
valuecol:{type:String,required:false},
labelcol:{type:String,required:false},
hasError:{type:Boolean,default:false},
errors:{type:Array},
},data(){
Expand Down
31 changes: 27 additions & 4 deletions client/src/views/Credentials.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
:columns="['name','user','host']"
:filters="['name','user','host']"
identifier="id"
:actions="[{name:'select',title:'edit credential',icon:'pencil-alt',color:'has-text-warning'},{name:'delete',title:'delete credential',icon:'times',color:'has-text-danger'}]"
:actions="[{name:'select',title:'edit credential',icon:'pencil-alt',color:'has-text-warning'},{name:'delete',title:'delete credential',icon:'times',color:'has-text-danger'},{name:'test',title:'test credential',icon:'database',color:'has-text-link'}]"
:currentItem="credentialItem"
@select="selectItem"
@reset="resetItem"
@delete="deleteItem"
@test="testItem"
/>
</div>
<transition name="add-column" appear>
Expand All @@ -32,6 +33,8 @@
<BulmaInput icon="server" v-model="credential.host" label="Host" placeholder="Host" :required="true" :hasError="$v.credential.host.$invalid" :errors="[]" />
<BulmaInput icon="door-closed" v-model="credential.port" label="Port" placeholder="3306" :required="true" :hasError="$v.credential.port.$invalid" :errors="[]" />
<BulmaInput icon="info-circle" v-model="credential.description" label="Description" placeholder="Description" :required="true" :hasError="$v.credential.description.$invalid" :errors="[]" />
<BulmaSelect icon="database" v-model="credential.db_type" label="Database type" :list="['mysql','mssql','postgres','mongodb']" />
<BulmaCheckbox checktype="checkbox" v-model="credential.secure" label="Secure connection" /><br><br>
<BulmaButton v-if="credentialItem==-1" icon="save" label="Create Credential" @click="newCredential()"></BulmaButton>
<BulmaButton v-if="credentialItem!=-1" icon="save" label="Update Credential" @click="updateCredential()"></BulmaButton>
</div>
Expand All @@ -49,6 +52,8 @@
import BulmaAdminTable from './../components/BulmaAdminTable.vue'
import BulmaInput from './../components/BulmaInput.vue'
import BulmaModal from './../components/BulmaModal.vue'
import BulmaCheckbox from './../components/BulmaCheckRadio.vue'
import BulmaSelect from './../components/BulmaSelect.vue'
import TokenStorage from './../lib/TokenStorage'
import { required, email, minValue,maxValue,minLength,maxLength,helpers,requiredIf,sameAs,numeric } from 'vuelidate/lib/validators'
Expand All @@ -59,7 +64,7 @@
authenticated:{type:Boolean},
isAdmin:{type:Boolean}
},
components:{BulmaButton,BulmaInput,BulmaModal,BulmaAdminTable},
components:{BulmaButton,BulmaInput,BulmaModal,BulmaAdminTable,BulmaCheckbox,BulmaSelect},
data(){
return {
credential:{
Expand All @@ -68,7 +73,9 @@
password:"",
host:"",
port:3306,
description:""
description:"",
secure:false,
db_type:""
},
showDelete:false,
credentialItem:undefined,
Expand Down Expand Up @@ -104,6 +111,21 @@
this.selectItem(value)
this.showDelete=true
},
testItem(value){
var ref= this;
if(value){
axios.get('/api/v1/credential/testdb/' + value,TokenStorage.getAuthentication())
.then((result)=>{
if(result.data.status=='success'){
ref.$toast.success(result.data.message)
}else{
ref.$toast.error(result.data.message + "\r\n" + result.data.data.error)
}
}),function(error){
ref.$toast.error(error.message);
};
}
},
loadCredential(){
var ref= this;
if(this.credentialItem!=undefined && this.credentialItem!=-1){
Expand All @@ -121,7 +143,8 @@
name:""
}
}
},deleteCredential(){
},
deleteCredential(){
var ref= this;
axios.delete('/api/v1/credential/'+this.credentialItem,TokenStorage.getAuthentication())
.then((result)=>{
Expand Down
30 changes: 30 additions & 0 deletions server/src/controllers/credential.controller.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
'use strict';
const Credential = require('../models/credential.model');
var RestResult = require('../models/restResult.model');
const mysql=require("../lib/mysql")
const postgres=require("../lib/postgres")
const mssql=require("../lib/mssql")

exports.find = function(req, res) {
if(req.query.name){
Expand Down Expand Up @@ -49,3 +52,30 @@ exports.delete = function(req, res) {
.then(()=>{res.json(new RestResult("success","credential deleted",null,""))})
.catch((err)=>{res.json(new RestResult("error","failed to delete credential",null,err))})
};
exports.testDb = function(req,res){
Credential.findById(req.params.id)
.then((cred)=>{
var db_type = cred[0].db_type
if(db_type=='mysql'){
return mysql.query(cred[0].name,'select 1')
}else if(db_type=='mssql'){
return mssql.query(cred[0].name,'select 1')
}else if(db_type=='postgres'){
return postgres.query(cred[0].name,'select 1')
}else if(db_type=='mongodb'){
throw "Mongodb test is not implemented"
}else{
throw "Database type not set"
}
})
.then(()=>{res.json(new RestResult("success","Database connection ok",null,""))})
.catch((err)=>{
if(err.includes("not set")){
res.json(new RestResult("error","Database type not set",null,""))
}else{
res.json(new RestResult("error","Database connection failed",null,err))
}

})

}
2 changes: 2 additions & 0 deletions server/src/db/create_schema_and_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ CREATE TABLE `credentials` (
`host` varchar(250) DEFAULT NULL,
`port` int(11) DEFAULT NULL,
`description` text NOT NULL,
`secure` tinyint(4) DEFAULT NULL,
`db_type` varchar(10) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `uk_AnsibleForms_credentials_natural_key` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Expand Down
11 changes: 11 additions & 0 deletions server/src/lib/mysql.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ MySql.query=function(connection_name,query){
try{
logger.debug(`[${connection_name}] connection found : ${config.name}`)
config.multipleStatements=true
if(config.secure){
config.ssl={
sslmode:"required",
rejectUnauthorized:false
}
}else{
config.ssl={
sslmode:"none",
rejectUnauthorized:false
}
}
// get connection
conn = client.createConnection(config)
}catch(err){
Expand Down
6 changes: 4 additions & 2 deletions server/src/models/credential.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ var Credential=function(credential){
this.host = credential.host;
this.port = credential.port;
this.user = credential.user;
this.secure = (credential.secure)?1:0;
this.password = encrypt(credential.password);
this.description = credential.description;
this.db_type = credential.db_type;
};

Credential.create = function (record) {
Expand All @@ -39,7 +41,7 @@ Credential.delete = function(id){
};
Credential.findAll = function () {
logger.info("Finding all credentials")
return mysql.do("SELECT id,name,user,host,port,description FROM AnsibleForms.`credentials`;")
return mysql.do("SELECT id,name,user,host,port,description,secure,db_type FROM AnsibleForms.`credentials`;")
};
Credential.findById = function (id) {
logger.info(`Finding credential ${id}`)
Expand Down Expand Up @@ -79,7 +81,7 @@ Credential.findByName = function (name) {
logger.debug(`Finding credential ${name}`)
var cred = cache.get(name)
if(cred==undefined){
return mysql.do("SELECT host,port,name,user,password FROM AnsibleForms.`credentials` WHERE name=?;",name)
return mysql.do("SELECT host,port,name,user,password,secure,db_type FROM AnsibleForms.`credentials` WHERE name=?;",name)
.then((res)=>{
if(res.length>0){
res[0].multipleStatements = true
Expand Down
30 changes: 0 additions & 30 deletions server/src/models/db.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,36 +37,6 @@ MySql.do=function(query,vars){
}
})
};
// MySql.query=function(query,vars,callback){
// logger.info("[ansibleforms] running query : " + query)
// var conn
// try{
// var conn = client.createConnection(dbConfig)
// }catch(err){
// logger.error("[ansibleforms] Connection error : " + err)
// callback(null,null)
// return;
// }
// try{
// conn.query(query,vars,function(err,result){
// // logger.debug("[ansibleforms] Closing connection")
// conn.end()
// if(err){
// logger.error("[ansibleforms] Query error : " + err)
// callback(err,null)
// }else{
// logger.debug("[ansibleforms] query result : " + JSON.stringify(result))
// callback(null,result)
// }
// })
// }catch(err){
// // logger.debug("[ansibleforms] Closing connection")
// conn.end()
// logger.error("[ansibleforms] " + err)
// callback(null,null)
// }
//
// };


module.exports = MySql
2 changes: 2 additions & 0 deletions server/src/models/schema.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ function patchAll(){
tablePromises.push(addColumn("jobs","parent_id","int(11)",true,"NULL")) // add for multistep
tablePromises.push(renameColumn("jobs","playbook","target","VARCHAR(250)")) // better column name
tablePromises.push(addColumn("jobs","step","varchar(250)",true,"NULL")) // add column to hold current step
tablePromises.push(addColumn("credentials","secure","tinyint(4)",true,"0")) // add column to have secure connection
tablePromises.push(addColumn("credentials","db_type","varchar(10)",true,"NULL")) // add column to have db type
buffer = fs.readFileSync(`${__dirname}/../db/create_settings_table.sql`)
sql = buffer.toString()
tablePromises.push(addTable("settings",sql)) // add settings table
Expand Down
2 changes: 2 additions & 0 deletions server/src/routes/credential.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ router.put('/:id', credentialController.update);
// Delete a credential with id
router.delete('/:id', credentialController.delete);

router.get('/testdb/:id', credentialController.testDb)

module.exports = router
50 changes: 49 additions & 1 deletion server/src/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"swagger": "2.0",
"info": {
"description": "This is the swagger interface for AnsibleForms.\r\nUse the `/auth/login` api with basic authentication to obtain a JWT token.\r\nThen use the access token, prefixed with the word '**Bearer**' to use all other api's.\r\nNote that the access token is limited in time. You can then either login again and get a new set of tokens or use the `/token` api and the refresh token to obtain a new set (preferred).",
"version": "3.0.6",
"version": "3.0.7",
"title": "AnsibleForms",
"contact": {
"email": "info@ansibleforms.com"
Expand Down Expand Up @@ -1997,6 +1997,54 @@
}
}
},
"/credential/testdb/{credentialId}": {
"get": {
"tags": [
"credentials"
],
"security": [
{
"bearerAuth": []
}
],
"summary": "Test a credential against a database",
"parameters": [
{
"in": "path",
"name": "credentialId",
"type": "integer",
"required": true,
"description": "Numeric ID of the credential to get."
}
],
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "successful operation",
"schema": {
"type": "object",
"example": {
"status": "success",
"message": "Mysql connection success",
"data": {
"output": "",
"error": ""
}
}
}
},
"401": {
"description": "unauthorized",
"schema": {
"type": "string",
"example": "Authorize with a valid Bearer access token"
}
}
}
}
},
"/user": {
"get": {
"tags": [
Expand Down

0 comments on commit d615c88

Please sign in to comment.