This repository was archived by the owner on Jun 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathGenerateCodeGovJson.ps1
More file actions
91 lines (67 loc) · 3.5 KB
/
GenerateCodeGovJson.ps1
File metadata and controls
91 lines (67 loc) · 3.5 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
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
81
82
83
84
85
86
87
88
89
90
91
Set-StrictMode -Version 3
Import-Module -Name CodeGov
Function Invoke-CodeGov() {
[OutputType([void])]
[CmdletBinding()]
Param (
[Parameter(Mandatory=$true, HelpMessage='A GitHub personal access OAuth token')]
[ValidateNotNullOrEmpty()]
[string]$UnprocessedJsonPath,
[Parameter(Mandatory=$true, HelpMessage='Path to store a temporary code.json file')]
[ValidateNotNullOrEmpty()]
[string]$ProcessedJsonPath,
[Parameter(Mandatory=$true, HelpMessage='A GitHub personal access OAuth token')]
[ValidateNotNullOrEmpty()]
[string]$OverridesJsonPath,
[Parameter(Mandatory=$true, HelpMessage='Organization properties for the code.json file')]
[ValidateNotNullOrEmpty()]
[object]$Properties,
[Parameter(Mandatory=$false, HelpMessage='Validate code.json file')]
[switch]$Validate
)
New-CodeGovJsonFile -Organization $Properties.Organization -AgencyName $Properties.AgencyName -AgencyContactEmail $Properties.AgencyContactEmail -AgencyContactName $Properties.AgencyContactName -AgencyContactUrl $Properties.AgencyContactUrl -AgencyContactPhone $Properties.AgencyContactPhone -Path $UnprocessedJsonPath
Invoke-CodeGovJsonOverride -OriginalJsonPath $UnprocessedJsonPath -NewJsonPath $ProcessedJsonPath -OverrideJsonPath $OverridesJsonPath
if($Validate) {
$valid = Test-CodeGovJsonFile -Path $ProcessedJsonPath
if(-not($valid)) {
throw "$ProcessedJsonPath does not validate against the code.gov schema"
}
}
}
Set-OAuthToken -Token 'insertgithubapitokenhere'
$tempPath = "$env:userprofile\Desktop"
$siteBasePath = "$env:userprofile\Documents\GitHub\nsacyber.github.io"
$codeGovPath = "$siteBasePath\codegov"
$nsaCyberProperties = [pscustomobject]@{
Organization = 'nsacyber';
AgencyName = 'NSA Cybersecurity';
AgencyContactEmail = 'cybersecurity_requests@nsa.gov';
AgencyContactName = 'NSA Cybersecurity';
AgencyContactUrl = 'https://www.nsa.gov/about/contact-us/';
AgencyContactPhone = '410-854-4200';
}
Invoke-CodeGov -UnprocessedJsonPath "$tempPath\nsacyber-code.json" -ProcessedJsonPath "$codeGovPath\nsacyber-code.json" -OverridesJsonPath "$codeGovPath\nsacyber-overrides.json" -Properties $nsaCyberProperties
$nsaProperties = [pscustomobject]@{
Organization = 'NationalSecurityAgency';
AgencyName = 'National Security Agency';
AgencyContactEmail = 'tech_transfer@nsa.gov';
AgencyContactName = 'NSA Technology Transfer Program';
AgencyContactUrl = 'https://www.nsa.gov/what-we-do/research/technology-transfer/';
AgencyContactPhone = '1-866-680-4539';
}
Invoke-CodeGov -UnprocessedJsonPath "$tempPath\nsa-code.json" -ProcessedJsonPath "$codeGovPath\nsa-code.json" -OverridesJsonPath "$codeGovPath\nsa-overrides.json" -Properties $nsaProperties
$nsaCyberJson = Get-Content -Path "$codeGovPath\nsacyber-code.json" | ConvertFrom-Json
$nsaJson = Get-Content -Path "$codeGovPath\nsa-code.json" | ConvertFrom-Json
$releases = @()
$releases += [pscustomobject]($nsaCyberJson.releases)
$releases += [pscustomobject]($nsaJson.releases)
$measurementType = [pscustomobject]@{
'method' = 'projects';
}
$codeGov = [pscustomobject][ordered]@{
'version' = '2.0'; # required
'agency' = 'NSA'; # required
'measurementType' = $measurementType; # required
'releases' = $releases | Sort-Object -Property 'Name'; # required
}
$codeGov | ConvertTo-Json -Depth 5 | Out-File -FilePath "$siteBasePath\code.json" -Force -NoNewline -Encoding 'ASCII'