Skip to content

Commit

Permalink
Merge pull request #29 from WeBankPartners/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Roy Wu(伍健君) authored Sep 30, 2021
2 parents 8b1f7ee + b8d4c01 commit f2ede65
Show file tree
Hide file tree
Showing 7 changed files with 190 additions and 157 deletions.
23 changes: 12 additions & 11 deletions terraform-server/services/db/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func ProviderBatchCreate(user string, param []*models.ProviderTable) (rowData []
}
terraformProviderCommonPath := terraformFilePath + "providers/" + data.Name + "/" + data.Version
terraformProviderPath := terraformProviderCommonPath + "/" + models.Config.TerraformProviderOsArch
terraformLockHclPath := terraformProviderCommonPath + "/" + models.Config.TerraformProviderOsArch + "_hcl"
terraformLockHclPath := terraformProviderCommonPath + "/" + models.Config.TerraformProviderOsArch + "_hcl"

data.Initialized = "Y"
_, err = os.Stat(terraformProviderPath)
Expand Down Expand Up @@ -108,7 +108,7 @@ func ProviderBatchUpdate(user string, param []*models.ProviderTable) (err error)
}
terraformProviderCommonPath := terraformFilePath + "providers/" + param[i].Name + "/" + param[i].Version
terraformProviderPath := terraformProviderCommonPath + "/" + models.Config.TerraformProviderOsArch
terraformLockHclPath := terraformProviderCommonPath + "/" + models.Config.TerraformProviderOsArch + "_hcl"
terraformLockHclPath := terraformProviderCommonPath + "/" + models.Config.TerraformProviderOsArch + "_hcl"

param[i].Initialized = "Y"
_, err = os.Stat(terraformProviderPath)
Expand Down Expand Up @@ -175,6 +175,7 @@ func ProviderPluginExport(providerNameList, pluginNameList []string) (result mod
pluginIdFilterSql = fmt.Sprintf("('%s')", strings.Join(pluginIdList, "','"))
x.SQL("select * from interface where plugin in " + pluginIdFilterSql).Find(&result.Interface)
x.SQL("select * from `parameter` where interface in (select id from interface where plugin in " + pluginIdFilterSql + ")").Find(&result.Parameter)
x.SQL("select * from provider_template_value where provider in " + providerIdFilterSql).Find(&result.ProviderTemplateValue)
templateSql := "select * from template where id in (select template_value from provider_template_value where provider in " + providerIdFilterSql + ")"
templateSql += " union "
templateSql += "select * from template where id in (select template from `parameter` where interface in (select id from interface where plugin in " + pluginIdFilterSql + "))"
Expand Down Expand Up @@ -312,15 +313,15 @@ func ProviderDownload(providerId string, user string) (err error) {
}
terraformProviderCommonPath := terraformFilePath + "providers/" + providerData.Name + "/" + providerData.Version
// terraformProviderPath := terraformProviderCommonPath + "/" + models.Config.TerraformProviderOsArch
terraformLockHclPath := terraformProviderCommonPath + "/" + models.Config.TerraformProviderOsArch + "_hcl"
terraformLockHclPath := terraformProviderCommonPath + "/" + models.Config.TerraformProviderOsArch + "_hcl"

/*
err = GenDir(terraformProviderPath)
if err != nil {
err = fmt.Errorf("Gen terraformProviderPath : %s error: %s", terraformProviderPath, err.Error())
log.Logger.Error("Gen terraformProviderPath error", log.String("terraformProviderPath", terraformProviderPath), log.Error(err))
return
}
err = GenDir(terraformProviderPath)
if err != nil {
err = fmt.Errorf("Gen terraformProviderPath : %s error: %s", terraformProviderPath, err.Error())
log.Logger.Error("Gen terraformProviderPath error", log.String("terraformProviderPath", terraformProviderPath), log.Error(err))
return
}
*/

err = GenDir(terraformLockHclPath)
Expand Down Expand Up @@ -402,7 +403,7 @@ func ProviderUpload(providerId string, r *http.Request, user string) (err error)
terraformFilePath += "/"
}
terraformProviderCommonPath := terraformFilePath + "providers/" + providerData.Name + "/" + providerData.Version
terraformLockHclPath := terraformProviderCommonPath + "/" + models.Config.TerraformProviderOsArch + "_hcl"
terraformLockHclPath := terraformProviderCommonPath + "/" + models.Config.TerraformProviderOsArch + "_hcl"

err = GenDir(terraformLockHclPath)
if err != nil {
Expand Down Expand Up @@ -530,4 +531,4 @@ func ProviderUpload(providerId string, r *http.Request, user string) (err error)
log.Logger.Error("Update provider's initialized column error", log.Error(err))
}
return
}
}
41 changes: 33 additions & 8 deletions terraform-server/services/db/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -625,21 +625,29 @@ func handleOutPutArgs(outPutArgs map[string]interface{},
if _, ok := reqParam[k]; ok {
mapOutPutArgs[i][k] = reqParam[k]
if k == "password" {
enCodeStr, encodeErr := cipher.AesEnPasswordByGuid(models.PGuid, models.Config.Auth.PasswordSeed, reqParam[k].(string), "")
if encodeErr != nil {
log.Logger.Error("Try to encode failed", log.Error(encodeErr))
if _, tmpOk := reqParam["seed"]; !tmpOk {
log.Logger.Error("Try to get seed failed")
} else {
mapOutPutArgs[i][k] = enCodeStr
enCodeStr, encodeErr := cipher.AesEnPasswordByGuid(reqParam["id"].(string), reqParam["seed"].(string), reqParam[k].(string), "")
if encodeErr != nil {
log.Logger.Error("Try to encode failed", log.Error(encodeErr))
} else {
mapOutPutArgs[i][k] = enCodeStr
}
}
}
}
} else {
if v.Sensitive == "Y" {
enCodeStr, encodeErr := cipher.AesEnPasswordByGuid(models.PGuid, models.Config.Auth.PasswordSeed, mapOutPutArgs[i][k].(string), "")
if encodeErr != nil {
log.Logger.Error("Try to encode failed", log.Error(encodeErr))
if _, tmpOk := reqParam["seed"]; !tmpOk {
log.Logger.Error("Try to get seed failed")
} else {
mapOutPutArgs[i][k] = enCodeStr
enCodeStr, encodeErr := cipher.AesEnPasswordByGuid(reqParam["id"].(string), reqParam["seed"].(string), mapOutPutArgs[i][k].(string), "")
if encodeErr != nil {
log.Logger.Error("Try to encode failed", log.Error(encodeErr))
} else {
mapOutPutArgs[i][k] = enCodeStr
}
}
}
}
Expand Down Expand Up @@ -3381,6 +3389,23 @@ func convertDirect(defaultValue string, reqParam map[string]interface{}, tfArgum
}
}

if parameterData.Sensitive == "Y" {
if _, tmpOk := reqParam["seed"]; !tmpOk {
err = fmt.Errorf("Parameter data: seed can not be found ")
return
} else if reqParam["seed"].(string) == "" {
err = fmt.Errorf("Parameter data: seed can not be empty ")
return
}

if _, ok := arg.(string); ok {
if strings.HasPrefix(arg.(string),"{cipher_a}") {
arg, err = cipher.AesDePasswordByGuid(reqParam["id"].(string), reqParam["seed"].(string), arg.(string))
return
}
}
}

if tfArgument.DefaultValue == models.RandomFlag && (arg == nil || arg == "") {
randomVal := guid.CreateGuid()
arg = randomVal[:16]
Expand Down
8 changes: 7 additions & 1 deletion ui/src/locale/i18n/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"t_region_attr_name": "Region Attr Name",
"t_secretKey_attr_name": "Secret Key Attr Name",
"t_secretId_attr_name": "Secret ID Attr Name",
"t_initialized": "Provider Initialized",
"t_source": "Source",
"t_resource_asset_id_Attribute": "Resource Asset Id Attribute",
"t_import_export": "Import & Export",
Expand Down Expand Up @@ -66,5 +67,10 @@
"t_remark": "Remark",
"t_namespace": "Namespace",
"t_format_parameter": "Format Parameter",
"t_instance_data": "Instance Data"
"t_instance_data": "Instance Data",
"t_download": "Download",
"t_online_download": "Download",
"t_local_upload": "Upload",
"t_online_download_tip": "In online scenarios, download the official provider file",
"t_local_upload_tip": "In offline scenarios, upload the locally made provider file"
}
8 changes: 7 additions & 1 deletion ui/src/locale/i18n/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"t_region_attr_name": "地域属性名称",
"t_secretKey_attr_name": "秘钥Key属性名称",
"t_secretId_attr_name": "秘钥Id属性名称",
"t_initialized": "是否初始化",
"t_source": "资源",
"t_resource_asset_id_Attribute": "资产ID属性",
"t_import_export": "导入&导出",
Expand Down Expand Up @@ -66,5 +67,10 @@
"t_remark": "备注",
"t_namespace": "命名空间",
"t_format_parameter": "格式化参数",
"t_instance_data": "实例数据"
"t_instance_data": "实例数据",
"t_download": "下载",
"t_online_download": "下载",
"t_local_upload": "上传",
"t_online_download_tip": "连网场景,下载官方提供的provider文件",
"t_local_upload_tip": "离线场景,上传本地制做的provider文件"
}
105 changes: 1 addition & 104 deletions ui/src/pages/instance-data.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</template>

<script>
import { getInstanceData, instanceDataDownload } from '@/api/server'
import { getInstanceData } from '@/api/server'
export default {
name: '',
data () {
Expand Down Expand Up @@ -93,71 +93,6 @@ export default {
</div>
)
}
},
{
title: this.$t('t_action'),
key: 'action',
width: 160,
align: 'center',
render: (h, params) => {
if (params.row.providerInitialized === 'Y') {
return ''
}
return h('div', [
h(
'Upload',
{
props: {
type: 'select',
size: 'small',
action: `/terraform/api/v1/providers/upload?id=${params.row.providerId}`,
'on-success': this.handleSuccess,
'on-error': this.handleError,
'before-upload': this.handleUpload
},
style: {
display: 'inline-block'
},
on: {}
},
[
h(
'Button',
{
props: {
type: 'success',
size: 'small'
},
style: {},
on: {}
},
this.$t('t_import')
)
]
),
h(
'Button',
{
props: Object.assign(
{},
{
type: 'primary',
size: 'small'
}
),
style: {
'margin-left': '8px'
},
on: {
click: () => {
this.downloadInstance(params.row)
}
}
},
this.$t('t_export')
)
])
}
}
],
tableData: [],
Expand All @@ -169,44 +104,6 @@ export default {
this.getInstanceData()
},
methods: {
handleUpload (file) {
if (file.name.endsWith('.gz') || file.name.endsWith('.zip')) {
return true
} else {
this.$Notice.warning({
title: 'Warning',
desc: 'Must be a .gz or .zip file'
})
return false
}
},
handleError (val) {
this.$Notice.error({
title: 'Error',
desc: 'Import Faild'
})
},
handleSuccess (val) {
this.$Notice.success({
title: 'Successful',
desc: 'Successful'
})
this.getInstanceData()
},
async downloadInstance (item) {
this.$Notice.success({
title: 'Info',
desc: 'Need 10s ……'
})
const { statusCode } = await instanceDataDownload(item.providerId)
if (statusCode === 'OK') {
this.$Notice.success({
title: 'Successful',
desc: 'Successful'
})
this.getInstanceData()
}
},
async getInstanceData () {
const { statusCode, data } = await getInstanceData()
if (statusCode === 'OK') {
Expand Down
Loading

0 comments on commit f2ede65

Please sign in to comment.