44import org .zstack .header .storage .primary .PrimaryStorageInventory ;
55import org .zstack .utils .gson .JSONObjectUtil ;
66
7+ import java .util .ArrayList ;
78import java .util .LinkedHashMap ;
89import java .util .List ;
10+ import java .util .Map ;
911import java .util .stream .Collectors ;
1012
1113@ Inventory (mappingVOClass = ExternalPrimaryStorageVO .class )
@@ -59,6 +61,7 @@ public ExternalPrimaryStorageInventory(ExternalPrimaryStorageVO lvo) {
5961 super (lvo );
6062 identity = lvo .getIdentity ();
6163 config = JSONObjectUtil .toObject (lvo .getConfig (), LinkedHashMap .class );
64+ desensitizeConfig (config );
6265 addonInfo = JSONObjectUtil .toObject (lvo .getAddonInfo (), LinkedHashMap .class );
6366 outputProtocols = lvo .getOutputProtocols ().stream ().map (PrimaryStorageOutputProtocolRefVO ::getOutputProtocol ).collect (Collectors .toList ());
6467 defaultProtocol = lvo .getDefaultProtocol ();
@@ -68,6 +71,35 @@ public static ExternalPrimaryStorageInventory valueOf(ExternalPrimaryStorageVO l
6871 return new ExternalPrimaryStorageInventory (lvo );
6972 }
7073
74+ private static void desensitizeConfig (Map config ) {
75+ if (config == null ) return ;
76+ desensitizeUrlList (config , "mdsUrls" );
77+ desensitizeUrlList (config , "mdsInfos" );
78+ }
79+
80+ private static void desensitizeUrlList (Map config , String key ) {
81+ Object urls = config .get (key );
82+ if (urls instanceof List ) {
83+ List <String > desensitized = new ArrayList <>();
84+ for (Object url : (List ) urls ) {
85+ desensitized .add (desensitizeUrl (String .valueOf (url )));
86+ }
87+ config .put (key , desensitized );
88+ }
89+ }
90+
91+ private static String desensitizeUrl (String url ) {
92+ int atIndex = url .lastIndexOf ('@' );
93+ if (atIndex > 0 ) {
94+ int schemeIndex = url .indexOf ("://" );
95+ if (schemeIndex >= 0 && schemeIndex < atIndex ) {
96+ return url .substring (0 , schemeIndex + 3 ) + "***" + url .substring (atIndex );
97+ }
98+ return "***" + url .substring (atIndex );
99+ }
100+ return url ;
101+ }
102+
71103 public String getIdentity () {
72104 return identity ;
73105 }
0 commit comments