-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimport-sample.ps1
80 lines (67 loc) · 2.33 KB
/
import-sample.ps1
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
Param(
[Parameter(Mandatory = $false)]
[string]$TargetRepo,
[Parameter(Mandatory = $false)]
[string]$TargetClientId,
[Parameter(Mandatory = $false)]
[string]$TargetClientSecret,
[Parameter(Mandatory = $false)]
[string]$SourcePath = "/Root",
[Parameter(Mandatory = $false)]
[string]$TargetPath = "/",
[Parameter(Mandatory = $false)]
[string]$PATFile = ".\settings\secret-local.json",
[Parameter(Mandatory = $false)]
[string]$execFile = ".\tools\SnIO.exe",
[Parameter(Mandatory = $false)]
[bool]$CtdOnly = $False,
[Parameter(Mandatory = $false)]
[bool]$PrepareTool = $False
)
# install snio tool
if ($PrepareTool -or -not (Test-Path $execFile -PathType Leaf)) {
.\scripts\install-snio.ps1
}
# PATFile format
# {
# "repositorywriter": {
# "url": "http://example.cloud",
# "authentication": {
# "clientid": "your_client_id_here",
# "clientsecret": "your_client_secret_here"
# }
# }
# }
if ($PATFile -and -not (Test-Path $PATFile -PathType Leaf)) {
$PATFile = $null
}
# if PATFile is set, read json with client and secret from file
if ($PATFile) {
Write-Output "Loading configuration from $PATFile..."
$PAT = Get-Content $PATFile | ConvertFrom-Json
if (-not $TargetRepo) { $TargetRepo = $PAT.repositorywriter.url }
if (-not $TargetClientId) { $TargetClientId = $PAT.repositorywriter.authentication.clientid }
if (-not $TargetClientSecret) { $TargetClientSecret = $PAT.repositorywriter.authentication.clientsecret }
} else {
Write-Output "No config file provided."
}
# content structure
if ($SourcePath -like "/Root*") {
$SourcePath = Join-Path "./package" $SourcePath
}
$RawPath = $SourcePath
if ($CtdOnly) {
# currently CTDs can be loadon only from the local folder
$RawPath = "./package/Root/System/Schema/ContentTypes"
$TargetPath = "/Root/System/Schema"
}
$SourcePath = Resolve-Path -Path $RawPath
# .\tools\SnIO.exe IMPORT --DISPLAY:LEVEL Verbose `
# -SOURCE -PATH $SourcePath `
# -TARGET $TargetRepo -PATH $TargetPath -CLIENTID $TargetClientId -CLIENTSECRET $TargetClientSecret
$params = "IMPORT", "--DISPLAY:LEVEL", "Verbose", "eol",
"-SOURCE", "-PATH", $SourcePath, "eol",
"-TARGET", $TargetRepo, "-PATH", $TargetPath, "eol",
"-CLIENTID", $TargetClientId, "-CLIENTSECRET", $TargetClientSecret
Write-Output "$execFile $($params -replace "eol", "$($eolChar)`r`n`t")"
& $execFile $($params | where-object {$_ -ne "eol"})