Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[azeventgrid] Use the common azcore/messaging/CloudEvent model #21028

Merged
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 1 addition & 1 deletion sdk/messaging/azeventgrid/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "go",
"TagPrefix": "go/messaging/azeventgrid",
"Tag": "go/messaging/azeventgrid_601fd733f2"
"Tag": "go/messaging/azeventgrid_b8c3771d17"
}
27 changes: 16 additions & 11 deletions sdk/messaging/azeventgrid/autorest.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,6 @@ directive:
- from: client.go
where: $
transform: return $.replace(/PublishCloudEvents\(/g, "internalPublishCloudEvents(");
# make sure the casing of the properties is what compliant.
# - from: swagger-document
# where: $.definitions.CloudEvent.properties.data
# transform: >
# $["type"] = "array"
# - from: swagger-document
# where: $.definitions.CloudEvent.properties.data
# transform: >
# $["items"] = {"type": "byte"}
- from: swagger-document
where: $.definitions.CloudEvent.properties.specversion
transform: $["x-ms-client-name"] = "SpecVersion"
Expand All @@ -54,11 +45,25 @@ directive:
- response_types.go
where: $
transform: return $.replace(/Client(\w+)((?:Options|Response))/g, "$1$2");
# replace references to the "generated" CloudEvent to the actual version in azcore/messaging
- from:
- client.go
- models.go
- models_serde.go
- response_types.go
where: $
transform: return $.replace(/AzureCoreFoundations/g, "");
transform: return $.replace(/\*CloudEvent/g, "messaging.CloudEvent");

# delete some models that we don't need.
- from:
- models.go
where: $
transform: return $.replace(/\/\/ (AzureCoreFoundation|CloudEvent).+?\n}/sg, "");
richardpark-msft marked this conversation as resolved.
Show resolved Hide resolved
- from:
- models_serde.go
where: $
transform: return $.replace(/\/\/ MarshalJSON implements the json\.Marshaller interface for type (AzureCoreFoundation|CloudEvent).+?\n}/sg, "");
- from:
- models_serde.go
where: $
transform: return $.replace(/\/\/ UnmarshalJSON implements the json.Unmarshaller interface for type (AzureCoreFoundation|CloudEvent).+?\n}/sg, "");
```
2 changes: 1 addition & 1 deletion sdk/messaging/azeventgrid/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
// +build go1.18

//go:generate autorest ./autorest.md
//go:generate gofmt -w .
//go:generate goimports -w .

package azeventgrid
31 changes: 16 additions & 15 deletions sdk/messaging/azeventgrid/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,29 @@
trigger:
branches:
include:
- main
- feature/*
- hotfix/*
- release/*
- main
- feature/*
- hotfix/*
- release/*
paths:
include:
- sdk/messaging/azeventgrid
- eng/
- sdk/messaging/azeventgrid
- eng/

pr:
branches:
include:
- main
- feature/*
- hotfix/*
- release/*
- main
- feature/*
- hotfix/*
- release/*
paths:
include:
- sdk/messaging/azeventgrid

- sdk/messaging/azeventgrid

stages:
- template: /eng/pipelines/templates/jobs/archetype-sdk-client.yml
parameters:
ServiceDirectory: 'messaging/azeventgrid'
- template: /eng/pipelines/templates/jobs/archetype-sdk-client.yml
parameters:
ServiceDirectory: "messaging/azeventgrid"
RunLiveTests: true
Location: westus2
14 changes: 7 additions & 7 deletions sdk/messaging/azeventgrid/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 2 additions & 21 deletions sdk/messaging/azeventgrid/client_custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ import (
"net/http"

"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/messaging"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/internal/uuid"
)

// ClientOptions contains optional settings for [Client]
Expand Down Expand Up @@ -59,27 +58,11 @@ func NewClientWithSharedKeyCredential(endpoint string, key string, options *Clie
// - topicName - Topic Name.
// - events - Array of Cloud Events being published.
// - options - ClientPublishCloudEventsOptions contains the optional parameters for the Client.PublishCloudEvents method.
func (client *Client) PublishCloudEvents(ctx context.Context, topicName string, events []*CloudEvent, options *PublishCloudEventsOptions) (PublishCloudEventsResponse, error) {
func (client *Client) PublishCloudEvents(ctx context.Context, topicName string, events []messaging.CloudEvent, options *PublishCloudEventsOptions) (PublishCloudEventsResponse, error) {
ctx = runtime.WithHTTPHeader(ctx, http.Header{
"Content-type": []string{"application/cloudevents-batch+json; charset=utf-8"},
})

for _, evt := range events {
if evt.ID == nil {
id, err := uuid.New()

if err != nil {
return PublishCloudEventsResponse{}, err
}

evt.ID = to.Ptr(id.String())
}

if evt.SpecVersion == nil || *evt.SpecVersion == "" {
evt.SpecVersion = &defaultSpecVersion
}
}

return client.internalPublishCloudEvents(ctx, topicName, events, options)
}

Expand All @@ -92,5 +75,3 @@ func (p *skpolicy) Do(req *policy.Request) (*http.Response, error) {
req.Raw().Header.Add("Authorization", "SharedAccessKey "+p.Key)
return req.Next()
}

var defaultSpecVersion = "1.0"
Loading