Skip to content

Commit

Permalink
check mtls test
Browse files Browse the repository at this point in the history
  • Loading branch information
chkp-omerma committed Dec 7, 2024
1 parent 2947050 commit 4f28c33
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 4 deletions.
13 changes: 12 additions & 1 deletion internal/models/web-app-asset/input.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package models

import "strings"
import (
"strings"
)

// PracticeModeInput represents the api input for creating a practice mode field
// in the practice field of the web application asset
Expand Down Expand Up @@ -101,3 +103,12 @@ func (inputs TagsInputs) ToIndicatorsMap() map[string]TagInput {

return ret
}

func (mtlsInputs FileSchemas) ToIndicatorMap() map[string]FileSchema {
mTLSs := make(map[string]FileSchema)
for _, mTLS := range mtlsInputs {
mTLSs[mTLS.Type] = mTLS
}

return mTLSs
}
2 changes: 0 additions & 2 deletions internal/resources/tests/add-mtls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,6 @@ resource "inext_web_app_asset" %[1]q {
key = "tagkey2"
value = "tagvalue2"
}
is_shares_urls = false
mtls {
filename = "cert.pem"
data = "cert data"
Expand Down Expand Up @@ -677,7 +676,6 @@ resource "inext_web_app_asset" %[1]q {
key = "tagkey3"
value = "tagvalue3"
}
is_shares_urls = true
mtls {
filename = "newfile.pem"
data = "new cert data"
Expand Down
2 changes: 1 addition & 1 deletion internal/resources/web-app-asset/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func mapToMTLSInput(mTLSMap map[string]any) models.FileSchema {
return mTLSFile
}

func mapMTLSToProxySettingInputs(mTLS []models.FileSchema, proxySettings models.ProxySettingInputs) models.ProxySettingInputs {
func mapMTLSToProxySettingInputs(mTLS models.FileSchemas, proxySettings models.ProxySettingInputs) models.ProxySettingInputs {
for _, mTLSFile := range mTLS {
var proxySettingEnable, proxySettingData, proxySettingFileName models.ProxySettingInput
switch mTLSFile.Type {
Expand Down
69 changes: 69 additions & 0 deletions internal/resources/web-app-asset/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,77 @@ func UpdateWebApplicationAssetInputFromResourceData(d *schema.ResourceData, asse

newProxySettingsIndicators := newProxySettings.ToIndicatorsMap()
for _, oldSetting := range oldProxySettings {
if oldSetting.Key == mtlsClientEnable || oldSetting.Key == mtlsClientData || oldSetting.Key == mtlsClientFileName || oldSetting.Key == mtlsServerData || oldSetting.Key == mtlsServerFileName || oldSetting.Key == mtlsServerEnable {
continue
}
if _, ok := newProxySettingsIndicators[oldSetting.Key]; !ok {
updateInput.RemoveProxySetting = append(updateInput.RemoveProxySetting, oldSetting.ID)
}
}
}

if oldMTLSs, newMTLSs, hasChange := utils.GetChangeWithParse(d, "mtls", parsemTLSs); hasChange {
oldMTLSsIndicators := oldMTLSs.ToIndicatorMap()
mTLSsToAdd := models.FileSchemas{}
for _, newMTLS := range newMTLSs {
oldMTLS, ok := oldMTLSsIndicators[newMTLS.Type]
if !ok {
mTLSsToAdd = append(mTLSsToAdd, newMTLS)
//proxysettingstoadd := mapMTLSToProxySettingInputs(newMTLS, models.ProxySettingInputs{})
//
//updateInput.AddProxySetting = append(updateInput.AddProxySetting, mapMTLSToProxySettingInputs(newMTLS))
continue
}
if oldMTLS.Enable != newMTLS.Enable {
var enableToString string
if newMTLS.Enable {
enableToString = "true"
} else {
enableToString = "false"
}
updateInput.UpdateProxySetting = append(updateInput.UpdateProxySetting, models.UpdateProxySetting{
ID: oldMTLS.EnableID,
Value: enableToString,
})
}

if oldMTLS.Data != newMTLS.Data {
updateInput.UpdateProxySetting = append(updateInput.UpdateProxySetting, models.UpdateProxySetting{
ID: oldMTLS.DataID,
Value: newMTLS.Data,
})
}

if oldMTLS.Filename != newMTLS.Filename {
updateInput.UpdateProxySetting = append(updateInput.UpdateProxySetting, models.UpdateProxySetting{
ID: oldMTLS.FilenameID,
Value: newMTLS.Filename,
})
}

//oldMTLS := oldMTLSsIndicators[newMTLS["type"].(string)]
//if oldMTLS.Data != newMTLS["data"].(string) || oldMTLS.Enable != newMTLS["enable"].(bool) {
// updateInput.UpdateMTLS = append(updateInput.UpdateMTLS, models.UpdateMTLS{
// ID: oldMTLS.ID,
// Type: oldMTLS.Type,
// Data: newMTLS["data"].(string),
// Enable: newMTLS["enable"].(bool),
// })
//}
}

var proxySettingsToAdd models.ProxySettingInputs
if mTLSsToAdd != nil {
proxySettingsToAdd = mapMTLSToProxySettingInputs(mTLSsToAdd, models.ProxySettingInputs{})
}
for _, proxySettingToAdd := range proxySettingsToAdd {
updateInput.AddProxySetting = append(updateInput.AddProxySetting, models.AddProxySetting{
Key: proxySettingToAdd.Key,
Value: proxySettingToAdd.Value,
})
}
}

if oldSourceIdentifiers, newSourceIdentifiers, hasChange := utils.GetChangeWithParse(d, "source_identifier", parseSchemaSourceIdentifiers); hasChange {
oldSourceIdentifiersIndicatorMap := oldSourceIdentifiers.ToIndicatorsMap()
for _, newSourceIdentifier := range newSourceIdentifiers {
Expand Down Expand Up @@ -218,3 +283,7 @@ func validatePracticeWrapperInput(practice models.PracticeWrapperInput) bool {
func parseSchemaTags(tagsFromResourceData any) models.TagsInputs {
return utils.Map(utils.MustSchemaCollectionToSlice[map[string]any](tagsFromResourceData), mapToTagsInputs)
}

func parsemTLSs(mTLSsFromResourceData any) models.FileSchemas {
return utils.Map(utils.MustSchemaCollectionToSlice[map[string]any](mTLSsFromResourceData), mapToMTLSInput)
}

0 comments on commit 4f28c33

Please sign in to comment.