Skip to content

Commit

Permalink
Feature: first implementation (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhouthuijzen authored Jul 25, 2024
1 parent 0e37a82 commit d473c5d
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 44 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com), and this project adheres to [Semantic Versioning](https://semver.org).

## [1.1.0] - 25-07-2024

This is the first release after implementation.

## [1.0.0] - 02-06-2024

This is the first official release of _HelloID-Conn-Prov-Target-GoodHabitz_. This release is based on template version _1.2.0_.
Expand Down
31 changes: 17 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
> This repository contains the connector and configuration code only. The implementer is responsible to acquire the connection details such as username, password, certificate, etc. You might even need to sign a contract or agreement with the supplier before implementing this connector. Please contact the client's application manager to coordinate the connector requirements.
<p align="center">
<img src="">
<img src="https://github.com/Tools4everBV/HelloID-Conn-Prov-Target-GoodHabitz/blob/main/Logo.png?raw=true">
</p>

## Table of contents
Expand All @@ -24,29 +24,29 @@

_HelloID-Conn-Prov-Target-GoodHabitz_ is a _target_ connector. _GoodHabitz_ The purpose of this connector is to only delete a person from GoodHabitz using the persons Active Directory email address.

| Endpoint | Description |
| -------- | ----------- |
| /person/forget | Endpoint for removing accounts from GoodHabitz. |
| Endpoint | Description |
| -------------- | ----------------------------------------------- |
| /person/forget | Endpoint for removing accounts from GoodHabitz. |

The following lifecycle actions are available:

| Action | Description |
| ---------------------- | ------------------------------------------------ |
| create.ps1 | PowerShell _create_ lifecycle action |
| delete.ps1 | PowerShell _delete_ lifecycle action |
| configuration.json | Default _configuration.json_ |
| fieldMapping.json | Default _fieldMapping.json_ |
| Action | Description |
| ------------------ | ------------------------------------ |
| create.ps1 | PowerShell _create_ lifecycle action |
| delete.ps1 | PowerShell _delete_ lifecycle action |
| configuration.json | Default _configuration.json_ |
| fieldMapping.json | Default _fieldMapping.json_ |

The field mapping can be imported by using the _fieldMapping.json_ file.

### Connection settings

The following settings are required to connect to the API.

| Setting | Description | Mandatory |
| -------- | ---------------------------------- | --------- |
| ApiKey | The ApiKey to connect to the API | Yes |
| BaseUrl | The URL to the API | Yes |
| Setting | Description | Mandatory |
| ------- | -------------------------------- | --------- |
| ApiKey | The ApiKey to connect to the API | Yes |
| BaseUrl | The URL to the API | Yes |

### Remarks

Expand All @@ -58,6 +58,9 @@ Within the _create_ lifecycle action, the `$outputContext.AccountReference` is s

The purpose of this connector is to __only__ remove an account from GoodHabitz.

> [!IMPORTANT]
> The account will be marked for deletion in Good Habitz. Good Habitz has an internal retention time before the account is deleted. By default, this time is 5 days.
## Getting help

> [!TIP]
Expand Down
6 changes: 3 additions & 3 deletions configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@
"type": "input",
"defaultValue": "",
"templateOptions": {
"type": "password",
"label": "Password",
"type": "password",
"description": "The ApiKey to connect to the API",
"required": true
}
},
{
"key": "BaseUrl",
"type": "input",
"defaultValue": "",
"defaultValue": "https://myengine.goodhabitz.com",
"templateOptions": {
"label": "BaseUrl",
"description": "The URL to the API.",
"required": true
}
}
]
]
8 changes: 4 additions & 4 deletions create.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ try {
Write-Information 'Correlating GoodHabitz account'

$outputContext.AccountReference = $actionContext.Data.EmailAddress
$outputContext.AccountCorrelated = $true
$outputContext.success = $true
$outputContext.AuditLogs.Add([PSCustomObject]@{
Action = 'CorrelateAccount'
Message = "Correlated account on field: [EmailAddress] with value: [$($actionContext.Data.EmailAddress)]"
Message = "Account [$($actionContext.Data.EmailAddress)] successfully correlated on field [EmailAddress]"
IsError = $false
})
}
} catch {
}
catch {
$outputContext.success = $false
Write-Warning "Error at Line '$($_.InvocationInfo.ScriptLineNumber)': $($_.InvocationInfo.Line). Error: $($_.Exception.Message)"
$outputContext.AuditLogs.Add([PSCustomObject]@{
Message = "Could not create or correlate GoodHabitz account. Error: $($_.Exception.Message)"
IsError = $true
})
}
}
56 changes: 34 additions & 22 deletions delete.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,16 @@ function Resolve-GoodHabitzError {
}
if (-not [string]::IsNullOrEmpty($ErrorObject.ErrorDetails.Message)) {
$httpErrorObj.ErrorDetails = $ErrorObject.ErrorDetails.Message
} elseif ($ErrorObject.Exception.GetType().FullName -eq 'System.Net.WebException') {
}
elseif ($ErrorObject.Exception.GetType().FullName -eq 'System.Net.WebException') {
if ($null -ne $ErrorObject.Exception.Response) {
$streamReaderResponse = [System.IO.StreamReader]::new($ErrorObject.Exception.Response.GetResponseStream()).ReadToEnd()
if (-not [string]::IsNullOrEmpty($streamReaderResponse)) {
$httpErrorObj.ErrorDetails = $streamReaderResponse
}
}
}
try {
$errorDetailsObject = ($httpErrorObj.ErrorDetails | ConvertFrom-Json)
# Make sure to inspect the error result object and add only the error message as a FriendlyMessage.
# $httpErrorObj.FriendlyMessage = $errorDetailsObject.message
$httpErrorObj.FriendlyMessage = $httpErrorObj.ErrorDetails # Temporarily assignment
} catch {
$httpErrorObj.FriendlyMessage = $httpErrorObj.ErrorDetails
}
$httpErrorObj.FriendlyMessage = $httpErrorObj.ErrorDetails
Write-Output $httpErrorObj
}
}
Expand All @@ -57,35 +51,53 @@ try {
# Process
if (-not($actionContext.DryRun -eq $true)) {
Write-Information "Deleting GoodHabitz account with accountReference: [$($actionContext.Data.EmailAddress)]"

$splatParams = @{
Uri = "$($actionContext.Configuration.BaseUrl)api/person/forget?email=$($actionContext.Data.EmailAddress)"
Uri = "$($actionContext.Configuration.BaseUrl)/api/person/forget?email=$($actionContext.Data.EmailAddress)"
Method = 'POST'
ContentType = 'application/x-www-form-urlencoded'
Headers = @{
Headers = @{
Authorization = "Bearer $($ActionContext.Configuration.ApiKey)"
}
}
$null = Invoke-RestMethod @splatParams
$outputContext.Success = $true
$outputContext.AuditLogs.Add([PSCustomObject]@{
Message = 'Delete account was successful'
IsError = $false
})

try {
$null = Invoke-RestMethod @splatParams

$outputContext.AuditLogs.Add([PSCustomObject]@{
Message = "Account [$($actionContext.Data.EmailAddress)] was successfully deleted"
IsError = $false
})
}
catch {
if ($_.Exception.Response.StatusCode -eq 404) {
$outputContext.AuditLogs.Add([PSCustomObject]@{
Message = "Account [$($actionContext.Data.EmailAddress)] was not found, action skiped"
IsError = $false
})
}
else {
throw
}
}
}
} catch {
$outputContext.success = $true
}
catch {
$outputContext.success = $false
$ex = $PSItem
if ($($ex.Exception.GetType().FullName -eq 'Microsoft.PowerShell.Commands.HttpResponseException') -or
$($ex.Exception.GetType().FullName -eq 'System.Net.WebException')) {
$errorObj = Resolve-GoodHabitzError -ErrorObject $ex
$auditMessage = "Could not delete GoodHabitz account. Error: $($errorObj.FriendlyMessage)"
Write-Warning "Error at Line '$($errorObj.ScriptLineNumber)': $($errorObj.Line). Error: $($errorObj.ErrorDetails)"
} else {
}
else {
$auditMessage = "Could not delete GoodHabitz account. Error: $($_.Exception.Message)"
Write-Warning "Error at Line '$($ex.InvocationInfo.ScriptLineNumber)': $($ex.InvocationInfo.Line). Error: $($ex.Exception.Message)"
}
$outputContext.AuditLogs.Add([PSCustomObject]@{
Message = $auditMessage
IsError = $true
})
Message = $auditMessage
IsError = $true
})
}
2 changes: 1 addition & 1 deletion fieldMapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"MappingMode": "Field",
"Value": "\"function getActiveDirectoryEmail(){\\n return Person.Accounts.MicrosoftActiveDirectory.mail\\n}\\ngetActiveDirectoryEmail();\"",
"UsedInNotifications": false,
"StoreInAccountData": false
"StoreInAccountData": true
}
]
}
Expand Down

0 comments on commit d473c5d

Please sign in to comment.