From ac368cc24d3bdc9ca2cbc8397ac42c1e60544f4b Mon Sep 17 00:00:00 2001 From: omerma Date: Thu, 5 Dec 2024 15:16:45 +0200 Subject: [PATCH] check mtls test --- internal/resources/web-app-asset/read.go | 161 ++++++++++++----------- 1 file changed, 86 insertions(+), 75 deletions(-) diff --git a/internal/resources/web-app-asset/read.go b/internal/resources/web-app-asset/read.go index c488fea..387e5df 100644 --- a/internal/resources/web-app-asset/read.go +++ b/internal/resources/web-app-asset/read.go @@ -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) @@ -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)