Compare commits

..

No commits in common. "main" and "v0.3.0" have entirely different histories.
main ... v0.3.0

9 changed files with 422 additions and 768 deletions

View File

@ -14,4 +14,4 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check WIP in PR Title
uses: embano1/wip@v2
uses: embano1/wip@v1

View File

@ -6,7 +6,7 @@
name: Release
on:
push:
create:
tags:
- v*
workflow_dispatch:

View File

@ -1,89 +0,0 @@
<a name="v0.3.3"></a>
## [Release v0.3.3](https://github.com/cloudevents/sdk-powershell/compare/v0.3.2...v0.3.3)
> Release Date: 2021-09-08
### 🧹 Chore
- [32f333b] Bump module version for new release
- [5e2e221] Trigger release on tag push (#47)
### ⚠️ BREAKING
### 📖 Commits
- [32f333b] chore: Bump module version for new release
- [5e2e221] chore: Trigger release on tag push (#47)
<a name="v0.3.2"></a>
## [Release v0.3.2](https://github.com/cloudevents/sdk-powershell/compare/v0.3.1...v0.3.2)
> Release Date: 2021-09-08
### 🧹 Chore
- [c8b5958] Add Project URI in the module manifest
### ⚠️ BREAKING
### 📖 Commits
- [c8b5958] chore: Add Project URI in the module manifest
<a name="v0.3.1"></a>
## [Release v0.3.1](https://github.com/cloudevents/sdk-powershell/compare/v0.3.0...v0.3.1)
> Release Date: 2021-08-30
### 🐞 Fix
- [7eb0f9b] Incorrect parsing of Binary Content Mode cloud events
### 🧹 Chore
- [941816a] Add RELEASE instructions (#40)
### ⚠️ BREAKING
### 📖 Commits
- [7eb0f9b] fix: Incorrect parsing of Binary Content Mode cloud events
- [941816a] chore: Add RELEASE instructions (#40)
- [7876104] Update README with the new version output
<a name="v0.3.0"></a>
## v0.3.0
> Release Date: 2021-06-21
### 🧹 Chore
- [5b14f75] Include commit details in CHANGELOG (#35)
- [2c4d0ed] Add check WIP action (#31)
- [5764180] Add CHANGELOG configuration (#29)
- [0bd4192] Verify PRs and push to main (#6)
- [e08a275] Add stale action (#7)
### ⚠️ BREAKING
### 📖 Commits
- [2144695] Bump module version 0.3.0
- [5b14f75] chore: Include commit details in CHANGELOG (#35)
- [78b7e9e] Implement publish script
- [2c4d0ed] chore: Add check WIP action (#31)
- [5764180] chore: Add CHANGELOG configuration (#29)
- [a0e1078] Add PR template (#3)
- [ae6f848] Update issue templates
- [3a9010a] Improve examples. Remove unnecessary details.
- [401a475] Implement wait server to start in the integrations tests BeforeAll Fix Binary Mode HTTP Header DateTime format. It is UTC time formatted in ISO 8601 format including milliseconds. Bump revision of the module version
- [0bd4192] chore: Verify PRs and push to main (#6)
- [e08a275] chore: Add stale action (#7)
- [3629c77] Add Install Module Instructions to README ([#17](https://github.com/cloudevents/sdk-powershell/issues/17)) (#17) (#16)
- [aac584a] Enable process exit in build.ps1
- [84606b0] Create CONTRIBUTING.md ([#15](https://github.com/cloudevents/sdk-powershell/issues/15)) (#15)
- [d305f16] Renames Add-CloudEvent*Data to Set-CloudEvent*Data ([#12](https://github.com/cloudevents/sdk-powershell/issues/12)) (#12) (#9)
- [f23df54] Adds license headers in source code files ([#11](https://github.com/cloudevents/sdk-powershell/issues/11)) (#11)
- [62f14b6] Remove install instructions from an internal PS repository ([#10](https://github.com/cloudevents/sdk-powershell/issues/10)) (#10) (#1)
- [b2afcf8] Initial commit

View File

@ -1,9 +0,0 @@
# Maintainers
Current active maintainers of this SDK:
- [William Lam](https://github.com/lamw)
- [Mark Peek](https://github.com/markpeek
- [Dimitar Milov](https://github.com/dmilov)
- [Michael Gasch](https://github.com/embano1)
- [Simeon Gerginov](https://github.com/SimeonGerginov)

View File

@ -1,7 +1,5 @@
# PowerShell 7.0 SDK for CloudEvents based on [.NET SDK for CloudEvents](https://github.com/cloudevents/sdk-csharp)
Official CloudEvents SDK to integrate your application with CloudEvents.
## Status
Supported CloudEvents versions:
@ -28,17 +26,16 @@ Install-Module CloudEvents.Sdk
Import-Module CloudEvents.Sdk
Get-Command -Module CloudEvents.Sdk
CommandType Name Version Source
----------- ---- ------- ------
Function ConvertFrom-HttpMessage 0.3.0 CloudEvents.Sdk
Function ConvertTo-HttpMessage 0.3.0 CloudEvents.Sdk
Function New-CloudEvent 0.3.0 CloudEvents.Sdk
Function Read-CloudEventData 0.3.0 CloudEvents.Sdk
Function Read-CloudEventJsonData 0.3.0 CloudEvents.Sdk
Function Read-CloudEventXmlData 0.3.0 CloudEvents.Sdk
Function Set-CloudEventData 0.3.0 CloudEvents.Sdk
Function Set-CloudEventJsonData 0.3.0 CloudEvents.Sdk
Function Set-CloudEventXmlData 0.3.0 CloudEvents.Sdk
CommandType Name Version Source ----------- ---- ------- ------
Function ConvertFrom-HttpMessage 0.2.0 CloudEvents.Sdk
Function ConvertTo-HttpMessage 0.2.0 CloudEvents.Sdk
Function New-CloudEvent 0.2.0 CloudEvents.Sdk
Function Read-CloudEventData 0.2.0 CloudEvents.Sdk
Function Read-CloudEventJsonData 0.2.0 CloudEvents.Sdk
Function Read-CloudEventXmlData 0.2.0 CloudEvents.Sdk
Function Set-CloudEventData 0.2.0 CloudEvents.Sdk
Function Set-CloudEventJsonData 0.2.0 CloudEvents.Sdk
Function Set-CloudEventXmlData 0.2.0 CloudEvents.Sdk
```
## Using **`CloudEvents.Sdk`** Module
@ -162,40 +159,3 @@ Read-CloudEventData -CloudEvent $cloudEvent
100
33
```
## Community
- There are bi-weekly calls immediately following the
[Serverless/CloudEvents call](https://github.com/cloudevents/spec#meeting-time)
at 9am PT (US Pacific). Which means they will typically start at 10am PT, but
if the other call ends early then the SDK call will start early as well. See
the
[CloudEvents meeting minutes](https://docs.google.com/document/d/1OVF68rpuPK5shIHILK9JOqlZBbfe91RNzQ7u_P7YCDE/edit#)
to determine which week will have the call.
- Slack: #cloudeventssdk channel under
[CNCF's Slack workspace](https://slack.cncf.io/).
- Email: https://lists.cncf.io/g/cncf-cloudevents-sdk
- Contact for additional information: Michael Gasch (`@Michael Gasch`
on slack).
Each SDK may have its own unique processes, tooling and guidelines, common
governance related material can be found in the
[CloudEvents `community`](https://github.com/cloudevents/spec/tree/master/community)
directory. In particular, in there you will find information concerning
how SDK projects are
[managed](https://github.com/cloudevents/spec/blob/master/community/SDK-GOVERNANCE.md),
[guidelines](https://github.com/cloudevents/spec/blob/master/community/SDK-maintainer-guidelines.md)
for how PR reviews and approval, and our
[Code of Conduct](https://github.com/cloudevents/spec/blob/master/community/GOVERNANCE.md#additional-information)
information.
If there is a security concern with one of the CloudEvents specifications, or
with one of the project's SDKs, please send an email to
[cncf-cloudevents-security@lists.cncf.io](mailto:cncf-cloudevents-security@lists.cncf.io).
## Additional SDK Resources
- [List of current active maintainers](MAINTAINERS.md)
- [How to contribute to the project](CONTRIBUTING.md)
- [SDK's License](LICENSE)
- [SDK's Release process](RELEASING.md)

View File

@ -1,57 +0,0 @@
# How to create a Release
We use `tags` to drive the creation of the releases. This is handled by the
Github Actions release workflow in
[`ps-ce-sdk-release.yaml`](.github/workflows/ps-ce-sdk-release.yaml).
A new release will upload the `PowerShell` module artifacts to the `PowerShell`
[gallery](https://www.powershellgallery.com/packages/CloudEvents.Sdk).
## Step 1 - Bump Module Version
Bump the `ModuleVersion` in
[`src/CloudEventsPowerShell/CloudEvents.Sdk.psd1`](./src/CloudEventsPowerShell/CloudEvents.Sdk.psd1)
to the next semantic release version (without `"v"` prefix).
```powershell
# Version number of this module.
ModuleVersion = '0.3.0'
```
Create a pull request with this change, review and approve it **after** all checks
have passed.
## Step 2 - Update local `main` branch
Pull in the latest changes, incl. the merged PR above, into your local `main`
branch of this repository **before** creating a `tag` via the `git` CLI.
```console
git checkout main
git fetch -avp
git pull upstream main
```
**Note:** the above commands assume `upstream` pointing to the remote
`https://github.com/cloudevents/sdk-powershell.git`
## Step 3 - Create and push a Tag
```console
RELEASE=v0.3.0
git tag -a $RELEASE -m "Release ${RELEASE}"
git push upstream refs/tags/${RELEASE}
```
This will trigger the release
[workflow](https://github.com/cloudevents/sdk-powershell/actions/workflows/ps-ce-sdk-release.yaml).
**Verify** that it executed successfully and that a new Github
[release](https://github.com/cloudevents/sdk-powershell/releases) was created.
The release workflow also creates a pull request with the updated
[`CHANGELOG.md`](CHANGELOG.md). **Verify**, approve and merge accordingly.
If you need to make changes to the Github release notes, you can edit them on the [release](https://github.com/cloudevents/sdk-powershell/releases) page.

View File

@ -9,7 +9,7 @@
RootModule = 'CloudEvents.Sdk.psm1'
# Version number of this module.
ModuleVersion = '0.3.3'
ModuleVersion = '0.3.0'
# Supported PSEditions
CompatiblePSEditions = @('Core')
@ -80,38 +80,5 @@ VariablesToExport = '*'
# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
AliasesToExport = @()
# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
PrivateData = @{
PSData = @{
# Tags applied to this module. These help with module discovery in online galleries.
Tags = 'CloudEvents','SDK'
# A URL to the license for this module.
# LicenseUri = ''
# A URL to the main website for this project.
ProjectUri = 'https://github.com/cloudevents/sdk-powershell'
# A URL to an icon representing this module.
# IconUri = ''
# ReleaseNotes of this module
# ReleaseNotes = ''
# Prerelease string of this module
# Prerelease = ''
# Flag to indicate whether the module requires explicit user acceptance for install/update
# RequireLicenseAcceptance = $false
# External dependent modules of this module
# ExternalModuleDependencies = @()
} # End of PSData hashtable
} # End of PrivateData hashtable
}

View File

@ -349,7 +349,7 @@ function Read-CloudEventJsonData {
-ArgumentList ([System.Net.Mime.MediaTypeNames+Application]::Json)
if ($CloudEvent.DataContentType -eq $dataContentType -or `
($CloudEvent.DataContentType -eq $null -and # Datacontent Type is Optional, if it is not specified we assume it is JSON as per https://github.com/cloudevents/spec/blob/v1.0.1/spec.md#datacontenttype
($CloudEvent.DataContentType -eq $null -and ` # Datacontent Type is Optional, if it is not specified we assume it is JSON as per https://github.com/cloudevents/spec/blob/v1.0.1/spec.md#datacontenttype
$cloudEvent.Data -is [Newtonsoft.Json.Linq.JObject])) {
$data = $cloudEvent.Data
@ -361,8 +361,7 @@ function Read-CloudEventJsonData {
$result = $data.ToString() | ConvertFrom-Json -AsHashtable -Depth $Depth
Write-Output $result
}
else {
} else {
Write-Error "Cloud Event '$($cloudEvent.Id)' has no json data"
}
}
@ -469,8 +468,7 @@ function Read-CloudEventXmlData {
$result = $data.ToString() | ConvertFrom-CEDataXml -ConvertMode $ConvertMode
Write-Output $result
}
else {
} else {
Write-Error "Cloud Event '$($cloudEvent.Id)' has no xml data"
}
}
@ -563,7 +561,8 @@ function ConvertTo-HttpMessage {
elseif ($attribute.Value -is [Uri] -or $attribute.Value -is [int]) {
$headers.Add(($HttpHeaderPrefix + $attribute.Key), $attribute.Value.ToString())
}
else {
else
{
$headers.Add(($HttpHeaderPrefix + $attribute.Key),
[System.Text.Encoding]::UTF8.GetString($cloudEventFormatter.EncodeAttribute($cloudEvent.SpecVersion, $attribute.Key,
$attribute.Value,
@ -610,17 +609,16 @@ function ConvertTo-HttpMessage {
try {
$read = 0
while (($read = $cloudEvent.Data.Read($buffer, 0, 1024)) -gt 0) {
while (($read = $cloudEvent.Data.Read($buffer, 0, 1024)) -gt 0)
{
$ms.Write($buffer, 0, $read);
}
$bodyData = $ms.ToArray()
}
finally {
} finally {
$ms.Dispose()
}
}
else {
} else {
$bodyData = $cloudEventFormatter.EncodeAttribute($cloudEvent.SpecVersion,
[CloudNative.CloudEvents.CloudEventAttributes]::DataAttributeName($cloudEvent.SpecVersion),
$cloudEvent.Data, $cloudEvent.Extensions.Values)
@ -676,7 +674,8 @@ function ConvertFrom-HttpMessage {
PROCESS {
$HttpHeaderPrefix = "ce-";
$SpecVersionHttpHeader = $HttpHeaderPrefix + "specversion";
$SpecVersionHttpHeader1 = $HttpHeaderPrefix + "cloudEventsVersion";
$SpecVersionHttpHeader2 = $HttpHeaderPrefix + "specversion";
$result = $null
@ -688,7 +687,7 @@ function ConvertFrom-HttpMessage {
$Body = [System.Text.Encoding]::UTF8.GetBytes($Body)
}
if ($null -ne $Headers['Content-Type']) {
if ($Headers['Content-Type'] -ne $null) {
$ContentType = $Headers['Content-Type']
if ($ContentType -is [array]) {
# Get the first content-type value
@ -715,25 +714,25 @@ function ConvertFrom-HttpMessage {
$result = $formatter.DecodeJObject($jObject, $null)
$result.Data = $result.Data
}
else {
} else {
# Throw error for unsupported encoding
throw "Unsupported CloudEvents encoding"
}
}
else {
} else {
# Handle Binary Mode
$version = $null
if ($Headers.Contains($SpecVersionHttpHeader) -and `
$null -ne $Headers[$SpecVersionHttpHeader] -and `
($Headers[$SpecVersionHttpHeader] | Select-Object -First 1).StartsWith('1.0')) {
# We do support the 1.0 cloud event version
$version = [CloudNative.CloudEvents.CloudEventsSpecVersion]::V1_0
$version = [CloudNative.CloudEvents.CloudEventsSpecVersion]::Default
if ($Headers.Contains($SpecVersionHttpHeader1)) {
$version = [CloudNative.CloudEvents.CloudEventsSpecVersion]::V0_1
}
if ($Headers.Contains($SpecVersionHttpHeader2)) {
if ($Headers[$SpecVersionHttpHeader2][0] -eq "0.2") {
$version = [CloudNative.CloudEvents.CloudEventsSpecVersion]::V0_2
} elseif ($Headers[$SpecVersionHttpHeader2][0] -eq "0.3") {
$version = [CloudNative.CloudEvents.CloudEventsSpecVersion]::V0_3
}
}
if ($null -ne $version) {
# SpecVersion is REQUIRED attribute, it it is not specified this is not a CloudEvent
# https://github.com/cloudevents/spec/blob/v1.0.1/spec.md#specversion
$cloudEvent = New-Object `
-TypeName 'CloudNative.CloudEvents.CloudEvent' `
-ArgumentList @($version, $null);
@ -742,7 +741,8 @@ function ConvertFrom-HttpMessage {
# Get attributes from HTTP Headers
foreach ($httpHeader in $Headers.GetEnumerator()) {
if ($httpHeader.Key.Equals($SpecVersionHttpHeader, [StringComparison]::InvariantCultureIgnoreCase)) {
if ($httpHeader.Key.Equals($SpecVersionHttpHeader1, [StringComparison]::InvariantCultureIgnoreCase) -or `
$httpHeader.Key.Equals($SpecVersionHttpHeader2, [StringComparison]::InvariantCultureIgnoreCase)) {
continue
}
@ -755,7 +755,8 @@ function ConvertFrom-HttpMessage {
$name = $httpHeader.Key.Substring(3);
# Abolished structures in headers in 1.0
if ( $null -ne $headerValue -and `
if ($version -ne [CloudNative.CloudEvents.CloudEventsSpecVersion]::V0_1 -and `
$headerValue -ne $null -and `
$headerValue.StartsWith('"') -and `
$headerValue.EndsWith('"') -or `
$headerValue.StartsWith("'") -and $headerValue.EndsWith("'") -or `
@ -766,39 +767,22 @@ function ConvertFrom-HttpMessage {
$attributes[$name] = $jsonFormatter.DecodeAttribute($version, $name,
[System.Text.Encoding]::UTF8.GetBytes($headerValue), $null);
}
else {
} else {
$attributes[$name] = $headerValue
}
}
}
# Verify parsed attributes from HTTP Headers
if ($null -ne $attributes['datacontenttype']) {
# ce-datatype is prohibitted by the protocol -> throw error
# https://github.com/cloudevents/spec/blob/v1.0.1/http-protocol-binding.md#311-http-content-type
throw "'ce-datacontenttype' HTTP header is prohibited for Binary ContentMode CloudEvent"
}
if ($Headers['Content-Type'] -is [string]) {
$cloudEvent.DataContentType = New-Object 'System.Net.Mime.ContentType' -ArgumentList @($Headers['Content-Type'])
} elseif ($Headers['Content-Type'][0] -is [string]) {
if ($Headers['Content-Type'] -ne $null -and $Headers['Content-Type'][0] -is [string]) {
$cloudEvent.DataContentType = New-Object 'System.Net.Mime.ContentType' -ArgumentList @($Headers['Content-Type'][0])
}
# Id, Type, and Source are reuiqred to be non-empty strings otherwise consider this is not a CloudEvent
# https://github.com/cloudevents/spec/blob/v1.0.1/spec.md#required-attributes
if ( -not [string]::IsNullOrEmpty($cloudEvent.Id) -and `
-not [string]::IsNullOrEmpty($cloudEvent.Source) -and `
-not [string]::IsNullOrEmpty($cloudEvent.Type)) {
# Get Data from HTTP Body
$cloudEvent.Data = $Body
$result = $cloudEvent
}
}
}
}
Write-Output $result
}

View File

@ -4,9 +4,9 @@
# **************************************************************************
Describe "ConvertFrom-HttpMessage Function Tests" {
BeforeEach {
$script:expectedSpecVersion = '1.0'
$script:expectedStructuredContentType = 'application/cloudevents+json'
BeforeAll {
$expectedSpecVersion = '1.0'
$expectedStructuredContentType = 'application/cloudevents+json'
}
Context "Converts CloudEvent in Binary Content Mode" {
@ -77,7 +77,6 @@ Describe "ConvertFrom-HttpMessage Function Tests" {
$expectedType = 'test'
$expectedSource = 'urn:test'
$expectedDataContentType = 'application/xml'
$expectedId = 'test-id-2'
$expectedData = [Text.Encoding]::UTF8.GetBytes('<much wow="xml"/>')
$headers = @{
@ -85,7 +84,6 @@ Describe "ConvertFrom-HttpMessage Function Tests" {
'ce-specversion' = $expectedSpecVersion
'ce-type' = $expectedType
'ce-source' = $expectedSource
'ce-id' = $expectedId
}
$body = $expectedData
@ -97,7 +95,6 @@ Describe "ConvertFrom-HttpMessage Function Tests" {
# Assert
$actual | Should -Not -Be $null
$actual.Id | Should -Be $expectedId
$actual.Type | Should -Be $expectedType
$actual.Source | Should -Be $expectedSource
$actual.DataContentType | Should -Be $expectedDataContentType
@ -108,81 +105,6 @@ Describe "ConvertFrom-HttpMessage Function Tests" {
$actualData | Should -Be $expectedData
}
It 'Returns null when ce-id is not specified' {
# Arrange
$expectedType = 'test'
$expectedSource = 'urn:test'
$expectedDataContentType = 'application/xml'
$expectedData = [Text.Encoding]::UTF8.GetBytes('<much wow="xml"/>')
$headers = @{
'Content-Type' = @($expectedDataContentType, 'charset=utf-8')
'ce-specversion' = $expectedSpecVersion
'ce-type' = $expectedType
'ce-source' = $expectedSource
}
$body = $expectedData
# Act
$actual = ConvertFrom-HttpMessage `
-Headers $headers `
-Body $body
# Assert
$actual | Should -Be $null
}
It 'Returns null when ce-source is not specified' {
# Arrange
$expectedType = 'test'
$expectedDataContentType = 'application/xml'
$expectedId = 'test-id-3'
$expectedData = [Text.Encoding]::UTF8.GetBytes('<much wow="xml"/>')
$headers = @{
'Content-Type' = @($expectedDataContentType, 'charset=utf-8')
'ce-specversion' = $expectedSpecVersion
'ce-type' = $expectedType
'ce-id' = $expectedId
}
$body = $expectedData
# Act
$actual = ConvertFrom-HttpMessage `
-Headers $headers `
-Body $body
# Assert
$actual | Should -Be $null
}
It 'Returns null when ce-type is not specified' {
# Arrange
$expectedSource = 'urn:test'
$expectedDataContentType = 'application/xml'
$expectedId = 'test-id-4'
$expectedData = [Text.Encoding]::UTF8.GetBytes('<much wow="xml"/>')
$headers = @{
'Content-Type' = @($expectedDataContentType, 'charset=utf-8')
'ce-specversion' = $expectedSpecVersion
'ce-source' = $expectedSource
'ce-id' = $expectedId
}
$body = $expectedData
# Act
$actual = ConvertFrom-HttpMessage `
-Headers $headers `
-Body $body
# Assert
$actual | Should -Be $null
}
}
Context "Converts CloudEvent in Structured Content Mode" {
@ -323,29 +245,5 @@ Describe "ConvertFrom-HttpMessage Function Tests" {
-Body $body } | `
Should -Throw "*Unsupported CloudEvents encoding*"
}
It 'Returns null when no Content-Type header' {
# Arrange
$expectedType = 'test'
$expectedSource = 'urn:test'
$expectedDataContentType = 'application/xml'
$expectedData = [Text.Encoding]::UTF8.GetBytes('<much wow="xml"/>')
$structuredJsonBody = @{
'specversion' = $expectedSpecVersion
'type' = $expectedType
'source' = $expectedSource
'datacontenttype' = $expectedDataContentType
'data' = $expectedData
}
$body = [Text.Encoding]::UTF8.GetBytes(($structuredJsonBody | ConvertTo-Json))
# Act & Assert
$ce = ConvertFrom-HttpMessage `
-Headers @{} `
-Body $body
$ce | Should -Be $null
}
}
}