-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMerge-RoleToConfigRepository.ps1
More file actions
55 lines (47 loc) · 1.75 KB
/
Merge-RoleToConfigRepository.ps1
File metadata and controls
55 lines (47 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
param (
[ValidateScript({Test-Path -PathType Leaf -Path $_})]
[Parameter(Mandatory=$true, HelpMessage='The location of the storage config.')]
$storageConfig,
$roleName,
$rolePlaceHolder,
$roleUrl,
[hashtable]$roleProperties,
[switch]$usePlaceholders=$false
)
$scriptPath = Split-Path $script:MyInvocation.MyCommand.Path
$config = [xml](gc $storageConfig)
if ($roleUrl) {
if ($usePlaceHolders -and $rolePlaceHolder) {
$roleUrl = "`$`{$rolePlaceHolder`:-$roleUrl`}"
} else {
$roleUrl = $roleUrl
}
}
# <Role Name="ContentServiceCapability" Url="${contenturl:-http://localhost:8081/content.svc}"/>
$roles = (Select-Xml -Xml $config.DocumentElement -XPath '/Configuration/ConfigRepository/Roles').Node
$role = (Select-Xml -Xml $roles -XPath "Role[@Name='$roleName']").Node
if ($role) {
if ($roleUrl) { #We may only be setting properties
$role.setAttribute("Url", $roleUrl)
}
} else {
$role = $roles.OwnerDocument.CreateElement('Role')
$roles.AppendChild($role)
$role.SetAttribute("Name", $roleName)
if ($roleUrl) {
$role.SetAttribute("Url", $roleUrl)
}
}
# <Role Name="DeployerCapability" Url="${deployerurl:-http://localhost:8084/httpupload}">
# <Property Name="encoding" Value="UTF-8" />
# </Role>
#REVIEW: This could be more robust in the scenario where the specified property already exists
if ($roleProperties) {
$roleProperties.Keys | % {
$property = $role.OwnerDocument.CreateElement('Property')
$role.AppendChild($property)
$property.SetAttribute("Name", $_)
$property.SetAttribute("Value", $roleProperties.Item($_))
}
}
$config.Save($storageConfig)