Skip to content

Commit 534eb0a

Browse files
committed
when downloading an encrypted asset that already exists locally, dont set its local value to null and keep old local value instead
1 parent 90622d6 commit 534eb0a

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

AutomationISE/Model/AutomationCredential.cs

+2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public string getUsername()
6464

6565
public void setUsername(string username)
6666
{
67+
this.ValueFields.Remove("Username");
6768
this.ValueFields.Add("Username", username);
6869
}
6970

@@ -76,6 +77,7 @@ public string getPassword()
7677

7778
public void setPassword(string password)
7879
{
80+
this.ValueFields.Remove("Password");
7981
this.ValueFields.Add("Password", password);
8082
}
8183
}

AutomationISE/Model/AutomationVariable.cs

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public Object getValue()
7474

7575
public void setValue(Object value)
7676
{
77+
this.ValueFields.Remove("Value");
7778
this.ValueFields.Add("Value", value);
7879
}
7980

AutomationISE/Model/LocalAssetsStore.cs

+27-4
Original file line numberDiff line numberDiff line change
@@ -65,32 +65,55 @@ private static void Set(String workspacePath, ICollection<AutomationAsset> asset
6565

6666
if (assetToAffect is AutomationVariable)
6767
{
68+
var variableToAffect = (AutomationVariable)assetToAffect;
69+
6870
if (assetToDelete != null)
6971
{
70-
localAssets.Variables.Remove((VariableJson)assetToDelete);
72+
var variableToDelete = (VariableJson)assetToDelete;
73+
74+
// Encrypted variable assets returned from the cloud have their values removed,
75+
// so keep the old local asset value instead of overwriting the local asset value with null
76+
if(variableToAffect.Encrypted && variableToAffect.getValue() == null) {
77+
variableToAffect.setValue(variableToDelete.Value);
78+
}
79+
80+
localAssets.Variables.Remove(variableToDelete);
7181
}
7282

7383
if (replace)
7484
{
75-
localAssets.Variables.Add(new VariableJson((AutomationVariable)assetToAffect));
85+
localAssets.Variables.Add(new VariableJson(variableToAffect));
7686
}
7787
}
7888

7989
else if (assetToAffect is AutomationCredential)
8090
{
91+
var credToAffect = (AutomationCredential)assetToAffect;
92+
8193
if (assetToDelete != null)
8294
{
83-
localAssets.PSCredentials.Remove((CredentialJson)assetToDelete);
95+
var credToDelete = (CredentialJson)assetToDelete;
96+
97+
// PSCredential assets returned from the cloud have their passwords removed,
98+
// so keep the old local asset password instead of overwriting the local asset password with null
99+
if (credToAffect.getPassword() == null)
100+
{
101+
credToAffect.setPassword(credToDelete.Password);
102+
}
103+
104+
localAssets.PSCredentials.Remove(credToDelete);
84105
}
85106

86107
if (replace)
87108
{
88-
localAssets.PSCredentials.Add(new CredentialJson((AutomationCredential)assetToAffect));
109+
localAssets.PSCredentials.Add(new CredentialJson(credToAffect));
89110
}
90111
}
91112

92113
else if (assetToAffect is AutomationConnection)
93114
{
115+
// TODO: support carry over of null fields from previous local asset
116+
94117
if (assetToDelete != null)
95118
{
96119
localAssets.Connections.Remove((ConnectionJson)assetToDelete);

0 commit comments

Comments
 (0)