Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Test/include/config.mock.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

$CONFIG_INVOKE_GET_ROOT_PATH_CMD = "Invoke-SfGetConfigRootPath"

function Mock_Config{
param(
Expand All @@ -23,6 +24,6 @@ function Mock_Config{
}

# Mock invoke call
MockCallToString "Invoke-GetConfigRootPath" -OutString $MOCK_CONFIG_PATH
MockCallToString $CONFIG_INVOKE_GET_ROOT_PATH_CMD -OutString $MOCK_CONFIG_PATH

}
5 changes: 4 additions & 1 deletion Test/include/database.mock.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

$DB_INVOKE_GET_ROOT_PATH_CMD = "Invoke-SfGetDbRootPath"

function Mock_Database([switch]$ResetDatabase){

MockCallToString "Invoke-GetDatabaseStorePath" -OutString "test_database_path"
MockCallToString $DB_INVOKE_GET_ROOT_PATH_CMD -OutString "test_database_path"

if($ResetDatabase){
Reset-DatabaseStore
Expand Down
2 changes: 1 addition & 1 deletion Test/public/sfDataQuery.test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function Test_GetSfAccount{
$mockAttrib = @{attributes = @("Potential_Seats_Manual__c","Website","PhotoUrl")}
Mock_Config -Config $mockAttrib

$dbstore = Invoke-MyCommand -Command GetDatabaseStorePath
$dbstore = Invoke-MyCommand -Command $DB_INVOKE_GET_ROOT_PATH_CMD
Assert-AreEqual -Expected "test_database_path" -Presented $dbstore

$attrib = "Id,Name,OwnerId,Industry,Account_Owner__c,Account_Segment__c,Account_Owner_Role__c,Account_Tier__c,Potential_Seats__c,Country_Name__c,Current_Seats__c,Current_ARR_10__c,Salesforce_Record_URL__c,Potential_Seats_Manual__c,Website,PhotoUrl"
Expand Down
33 changes: 29 additions & 4 deletions include/config.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
# Configuration management module

Set-MyInvokeCommandAlias -Alias GetConfigRootPath -Command "Invoke-GetConfigRootPath"
# Include design description
# This is the function ps1. This file is the same for all modules.
# Create a public psq with variables, Set-MyInvokeCommandAlias call and Invoke public function.
# Invoke function will call back `GetConfigRootPath` to use production root path
# Mock this Invoke function with Set-MyInvokeCommandAlias to set the Store elsewhere
# This ps1 has function `GetConfigFile` that will call `Invoke-MyCommand -Command $CONFIG_INVOKE_GET_ROOT_PATH_ALIAS`
# to use the store path, mocked or not, to create the final store file name.
# All functions of this ps1 will depend on `GetConfigFile` for functionality.
#
# TODO : Create a related public ps1

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace

# Create a related public ps1

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
# 1. define $CONFIG_INVOKE_GET_ROOT_PATH_ALIAS. Make it unique.
# 2. define $CONFIG_INVOKE_GET_ROOT_PATH_CMD. Point to the invoke function that calls GetConfigRootPath to get the store path
#
# Sample code (replace "MyModule" with a unique module prefix):
# $CONFIG_INVOKE_GET_ROOT_PATH_ALIAS = "MyModuleGetConfigRootPath"
# $CONFIG_INVOKE_GET_ROOT_PATH_CMD = "Invoke-MyModuleGetConfigRootPath"
#

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
# Set-MyInvokeCommandAlias -Alias $CONFIG_INVOKE_GET_ROOT_PATH_ALIAS -Command $CONFIG_INVOKE_GET_ROOT_PATH_CMD
#

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
# function Invoke-MyModuleGetConfigRootPath{
# $configRoot = GetConfigRootPath
# return $configRoot
# } Export-ModuleMember -Function Invoke-MyModuleGetConfigRootPath


$moduleName = Get-ModuleName
$CONFIG_ROOT = [System.Environment]::GetFolderPath('UserProfile') | Join-Path -ChildPath ".helpers" -AdditionalChildPath $moduleName, "config"
Expand All @@ -10,21 +35,21 @@
New-Item -Path $CONFIG_ROOT -ItemType Directory
}

function Invoke-GetConfigRootPath {
function GetConfigRootPath {
[CmdletBinding()]
param()

$configRoot = $CONFIG_ROOT
return $configRoot
} Export-ModuleMember -Function Invoke-GetConfigRootPath
}

function GetConfigFile {
[CmdletBinding()]
param(
[Parameter(Mandatory = $true, Position = 0)][string]$Key
)

$configRoot = Invoke-MyCommand -Command GetConfigRootPath
$configRoot = Invoke-MyCommand -Command $CONFIG_INVOKE_GET_ROOT_PATH_ALIAS
$path = Join-Path -Path $configRoot -ChildPath "$Key.json"
return $path
}
Expand Down
77 changes: 41 additions & 36 deletions private/dependencies/databaseV2.ps1 → include/databaseV2.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,34 @@
# Database driver to store the cache

# Include design description
# This is the function ps1. This file is the same for all modules.
# Create a public psq with variables, Set-MyInvokeCommandAlias call and Invoke public function.
# Invoke function will call back `GetDatabaseRootPath` to use production root path
# Mock this Invoke function with Set-MyInvokeCommandAlias to set the Store elsewhere
# This ps1 has function `GetDatabaseFile` that will call `Invoke-MyCommand -Command $DB_INVOKE_GET_ROOT_PATH_ALIAS`
# to use the store path, mocked or not, to create the final store file name.
# All functions of this ps1 will depend on `GetDatabaseFile` for functionality.
#
# TODO : Create a related public ps1
# 1. define $DB_INVOKE_GET_ROOT_PATH_ALIAS. Make it unique.
# 2. define $DB_INVOKE_GET_ROOT_PATH_CMD. Point to the invoke function that calls GetConfigRootPath to get the store path
#
# Sample code (replace "MyModule" with a unique module prefix):
# $DB_INVOKE_GET_ROOT_PATH_ALIAS = "SfGetDbRootPath"
# $DB_INVOKE_GET_ROOT_PATH_CMD = "Invoke-SfGetDbRootPath"
#
# Set-MyInvokeCommandAlias -Alias $DB_INVOKE_GET_ROOT_PATH_ALIAS -Command $DB_INVOKE_GET_ROOT_PATH_CMD
#

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
# function Invoke-SfGetDbRootPath{
# [CmdletBinding()]
# param()
#

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
# $databaseRoot = GetDatabaseRootPath
# return $databaseRoot
#

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
# } Export-ModuleMember -Function Invoke-SfGetDbRootPath

# Invoke to allow mockig the store path on testing
Set-MyInvokeCommandAlias -Alias GetDatabaseStorePath -Command "Invoke-GetDatabaseStorePath"

$moduleName = Get-ModuleName
$DATABASE_ROOT = [System.Environment]::GetFolderPath('UserProfile') | Join-Path -ChildPath ".helpers" -AdditionalChildPath $moduleName, "databaseCache"
Expand All @@ -11,27 +38,26 @@
New-Item -Path $DATABASE_ROOT -ItemType Directory
}

function Reset-DatabaseStore{
function GetDatabaseRootPath {
[CmdletBinding()]
param()

$databaseRoot = Invoke-MyCommand -Command GetDatabaseStorePath

Remove-Item -Path $databaseRoot -Recurse -Force -ErrorAction SilentlyContinue

New-Item -Path $databaseRoot -ItemType Directory

} Export-ModuleMember -Function Reset-DatabaseStore
$databaseRoot = $DATABASE_ROOT
return $databaseRoot
}

function Get-DatabaseStore{
function GetDatabaseFile{
[CmdletBinding()]
param()
param(
[Parameter(Position = 0)][string]$Key
)

$databaseRoot = Invoke-MyCommand -Command GetDatabaseStorePath
return $databaseRoot
$databaseRoot = Invoke-MyCommand -Command $DB_INVOKE_GET_ROOT_PATH_ALIAS

$path = $databaseRoot | Join-Path -ChildPath "$Key.json"

} Export-ModuleMember -Function Get-DatabaseStore
return $path
}

function Get-Database{
[CmdletBinding()]
Expand Down Expand Up @@ -90,24 +116,3 @@
return $true
}

function GetDatabaseFile{
[CmdletBinding()]
param(
[Parameter(Position = 0)][string]$Key
)

$databaseRoot = Invoke-MyCommand -Command GetDatabaseStorePath

$path = $databaseRoot | Join-Path -ChildPath "$Key.json"

return $path
}

function Invoke-GetDatabaseStorePath{
[CmdletBinding()]
param()

$databaseRoot = $DATABASE_ROOT

return $databaseRoot
} Export-ModuleMember -Function Invoke-GetDatabaseStorePath
28 changes: 28 additions & 0 deletions public/sfDatabase.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@


$DB_INVOKE_GET_ROOT_PATH_ALIAS = "SfGetDbRootPath"
$DB_INVOKE_GET_ROOT_PATH_CMD = "Invoke-SfGetDbRootPath"

Set-MyInvokeCommandAlias -Alias $DB_INVOKE_GET_ROOT_PATH_ALIAS -Command $DB_INVOKE_GET_ROOT_PATH_CMD

function Invoke-SfGetDbRootPath{

Check notice

Code scanning / PSScriptAnalyzer

The cmdlet 'Invoke-SfGetDbRootPath' does not have a help comment. Note

The cmdlet 'Invoke-SfGetDbRootPath' does not have a help comment.
[CmdletBinding()]
param()

$databaseRoot = GetDatabaseRootPath
return $databaseRoot

} Export-ModuleMember -Function Invoke-SfGetDbRootPath


function Reset-DatabaseStore{

Check notice

Code scanning / PSScriptAnalyzer

The cmdlet 'Reset-DatabaseStore' does not have a help comment. Note

The cmdlet 'Reset-DatabaseStore' does not have a help comment.

Check warning

Code scanning / PSScriptAnalyzer

Function 'Reset-DatabaseStore' has verb that could change system state. Therefore, the function has to support 'ShouldProcess'. Warning

Function 'Reset-DatabaseStore' has verb that could change system state. Therefore, the function has to support 'ShouldProcess'.
[CmdletBinding()]
param()

$databaseRoot = Invoke-MyCommand -Command $DB_INVOKE_GET_ROOT_PATH_ALIAS

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
Remove-Item -Path $databaseRoot -Recurse -Force -ErrorAction SilentlyContinue

New-Item -Path $databaseRoot -ItemType Directory

} Export-ModuleMember -Function Reset-DatabaseStore
74 changes: 74 additions & 0 deletions public/sfconfig.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@

$CONFIG_INVOKE_GET_ROOT_PATH_ALIAS = "SfGetConfigRootPath"
$CONFIG_INVOKE_GET_ROOT_PATH_CMD = "Invoke-SfGetConfigRootPath"

Set-MyInvokeCommandAlias -Alias $CONFIG_INVOKE_GET_ROOT_PATH_ALIAS -Command $CONFIG_INVOKE_GET_ROOT_PATH_CMD

function Invoke-SfGetConfigRootPath{

Check notice

Code scanning / PSScriptAnalyzer

The cmdlet 'Invoke-SfGetConfigRootPath' does not have a help comment. Note

The cmdlet 'Invoke-SfGetConfigRootPath' does not have a help comment.
$configRoot = GetConfigRootPath
return $configRoot
} Export-ModuleMember -Function Invoke-SfGetConfigRootPath


function Get-SfConfig{

Check notice

Code scanning / PSScriptAnalyzer

The cmdlet 'Get-SfConfig' does not have a help comment. Note

The cmdlet 'Get-SfConfig' does not have a help comment.
[CmdletBinding()]
param()

$config = Get-Configuration

return $config
} Export-ModuleMember -Function Get-SfConfig

function Save-SfConfig{

Check notice

Code scanning / PSScriptAnalyzer

The cmdlet 'Save-SfConfig' does not have a help comment. Note

The cmdlet 'Save-SfConfig' does not have a help comment.
[CmdletBinding()]
param(
[Parameter(Mandatory, ValueFromPipeline, Position = 0)][Object]$Config

Check warning

Code scanning / PSScriptAnalyzer

Command accepts pipeline input but has not defined a process block. Warning

Command accepts pipeline input but has not defined a process block.
)

return Save-Configuration -Config $Config
} Export-ModuleMember -Function Save-SfConfig

function Open-SfConfig{

Check notice

Code scanning / PSScriptAnalyzer

The cmdlet 'Open-SfConfig' does not have a help comment. Note

The cmdlet 'Open-SfConfig' does not have a help comment.
[CmdletBinding()]
param()

$path = GetConfigFile -Key "config"

code $path

} Export-ModuleMember -Function Open-SfConfig

function Add-SfConfigAttribute{

Check notice

Code scanning / PSScriptAnalyzer

The cmdlet 'Add-SfConfigAttribute' does not have a help comment. Note

The cmdlet 'Add-SfConfigAttribute' does not have a help comment.
[CmdletBinding()]
param(
[Parameter(Mandatory, ValueFromPipeline, Position = 0)][string]$Attribute
)

begin{
$config = Get-Configuration

if(-Not $config){
$config = @{}
}

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
if(-Not $config.attributes){
$config.attributes = @()
}
}

process{
$config.attributes += $Attribute
}

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
End{
$ret = Save-Configuration -Config $config
if(-Not $ret){
throw "Error saving configuration"
}

$config = Get-SfConfig
Write-Output $config.attributes

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
}

} Export-ModuleMember -Function Add-SfConfigAttribute
Loading