Skip to content

Commit a59b941

Browse files
committed
added my files
I just copy and past all my files into a new folder.
1 parent 7eb6a96 commit a59b941

File tree

169 files changed

+19426
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

169 files changed

+19426
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
function Get-FileDefinitionParts {
2+
[CmdletBinding()]
3+
param (
4+
[Parameter(Mandatory = $true)]
5+
[ValidateNotNullOrEmpty()]
6+
[string]$sourceDirectory
7+
)
8+
try {
9+
if (-Not (Test-Path $sourceDirectory)) {
10+
Write-Message -Message "The specified source directory does not exist: $sourceDirectory" -Level Error
11+
throw
12+
}
13+
14+
# Get all files from the directory recursively
15+
Write-Message -Message "Get all files from the directory recursively" -Level Debug
16+
$fileList = Get-ChildItem -Path $sourceDirectory -File -Recurse
17+
18+
# Initialize the output JSON object
19+
$jsonObject = @{ parts = @() }
20+
21+
# Loop through the files to create parts dynamically
22+
Write-Message -Message "Loop through the files to create parts dynamically" -Level Debug
23+
foreach ($file in $fileList) {
24+
25+
$relativePath = $file.FullName.Substring($sourceDirectory.Length + 1) -replace "\\", "/"
26+
Write-Message -Message "File found: $relativePath" -Level Debug
27+
Write-Message -Message "Starting encode to base64" -Level Debug
28+
29+
$base64Content = Convert-ToBase64 -filePath $file.FullName
30+
Write-Message -Message "Adding part to json object" -Level Debug
31+
32+
$jsonObject.parts += @{
33+
path = $relativePath
34+
payload = $base64Content
35+
payloadType = "InlineBase64"
36+
}
37+
}
38+
Write-Message -Message "Loop through the files finished" -Level Debug
39+
40+
return $jsonObject
41+
Write-Message -Message "Parts returned" -Level Debug
42+
}
43+
44+
catch {
45+
# Step 4: Handle and log errors
46+
$errorDetails = $_.Exception.Message
47+
Write-Message -Message "An error occurred while getting file definition parts: $errorDetails" -Level Error
48+
throw "An error occurred while encoding to Base64: $_"
49+
}
50+
}
51+
52+
53+
# Example usage
54+
#$sourceDirectory = "C:\temp\API\Notebook"
55+
#Get-FileParts -sourceDirectory $sourceDirectory
56+
#$fileParts = Get-FileParts -sourceDirectory $sourceDirectory
57+
#$fileParts | ConvertTo-Json -Depth 10
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<#
2+
.SYNOPSIS
3+
Checks if the Fabric token is expired and logs appropriate messages.
4+
5+
.DESCRIPTION
6+
The `Test-TokenExpired` function checks the expiration status of the Fabric token stored in the `$FabricConfig.TokenExpiresOn` variable.
7+
If the token is expired, it logs an error message and provides guidance for refreshing the token.
8+
Otherwise, it logs that the token is still valid.
9+
10+
.PARAMETER FabricConfig
11+
The configuration object containing the token expiration details.
12+
13+
.EXAMPLE
14+
Test-TokenExpired -FabricConfig $config
15+
16+
Checks the token expiration status using the provided `$config` object.
17+
18+
.NOTES
19+
- Ensure the `FabricConfig` object includes a valid `TokenExpiresOn` property of type `DateTimeOffset`.
20+
- Requires the `Write-Message` function for logging.
21+
22+
.AUTHOR
23+
Tiago Balabuch
24+
#>
25+
function Test-TokenExpired {
26+
[CmdletBinding()]
27+
param ()
28+
29+
try {
30+
# Ensure required properties have valid values
31+
if ([string]::IsNullOrWhiteSpace($FabricConfig.TenantIdGlobal) -or
32+
[string]::IsNullOrWhiteSpace($FabricConfig.TokenExpiresOn)) {
33+
Write-Message -Message "Token details are missing. Please run 'Set-FabricApiHeaders' to configure them." -Level Error
34+
throw "MissingTokenDetailsException: Token details are missing."
35+
}
36+
37+
# Convert the TokenExpiresOn value to a DateTime object
38+
$tokenExpiryDate = [datetimeoffset]::Parse($FabricConfig.TokenExpiresOn)
39+
40+
# Check if the token is expired
41+
if ($tokenExpiryDate -le [datetimeoffset]::Now) {
42+
Write-Message -Message "Your authentication token has expired. Please sign in again to refresh your session." -Level Warning
43+
#throw "TokenExpiredException: Token has expired."
44+
#Set-FabricApiHeaders -tenantId $FabricConfig.TenantIdGlobal
45+
}
46+
47+
# Log valid token status
48+
Write-Message -Message "Token is still valid. Expiry time: $($tokenExpiryDate.ToString("u"))" -Level Debug
49+
} catch [System.FormatException] {
50+
Write-Message -Message "Invalid 'TokenExpiresOn' format in the FabricConfig object. Ensure it is a valid datetime string." -Level Error
51+
throw "FormatException: Invalid TokenExpiresOn value."
52+
} catch {
53+
# Log unexpected errors with details
54+
Write-Message -Message "An unexpected error occurred: $_" -Level Error
55+
throw $_
56+
}
57+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<#
2+
.SYNOPSIS
3+
Logs messages with different severity levels to the console and optionally to a file.
4+
5+
.DESCRIPTION
6+
The `Write-Message` function provides a unified way to log messages with levels such as Info, Error, Alert, Verbose, and Debug.
7+
It supports logging to the console with color-coded messages and optionally writing logs to a file with timestamps.
8+
9+
.PARAMETER Message
10+
The message to log. Supports pipeline input.
11+
12+
.PARAMETER Level
13+
Specifies the log level. Supported values are Info, Error, Alert, Verbose, and Debug.
14+
15+
.PARAMETER LogFile
16+
(Optional) Specifies a file path to write the log messages to. If not provided, messages are only written to the console.
17+
18+
.EXAMPLE
19+
Write-Message -Message "This is an info message." -Level Info
20+
21+
Logs an informational message to the console.
22+
23+
.EXAMPLE
24+
Write-Message -Message "Logging to file." -Level Info -LogFile "C:\Logs\MyLog.txt"
25+
26+
Logs an informational message to the console and writes it to a file.
27+
28+
.EXAMPLE
29+
"Pipeline message" | Write-Message -Level Alert
30+
31+
Logs a message from the pipeline with an Alert level.
32+
33+
.NOTES
34+
Author: Tiago Balabuch
35+
#>
36+
37+
function Write-Message {
38+
[CmdletBinding()]
39+
param (
40+
[Parameter(Mandatory, ValueFromPipeline)]
41+
[string]$Message,
42+
43+
[Parameter()]
44+
[ValidateSet("Message","Info", "Error", "Warning","Critical", "Verbose", "Debug", IgnoreCase = $true)]
45+
[string]$Level = "Info",
46+
47+
[Parameter()]
48+
[string]$LogFile
49+
)
50+
51+
process {
52+
try {
53+
# Format timestamp
54+
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
55+
56+
# Construct log message
57+
$logMessage = "[$timestamp] [$Level] $Message"
58+
59+
# Write log message to console with colors
60+
switch ($Level) {
61+
"Message" { Write-Host $logMessage -ForegroundColor White }
62+
"Info" { Write-Host $logMessage -ForegroundColor Green }
63+
"Error" { Write-Host $logMessage -ForegroundColor Red }
64+
"Warning" { Write-Host $logMessage -ForegroundColor Yellow }
65+
"Critical" { Write-Host $logMessage -ForegroundColor Red }
66+
"Verbose" { Write-Verbose $logMessage }
67+
"Debug" { Write-Debug $logMessage }
68+
69+
}
70+
71+
# Optionally write log message to a file
72+
if ($LogFile) {
73+
try {
74+
Add-Content -Path $LogFile -Value $logMessage -Encoding UTF8
75+
} catch {
76+
# Catch and log any errors when writing to file
77+
Write-Host "[ERROR] Failed to write to log file '$LogFile': $_" -ForegroundColor Red
78+
}
79+
}
80+
} catch {
81+
Write-Host "[ERROR] An unexpected error occurred: $_" -ForegroundColor Red
82+
}
83+
}
84+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
2+
<#
3+
.SYNOPSIS
4+
Retrieves capacity details from a specified Microsoft Fabric workspace.
5+
6+
.DESCRIPTION
7+
This function retrieves capacity details from a specified workspace using either the provided capacityId or capacityName.
8+
It handles token validation, constructs the API URL, makes the API request, and processes the response.
9+
10+
.PARAMETER capacityId
11+
The unique identifier of the capacity to retrieve. This parameter is optional.
12+
13+
.PARAMETER capacityName
14+
The name of the capacity to retrieve. This parameter is optional.
15+
16+
.EXAMPLE
17+
Get-FabricCapacity -capacityId "capacity-12345"
18+
This example retrieves the capacity details for the capacity with ID "capacity-12345".
19+
20+
.EXAMPLE
21+
Get-FabricCapacity -capacityName "MyCapacity"
22+
This example retrieves the capacity details for the capacity named "MyCapacity".
23+
24+
.NOTES
25+
- Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`.
26+
- Calls `Test-TokenExpired` to ensure token validity before making the API request.
27+
28+
Author: Tiago Balabuch
29+
#>
30+
function Get-FabricCapacity {
31+
[CmdletBinding()]
32+
param (
33+
[Parameter(Mandatory = $false)]
34+
[ValidateNotNullOrEmpty()]
35+
[string]$capacityId,
36+
37+
[Parameter(Mandatory = $false)]
38+
[ValidateNotNullOrEmpty()]
39+
[string]$capacityName
40+
)
41+
try {
42+
# Handle ambiguous input
43+
if ($capacityId -and $capacityName) {
44+
Write-Message -Message "Both 'capacityId' and 'capacityName' were provided. Please specify only one." -Level Error
45+
return $null
46+
}
47+
48+
# Ensure token validity
49+
Write-Message -Message "Validating token..." -Level Debug
50+
Test-TokenExpired
51+
Write-Message -Message "Token validation completed." -Level Debug
52+
53+
# Construct the API endpoint URL
54+
$apiEndpointURI = "{0}/capacities" -f $FabricConfig.BaseUrl
55+
56+
# Invoke the Fabric API to retrieve capacity details
57+
$capacities = Invoke-FabricAPIRequest `
58+
-BaseURI $apiEndpointURI `
59+
-Headers $FabricConfig.FabricHeaders `
60+
-Method Get
61+
62+
63+
# Filter results based on provided parameters
64+
$response = if ($capacityId) {
65+
$capacities | Where-Object { $_.Id -eq $capacityId }
66+
}
67+
elseif ($capacityName) {
68+
$capacities | Where-Object { $_.DisplayName -eq $capacityName }
69+
}
70+
else {
71+
# No filter, return all capacities
72+
Write-Message -Message "No filter specified. Returning all capacities." -Level Debug
73+
return $capacities
74+
}
75+
76+
# Handle results
77+
if ($response) {
78+
Write-Message -Message "Capacity found matching the specified criteria." -Level Debug
79+
return $response
80+
}
81+
else {
82+
Write-Message -Message "No capacity found matching the specified criteria." -Level Warning
83+
return $null
84+
}
85+
}
86+
catch {
87+
# Capture and log error details
88+
$errorDetails = $_.Exception.Message
89+
Write-Message -Message "Failed to retrieve capacity. Error: $errorDetails" -Level Error
90+
return $null
91+
}
92+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<#
2+
.SYNOPSIS
3+
Retrieves CopyJob details from a specified Microsoft Fabric workspace.
4+
5+
.DESCRIPTION
6+
This function retrieves CopyJob details from a specified workspace using either the provided CopyJobId or CopyJobName.
7+
It handles token validation, constructs the API URL, makes the API request, and processes the response.
8+
9+
.PARAMETER WorkspaceId
10+
The unique identifier of the workspace where the CopyJob exists. This parameter is mandatory.
11+
12+
.PARAMETER CopyJobId
13+
The unique identifier of the CopyJob to retrieve. This parameter is optional.
14+
15+
.PARAMETER CopyJobName
16+
The name of the CopyJob to retrieve. This parameter is optional.
17+
18+
.EXAMPLE
19+
FabricCopyJob -WorkspaceId "workspace-12345" -CopyJobId "CopyJob-67890"
20+
This example retrieves the CopyJob details for the CopyJob with ID "CopyJob-67890" in the workspace with ID "workspace-12345".
21+
22+
.EXAMPLE
23+
FabricCopyJob -WorkspaceId "workspace-12345" -CopyJobName "My CopyJob"
24+
This example retrieves the CopyJob details for the CopyJob named "My CopyJob" in the workspace with ID "workspace-12345".
25+
26+
.NOTES
27+
- Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`.
28+
- Calls `Test-TokenExpired` to ensure token validity before making the API request.
29+
30+
Author: Tiago Balabuch
31+
#>
32+
function FabricCopyJob {
33+
[CmdletBinding()]
34+
param (
35+
[Parameter(Mandatory = $true)]
36+
[ValidateNotNullOrEmpty()]
37+
[string]$WorkspaceId,
38+
39+
[Parameter(Mandatory = $false)]
40+
[ValidateNotNullOrEmpty()]
41+
[string]$CopyJobId,
42+
43+
[Parameter(Mandatory = $false)]
44+
[ValidateNotNullOrEmpty()]
45+
[ValidatePattern('^[a-zA-Z0-9_ ]*$')]
46+
[string]$CopyJob
47+
)
48+
49+
try {
50+
# Handle ambiguous input
51+
if ($CopyJobId -and $CopyJobName) {
52+
Write-Message -Message "Both 'CopyJobId' and 'CopyJobName' were provided. Please specify only one." -Level Error
53+
return $null
54+
}
55+
56+
# Ensure token validity
57+
Write-Message -Message "Validating token..." -Level Debug
58+
Test-TokenExpired
59+
Write-Message -Message "Token validation completed." -Level Debug
60+
61+
62+
# Construct the API endpoint URL
63+
$apiEndpointURI = "{0}/workspaces/{1}/copyJobs" -f $FabricConfig.BaseUrl, $WorkspaceId
64+
65+
# Invoke the Fabric API to retrieve capacity details
66+
$copyJobs = Invoke-FabricAPIRequest `
67+
-BaseURI $apiEndpointURI `
68+
-Headers $FabricConfig.FabricHeaders `
69+
-Method Get
70+
71+
# Filter results based on provided parameters
72+
$response = if ($CopyJobId) {
73+
$copyJobs | Where-Object { $_.Id -eq $CopyJobId }
74+
}
75+
elseif ($CopyJobName) {
76+
$copyJobs | Where-Object { $_.DisplayName -eq $CopyJobName }
77+
}
78+
else {
79+
# Return all CopyJobs if no filter is provided
80+
Write-Message -Message "No filter provided. Returning all CopyJobs." -Level Debug
81+
$copyJobs
82+
}
83+
84+
# Step 9: Handle results
85+
if ($response) {
86+
Write-Message -Message "CopyJob found matching the specified criteria." -Level Debug
87+
return $response
88+
}
89+
else {
90+
Write-Message -Message "No CopyJob found matching the provided criteria." -Level Warning
91+
return $null
92+
}
93+
}
94+
catch {
95+
# Step 10: Capture and log error details
96+
$errorDetails = $_.Exception.Message
97+
Write-Message -Message "Failed to retrieve CopyJob. Error: $errorDetails" -Level Error
98+
}
99+
100+
}

0 commit comments

Comments
 (0)