Skip to content

Commit

Permalink
!deploy v2.17.0 with updated psake, functions, and fixes for #102 and #…
Browse files Browse the repository at this point in the history
…103

## 2.17.0

* [Issue #102](#102)
  * Fixed: `$EncryptionKey` PSM1 parameter now stores the AES key correctly so SecureStrings are encrypted/decrypted as intended.
* [Issue #103](#103)
  * Updated: `SendNotificationEmail` parameter on `Add-GSDrivePermission` defaults to false for all User & Group permissions that are not ownership transfers.
  * Updated: Documentation for `SendNotificationEmail` parameter on `Add-GSDrivePermission` for clarity towards default Google API parameter values.
* Added: More unit testing for `Get-GSUser`
* Updated: `psake` build script
  • Loading branch information
scrthq authored Oct 23, 2018
2 parents c49cab9 + 3a9aecb commit df5e72e
Show file tree
Hide file tree
Showing 21 changed files with 305 additions and 183 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
TestPad.ps1
**TestPad.ps1
**-PSGSuite.xml
**.insyncdl
.vscode
Expand Down
8 changes: 3 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,17 @@ notifications:
on_failure: always
on_start: always
before_install:
- chmod +x ci/download.sh
- chmod +x pwsh_download.sh
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; brew install openssl; brew
install python3; mkdir -p /usr/local/lib; ln -s /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib
/usr/local/lib/; ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/;
fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get -y install python3; nvm
install v6.0.0; fi
install:
- pushd ci
- "./download.sh"
- popd
- ./pwsh_download.sh
before_script:
- export PATH=~/.local/bin:$PATH
script:
- ulimit -n 4096
- pwsh -File ci/init.ps1
- pwsh -File build.ps1
16 changes: 14 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Changelog

* [2.17.0](#2170)
* [2.16.1](#2161)
* [2.16.0](#2160)
* [2.15.4](#2154)
* [2.15.3](#2153)
Expand Down Expand Up @@ -51,13 +53,23 @@
* [Functions Removed](#functions-removed)
* [Functions Aliased](#functions-aliased)

## 2.17.0

* [Issue #102](https://github.com/scrthq/PSGSuite/issues/102)
* Fixed: `$EncryptionKey` PSM1 parameter now stores the AES key correctly so SecureStrings are encrypted/decrypted as intended.
* [Issue #103](https://github.com/scrthq/PSGSuite/issues/103)
* Updated: `SendNotificationEmail` parameter on `Add-GSDrivePermission` defaults to false for all User & Group permissions that are not ownership transfers.
* Updated: Documentation for `SendNotificationEmail` parameter on `Add-GSDrivePermission` for clarity towards default Google API parameter values.
* Added: More unit testing for `Get-GSUser`
* Updated: `psake` build script

## 2.16.1

- Fixed: Module deployment segment in psake script deploying decompiled/broken module
* Fixed: Module deployment segment in psake script deploying decompiled/broken module

## 2.16.0

- Updated: Build script to compile module into a single PSM1 file for cleanliness and loading speed improvements
* Updated: Build script to compile module into a single PSM1 file for cleanliness and loading speed improvements

## 2.15.4

Expand Down
4 changes: 2 additions & 2 deletions DebugMode.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

# Enable Debug Mode to export the New-GoogleService function during module import
# by setting the environment variable '$env:EnablePSGSuiteDebug' to $true
$env:EnablePSGSuiteDebug = $true
$env:EnablePSGSuiteDebug = $false

Get-Module PSGSuite | Remove-Module -Force

. ([System.IO.Path]::Combine("$PSScriptRoot","ci","init.ps1")) -Task Compile
. .\build.ps1 -Task Compile

# Force import the module in the repo path so that updated functions are reloaded
$modulePath = [System.IO.Path]::Combine("$PSScriptRoot","out","PSGSuite")
Expand Down
2 changes: 1 addition & 1 deletion PSGSuite/PSGSuite.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'PSGSuite.psm1'

# Version number of this module.
ModuleVersion = '2.16.1'
ModuleVersion = '2.17.0'

# ID used to uniquely identify this module
GUID = '9d751152-e83e-40bb-a6db-4c329092aaec'
Expand Down
21 changes: 8 additions & 13 deletions PSGSuite/PSGSuite.psm1
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
Param
(
[parameter(Position = 0)]
[System.Byte[]]
$EncryptionKey = $(if (Get-Command Import-SCRTKey -ErrorAction SilentlyContinue) {
Import-SCRTKey
}
else {
$null
}),
[parameter(Position = 0,ValueFromRemainingArguments = $true)]
[AllowNull()]
[Byte[]]
$EncryptionKey = $null,
[parameter(Position = 1)]
[string]
$ConfigName = $null
[AllowNull()]
[String]
$ConfigName
)
#Get public and private function definition files.
$Public = @(Get-ChildItem -Recurse -Path $PSScriptRoot\Public\*.ps1 -ErrorAction SilentlyContinue)
$Private = @(Get-ChildItem -Recurse -Path $PSScriptRoot\Private\*.ps1 -ErrorAction SilentlyContinue)
$ModuleRoot = $PSScriptRoot
New-Variable -Name PSGSuiteKey -Value $EncryptionKey -Scope Global -Force -PassThru
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@ function Get-GSToken {
[ValidateNotNullOrEmpty()]
[string[]]
$Scopes,
[parameter(Mandatory = $false,HelpMessage = "What is the full path to your Google Service Account's P12 key file?")]
[parameter(Mandatory = $false)]
[Alias('User')]
[ValidateNotNullOrEmpty()]
[String]
$P12KeyPath = $Script:PSGSuite.P12KeyPath,
$AdminEmail = $Script:PSGSuite.AdminEmail,
[parameter(Mandatory = $false)]
[ValidateNotNullOrEmpty()]
[String]
$AppEmail = $Script:PSGSuite.AppEmail,
[parameter(Mandatory = $false)]
[ValidateNotNullOrEmpty()]
[String]
$AdminEmail = $Script:PSGSuite.AdminEmail
$P12KeyPath = $Script:PSGSuite.P12KeyPath
)
function Invoke-URLEncode ($Object) {
([String]([System.Convert]::ToBase64String($Object))).TrimEnd('=').Replace('+','-').Replace('/','_')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ function New-GoogleService {
[String]
$ServiceType,
[Parameter(Mandatory = $false,Position = 2)]
[Alias('AdminEmail')]
[String]
$User = $script:PSGSuite.AdminEmail
)
Expand Down Expand Up @@ -49,4 +50,4 @@ function New-GoogleService {
$PSCmdlet.ThrowTerminatingError($_)
}
}
}
}
59 changes: 38 additions & 21 deletions PSGSuite/Public/Drive/Add-GSDrivePermission.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ function Add-GSDrivePermission {
<#
.SYNOPSIS
Adds a new permission to a Drive file
.DESCRIPTION
Adds a new permission to a Drive file
.PARAMETER User
The owner of the Drive file
Defaults to the AdminEmail user
.PARAMETER FileId
The unique Id of the Drive file you would like to add the permission to
.PARAMETER Role
The role/permission set you would like to give the email $EmailAddress
Expand All @@ -23,7 +23,7 @@ function Add-GSDrivePermission {
* "Commenter"
* "Reader"
* "Organizer"
.PARAMETER Type
The type of the grantee
Expand All @@ -32,36 +32,42 @@ function Add-GSDrivePermission {
* "Group": a group email
* "Domain": the entire domain
* "Anyone": public access
.PARAMETER EmailAddress
The email address of the user or group to which this permission refers
.PARAMETER Domain
The domain to which this permission refers
.PARAMETER ExpirationTime
The time at which this permission will expire.
Expiration times have the following restrictions:
The time at which this permission will expire.
Expiration times have the following restrictions:
* They can only be set on user and group permissions
* The time must be in the future
* The time cannot be more than a year in the future
* The time cannot be more than a year in the future
.PARAMETER EmailMessage
A plain text custom message to include in the notification email
.PARAMETER SendNotificationEmail
Whether to send a notification email when sharing to users or groups. This defaults to true for users and groups, and is not allowed for other requests. It must not be disabled for ownership transfers
Whether to send a notification email when sharing to users or groups.
This defaults to **FALSE** for users and groups in PSGSuite, and is not allowed for other requests.
**It must not be disabled for ownership transfers**
.PARAMETER AllowFileDiscovery
Whether the permission allows the file to be discovered through search. This is only applicable for permissions of type domain or anyone
Whether the permission allows the file to be discovered through search.
This is only applicable for permissions of type domain or anyone
.PARAMETER TransferOwnership
Confirms transfer of ownership if the Role is set to 'Owner'. You can also force the same behavior by passing -Confirm:$false instead
.PARAMETER UseDomainAdminAccess
Whether the request should be treated as if it was issued by a domain administrator; if set to true, then the requester will be granted access if they are an administrator of the domain to which the item belongs
.EXAMPLE
Add-GSDrivePermission -FileId "1rhsAYTOB_vrpvfwImPmWy0TcVa2sgmQa_9u976" -Role Owner -Type User -EmailAddress joe -SendNotificationEmail -Confirm:$false
Expand Down Expand Up @@ -165,6 +171,14 @@ function Add-GSDrivePermission {
Type {
$body.$key = ($PSBoundParameters[$key]).ToLower()
}
SendNotificationEmail {
if ($PSBoundParameters[$key]) {
$body.$key = $PSBoundParameters[$key]
}
else {
$body.$key = $false
}
}
Default {
if ($body.PSObject.Properties.Name -contains $key) {
$body.$key = $PSBoundParameters[$key]
Expand All @@ -179,6 +193,9 @@ function Add-GSDrivePermission {
$request.$key = $PSBoundParameters[$key]
}
}
if ($PSBoundParameters.Keys -notcontains 'SendNotificationEmail') {
$request.SendNotificationEmail = $false
}
Write-Verbose "Adding Drive Permission of '$Role' for user '$EmailAddress' on Id '$FileID'"
$request.Execute() | Add-Member -MemberType NoteProperty -Name 'User' -Value $User -PassThru
}
Expand All @@ -191,4 +208,4 @@ function Add-GSDrivePermission {
}
}
}
}
}
4 changes: 2 additions & 2 deletions PSGSuite/Public/Users/Get-GSUser.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ function Get-GSUser {
if ($Fields) {
$request.Fields = "$($Fields -join ",")"
}
$request.Execute() | Add-Member -MemberType NoteProperty -Name 'User' -Value $U -PassThru | Add-Member -MemberType ScriptMethod -Name ToString -Value {$this.PrimaryEmail} -PassThru -Force
$request.Execute() | Add-Member -MemberType NoteProperty -Name 'User' -Value $U -Force -PassThru | Add-Member -MemberType ScriptMethod -Name ToString -Value {$this.PrimaryEmail} -PassThru -Force
}
catch {
if ($ErrorActionPreference -eq 'Stop') {
Expand Down Expand Up @@ -247,7 +247,7 @@ function Get-GSUser {
$result = $request.Execute()
if ($result.UsersValue) {
$result.UsersValue | ForEach-Object {
$_ | Add-Member -MemberType NoteProperty -Name 'User' -Value $_.PrimaryEmail -PassThru | Add-Member -MemberType ScriptMethod -Name ToString -Value {$this.PrimaryEmail} -Force
$_ | Add-Member -MemberType NoteProperty -Name 'User' -Value $_.PrimaryEmail -Force -PassThru | Add-Member -MemberType ScriptMethod -Name ToString -Value {$this.PrimaryEmail} -Force
[void]$response.Add($_)
}
}
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,17 @@ Update-GSSheetValue Export-GSSheet

### Most recent changes

#### 2.17.0

* [Issue #102](https://github.com/scrthq/PSGSuite/issues/102)
* Fixed: `$EncryptionKey` PSM1 parameter now stores the AES key correctly so SecureStrings are encrypted/decrypted as intended.
* [Issue #103](https://github.com/scrthq/PSGSuite/issues/103)
* Updated: `SendNotificationEmail` parameter on `Add-GSDrivePermission` defaults to false for all User & Group permissions that are not ownership transfers.
* Updated: Documentation for `SendNotificationEmail` parameter on `Add-GSDrivePermission` for clarity towards default Google API parameter values.
* Moved: `Get-GSToken` and `New-GoogleService` to Public functions under the Authentication section
* Added: More unit testing for `Get-GSUser`
* Updated: `psake` build script

#### 2.16.1

- Fixed: Module deployment segment in psake script deploying decompiled/broken module
Expand Down
89 changes: 89 additions & 0 deletions Tests/Mocks/Users.Mocks.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
Mock 'New-GoogleService' -ModuleName PSGSuite -ParameterFilter {$ServiceType -eq 'Google.Apis.Admin.Directory.directory_v1.DirectoryService'} -MockWith {
Write-Verbose "Mocking New-GoogleService for ServiceType '$ServiceType'"
$o = New-Object PSObject -Property @{Users = [PSCustomObject]@{};ApplicationName = ""}
$o.Users | Add-Member -Force -MemberType ScriptMethod -Name List -Value {
New-Object -TypeName PSObject -Property @{
Projection = ""
Domain = ""
Customer = ""
MaxResults = ""
OrderBy = ""
SortOrder = ""
CustomFieldMask = ""
ShowDeleted = $false
ViewType = ""
Query = ""
PageToken = ""
} | Add-Member -MemberType ScriptMethod -Name Execute -Value {
$userList = @()
1..2 | ForEach-Object {
$userList += New-Object 'Google.Apis.Admin.Directory.directory_v1.Data.User' -Property @{
PrimaryEmail = "user$($_)@domain.com"
OrgUnitPath = "/Users/$_"
}
foreach ($sub in (1..2)) {
$userList += New-Object 'Google.Apis.Admin.Directory.directory_v1.Data.User' -Property @{
PrimaryEmail = "user$($_).$($sub)@domain.com"
OrgUnitPath = "/Users/$_/$sub"
}
}
}
$userList += New-Object 'Google.Apis.Admin.Directory.directory_v1.Data.User' -Property @{
PrimaryEmail = "admin@domain.com"
OrgUnitPath = "/Users"
}
if ( -not [String]::IsNullOrEmpty($this.Query)) {
$filter = $this.Query.Trim()
$left = $filter.Split('=',2)[1].Trim()
$right = $filter.Split('=',2)[2].Trim("'")
$filtered = $userList | Where-Object {$_.$left -like "$right*"}
return ([PSCustomObject]@{
UsersValue = $filtered
})
}
else {
return ([PSCustomObject]@{
UsersValue = $userList
})
}
} -Force -PassThru
}
$o.Users | Add-Member -Force -MemberType ScriptMethod -Name Get -Value {
Process {
$UserKey = $args[0]
New-Object -TypeName PSObject -Property @{
Projection = ""
Domain = ""
Customer = ""
MaxResults = ""
OrderBy = ""
SortOrder = ""
CustomFieldMask = ""
ViewType = ""
Fields = ""
UserKey = $UserKey
} | Add-Member -MemberType ScriptMethod -Name Execute -Value {
$userList = @()
1..2 | ForEach-Object {
$userList += New-Object 'Google.Apis.Admin.Directory.directory_v1.Data.User' -Property @{
PrimaryEmail = "user$($_)@domain.com"
OrgUnitPath = "/Users/$_"
}
foreach ($sub in (1..2)) {
$userList += New-Object 'Google.Apis.Admin.Directory.directory_v1.Data.User' -Property @{
PrimaryEmail = "user$($_).$($sub)@domain.com"
OrgUnitPath = "/Users/$_/$sub"
}
}
}
if ($userFound = $userList | Where-Object {$_.PrimaryEmail -eq $this.UserKey}) {
return $userFound
}
else {
Write-Error "User not found!"
}
} -Force -PassThru
}
}
return $o
}
Loading

0 comments on commit df5e72e

Please sign in to comment.