forked from 1RedOne/PSReddit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PSReddit.psm1
56 lines (43 loc) · 1.81 KB
/
PSReddit.psm1
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
[CmdletBinding()]
#Get public and private function definition files.
$PublicFunction = @( Get-ChildItem -Path $PSScriptRoot\Public\*.ps1 -Exclude *tests* -ErrorAction SilentlyContinue )
$PrivateFunction = @( Get-ChildItem -Path $PSScriptRoot\Private\*.ps1 -Exclude *tests* -ErrorAction SilentlyContinue )
#Dot source the files
Foreach($import in @($PublicFunction + $PrivateFunction))
{
write-verbose "importing $import"
Try
{
. $import.fullname
}
Catch
{
Write-Error -Message "Failed to import function $($import.fullname): $_"
}
}
#Initialize our variables. I know, I know...
$configDir = "$Env:AppData\WindowsPowerShell\Modules\PSReddit\0.1\Config.ps1xml"
$refreshToken = "$Env:AppData\WindowsPowerShell\Modules\PSReddit\0.1\Config.Refresh.ps1xml"
Try
{
#Import the config
$password = Import-Clixml -Path $configDir -ErrorAction STOP | ConvertTo-SecureString
}
catch {
Write-Warning "Corrupt Password file found, rerun with -Force to fix this"
}
Try
{
#Import the config
$refreshToken = Import-Clixml -Path $refreshToken -ErrorAction STOP | ConvertTo-SecureString
}
catch {
Write-Warning "Corrupt refresh token file found, rerun with -Force to fix this"
}
if ($password){Get-DecryptedValue -inputObj $password -name PSReddit_accessToken}
if($refreshToken){Get-DecryptedValue -inputObj $refreshToken -name PSReddit_refreshToken}
# Here I might...
# Read in or create an initial config file and variable
# Export Public functions ($Public.BaseName) for WIP modules
# Set variables visible to the module and its functions only
Export-ModuleMember -Function $PublicFunction.Basename