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 5, 2024
1 parent 84dbb1f commit ac368cc
Showing 1 changed file with 86 additions and 75 deletions.
161 changes: 86 additions & 75 deletions internal/resources/web-app-asset/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,101 +47,60 @@ func ReadWebApplicationAssetToResourceData(asset models.WebApplicationAsset, d *

var proxySettingsSchemaMap []map[string]any
var mTLSsSchemaMap map[string]models.FileSchema
var mTLSsMap []map[string]any

for _, proxySetting := range asset.ProxySettings {
mTLSType := proxySettingKeyTomTLSType(proxySetting.Key)
if mTLSType != "" {
if _, ok := mTLSsSchemaMap[mTLSType]; !ok {
switch proxySetting.Key {
case mtlsClientEnable:
if proxySetting.Value == "true" {
mTLSsSchemaMap[mTLSType] = models.FileSchema{
FilenameID: mTLSsSchemaMap[mTLSType].FilenameID,
Filename: mTLSsSchemaMap[mTLSType].Filename,
DataID: mTLSsSchemaMap[mTLSType].DataID,
Data: mTLSsSchemaMap[mTLSType].Data,
Type: mTLSType,
EnableID: proxySetting.ID,
Enable: true,
}
}
if proxySetting.Value == "false" {
mTLSsSchemaMap[mTLSType] = models.FileSchema{
FilenameID: mTLSsSchemaMap[mTLSType].FilenameID,
Filename: mTLSsSchemaMap[mTLSType].Filename,
DataID: mTLSsSchemaMap[mTLSType].DataID,
Data: mTLSsSchemaMap[mTLSType].Data,
Type: mTLSType,
EnableID: proxySetting.ID,
Enable: false,
}
}
case mtlsClientData:
mTLSsSchemaMap[mTLSType] = models.FileSchema{}
}
switch proxySetting.Key {
case mtlsClientEnable, mtlsServerEnable:
if proxySetting.Value == "true" {
mTLSsSchemaMap[mTLSType] = models.FileSchema{
FilenameID: mTLSsSchemaMap[mTLSType].FilenameID,
Filename: mTLSsSchemaMap[mTLSType].Filename,
DataID: proxySetting.ID,
Data: proxySetting.Value,
Type: mTLSType,
EnableID: mTLSsSchemaMap[mTLSType].EnableID,
Enable: mTLSsSchemaMap[mTLSType].Enable,
}
case mtlsClientFileName:
mTLSsSchemaMap[mTLSType] = models.FileSchema{
FilenameID: proxySetting.ID,
Filename: proxySetting.Value,
DataID: mTLSsSchemaMap[mTLSType].DataID,
Data: mTLSsSchemaMap[mTLSType].Data,
Type: mTLSType,
EnableID: mTLSsSchemaMap[mTLSType].EnableID,
Enable: mTLSsSchemaMap[mTLSType].Enable,
}
case mtlsServerEnable:
if proxySetting.Value == "true" {
mTLSsSchemaMap[mTLSType] = models.FileSchema{
FilenameID: mTLSsSchemaMap[mTLSType].FilenameID,
Filename: mTLSsSchemaMap[mTLSType].Filename,
DataID: mTLSsSchemaMap[mTLSType].DataID,
Data: mTLSsSchemaMap[mTLSType].Data,
Type: mTLSType,
EnableID: proxySetting.ID,
Enable: true,
}
EnableID: proxySetting.ID,
Enable: true,
}
if proxySetting.Value == "false" {
mTLSsSchemaMap[mTLSType] = models.FileSchema{
FilenameID: mTLSsSchemaMap[mTLSType].FilenameID,
Filename: mTLSsSchemaMap[mTLSType].Filename,
DataID: mTLSsSchemaMap[mTLSType].DataID,
Data: mTLSsSchemaMap[mTLSType].Data,
Type: mTLSType,
EnableID: proxySetting.ID,
Enable: false,
}
}
case mtlsServerData:
}
if proxySetting.Value == "false" {
mTLSsSchemaMap[mTLSType] = models.FileSchema{
FilenameID: mTLSsSchemaMap[mTLSType].FilenameID,
Filename: mTLSsSchemaMap[mTLSType].Filename,
DataID: proxySetting.ID,
Data: proxySetting.Value,
Type: mTLSType,
EnableID: mTLSsSchemaMap[mTLSType].EnableID,
Enable: mTLSsSchemaMap[mTLSType].Enable,
}
case mtlsServerFileName:
mTLSsSchemaMap[mTLSType] = models.FileSchema{
FilenameID: proxySetting.ID,
Filename: proxySetting.Value,
DataID: mTLSsSchemaMap[mTLSType].DataID,
Data: mTLSsSchemaMap[mTLSType].Data,
Type: mTLSType,
EnableID: mTLSsSchemaMap[mTLSType].EnableID,
Enable: mTLSsSchemaMap[mTLSType].Enable,
EnableID: proxySetting.ID,
Enable: false,
}
default:
continue
}
case mtlsClientData, mtlsServerData:
mTLSsSchemaMap[mTLSType] = models.FileSchema{
FilenameID: mTLSsSchemaMap[mTLSType].FilenameID,
Filename: mTLSsSchemaMap[mTLSType].Filename,
DataID: proxySetting.ID,
Data: proxySetting.Value,
Type: mTLSType,
EnableID: mTLSsSchemaMap[mTLSType].EnableID,
Enable: mTLSsSchemaMap[mTLSType].Enable,
}
case mtlsClientFileName, mtlsServerFileName:
mTLSsSchemaMap[mTLSType] = models.FileSchema{
FilenameID: proxySetting.ID,
Filename: proxySetting.Value,
DataID: mTLSsSchemaMap[mTLSType].DataID,
Data: mTLSsSchemaMap[mTLSType].Data,
Type: mTLSType,
EnableID: mTLSsSchemaMap[mTLSType].EnableID,
Enable: mTLSsSchemaMap[mTLSType].Enable,
}
default:
continue
}
} else {
proxySettingSchemaMap, err := utils.UnmarshalAs[map[string]any](proxySetting)
Expand All @@ -152,12 +111,64 @@ func ReadWebApplicationAssetToResourceData(asset models.WebApplicationAsset, d *
proxySettingsSchemaMap = append(proxySettingsSchemaMap, proxySettingSchemaMap)
}
}
//case mtlsServerEnable:
// if proxySetting.Value == "true" {
// mTLSsSchemaMap[mTLSType] = models.FileSchema{
// FilenameID: mTLSsSchemaMap[mTLSType].FilenameID,
// Filename: mTLSsSchemaMap[mTLSType].Filename,
// DataID: mTLSsSchemaMap[mTLSType].DataID,
// Data: mTLSsSchemaMap[mTLSType].Data,
// Type: mTLSType,
// EnableID: proxySetting.ID,
// Enable: true,
// }
// }
// if proxySetting.Value == "false" {
// mTLSsSchemaMap[mTLSType] = models.FileSchema{
// FilenameID: mTLSsSchemaMap[mTLSType].FilenameID,
// Filename: mTLSsSchemaMap[mTLSType].Filename,
// DataID: mTLSsSchemaMap[mTLSType].DataID,
// Data: mTLSsSchemaMap[mTLSType].Data,
// Type: mTLSType,
// EnableID: proxySetting.ID,
// Enable: false,
// }
// }
//case mtlsServerData:
// mTLSsSchemaMap[mTLSType] = models.FileSchema{
// FilenameID: mTLSsSchemaMap[mTLSType].FilenameID,
// Filename: mTLSsSchemaMap[mTLSType].Filename,
// DataID: proxySetting.ID,
// Data: proxySetting.Value,
// Type: mTLSType,
// EnableID: mTLSsSchemaMap[mTLSType].EnableID,
// Enable: mTLSsSchemaMap[mTLSType].Enable,
// }
//case mtlsServerFileName:
// mTLSsSchemaMap[mTLSType] = models.FileSchema{
// FilenameID: proxySetting.ID,
// Filename: proxySetting.Value,
// DataID: mTLSsSchemaMap[mTLSType].DataID,
// Data: mTLSsSchemaMap[mTLSType].Data,
// Type: mTLSType,
// EnableID: mTLSsSchemaMap[mTLSType].EnableID,
// Enable: mTLSsSchemaMap[mTLSType].Enable,
// }

//proxySettingsSchemaMap, err := utils.UnmarshalAs[[]map[string]any](asset.ProxySettings)
//if err != nil {
// return fmt.Errorf("failed to convert proxy settings to slice of maps. Error: %+v", err)
//}

for _, mTLSscehma := range mTLSsSchemaMap {
mTLS, err := utils.UnmarshalAs[map[string]any](mTLSscehma)
if err != nil {
return fmt.Errorf("failed to convert mTLS to map. Error: %+v", err)
}

mTLSsMap = append(mTLSsMap, mTLS)
}

d.Set("proxy_setting", proxySettingsSchemaMap)
d.Set("mtls", mTLSsSchemaMap)

Expand Down

0 comments on commit ac368cc

Please sign in to comment.