Skip to content

Commit

Permalink
[azsystemevents] switch over to use tsp-client (#23830)
Browse files Browse the repository at this point in the history
As part of this we've moved forward to the latest commit, which has removed Azure Media services events, since that service has been retired.
  • Loading branch information
richardpark-msft authored Dec 6, 2024
1 parent da0498b commit 8ebca98
Show file tree
Hide file tree
Showing 16 changed files with 357 additions and 3,002 deletions.
5 changes: 4 additions & 1 deletion sdk/messaging/eventgrid/azsystemevents/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# Release History

## 0.5.1 (Unreleased)
## 0.6.0 (Unreleased)

### Features Added


### Breaking Changes

- Azure Media services has been retired - all related system events have been removed. See the [retirement announcement](https://azure.microsoft.com/updates?id=retirement-notice-azure-media-services-is-being-retired-on-30-june-2024) for more details.

### Bugs Fixed

### Other Changes
Expand Down
2 changes: 1 addition & 1 deletion sdk/messaging/eventgrid/azsystemevents/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

//go:generate pwsh ./testdata/gen.ps1
//go:generate tsp-client update
//go:generate goimports -w .
//go:generate go run ./internal/generate
//go:generate goimports -w ./..
Expand Down
133 changes: 0 additions & 133 deletions sdk/messaging/eventgrid/azsystemevents/constants.go

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

14 changes: 0 additions & 14 deletions sdk/messaging/eventgrid/azsystemevents/interfaces.go

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package main
import (
"fmt"
"os"
"regexp"
"strings"

"github.com/Azure/azure-sdk-for-go/sdk/messaging/eventgrid/azsystemevents/internal/gopls"
Expand All @@ -26,6 +27,10 @@ func main() {
return err
}

if err := deleteUnneededTypes(); err != nil {
return err
}

if err := generateSystemEventEnum(); err != nil {
return err
}
Expand All @@ -42,6 +47,71 @@ func main() {
fmt.Printf("DONE\n")
}

// deleteUnneededTypes deletes types that are vestigial. Event Grid system events, in TypeSpec,
// use inheritance. We model this by pushing the parent properties into the child objects, so the
// parent object is not needed.
// NOTE: this is a workaround, I'm running into some conflicting behavior as I move between tsp-client
// and my "homebrew" version calling the powershell scripts directly.
func deleteUnneededTypes() error {
typesToDelete := []string{
"ACSChatEventBaseProperties",
"ACSChatEventInThreadBaseProperties",
"ACSChatMessageEventBaseProperties",
"ACSChatMessageEventInThreadBaseProperties",
"ACSChatThreadEventBaseProperties",
"ACSChatThreadEventInThreadBaseProperties",
"ACSMessageEventData",
"ACSRouterEventData",
"ACSRouterJobEventData",
"ACSRouterWorkerEventData",
"ACSSmsEventBaseProperties",
"AppConfigurationSnapshotEventData",
"AVSClusterEventData",
"AVSPrivateCloudEventData",
"AVSScriptExecutionEventData",
"ContainerRegistryArtifactEventData",
"ContainerRegistryEventData",
"ContainerServiceClusterSupportEventData",
"ContainerServiceNodePoolRollingEventData",
"DeviceConnectionStateEventProperties",
"DeviceLifeCycleEventProperties",
"DeviceTelemetryEventProperties",
"EventGridMQTTClientEventData",
"MapsGeofenceEventProperties",
"ResourceNotificationsResourceDeletedEventData",
"ResourceNotificationsResourceUpdatedEventData",
}

for _, typeToDelete := range typesToDelete {
// ex: // ACSChatEventBaseProperties - Schema of common properties of all chat events
if err := replaceAll("models.go", fmt.Sprintf("(?is)// %s.+?\n}\n", typeToDelete), ""); err != nil {
return err
}

// ex: // MarshalJSON implements the json.Marshaller interface for type ACSChatEventBaseProperties.
// ex: // UnmarshalJSON implements the json.Unmarshaller interface for type ACSChatEventBaseProperties.
if err := replaceAll("models_serde.go",
fmt.Sprintf("(?is)// (?:Marshal|Unmarshal)JSON\\s*implements\\s*the\\s*json\\.(?:Marshaller|Unmarshaller)\\s*interface\\s*for\\s*type\\s*%s.+?\n}\n", typeToDelete), ""); err != nil {
return err
}
}

return nil
}

func replaceAll(filename string, re string, replacement string) error {
buff, err := os.ReadFile(filename)

if err != nil {
return err
}

modelsRE := regexp.MustCompile(re)
buff = modelsRE.ReplaceAll(buff, []byte(replacement))

return os.WriteFile(filename, buff, 0600)
}

// swapErrorTypes handles turning most of the auto-generated errors into a single consistent error type.
// The key is that the Error type doesn't export human readable strings as fields - it's all contained in
// the Error() field.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func getConstantValues(reader io.ReadCloser) (map[string]constant, error) {
}

if !ignorable {
log.Printf("===========> DIDN'T MATCH REGEX: %q ", comment)
log.Fatalf("Non-system event type not classified: %q ", comment)
}
}

Expand Down
2 changes: 1 addition & 1 deletion sdk/messaging/eventgrid/azsystemevents/internal/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ const (
ModuleName = "azsystemevents"

// ModuleVersion is the semantic version (see http://semver.org) of this module.
ModuleVersion = "v0.5.1"
ModuleVersion = "v0.6.0"
)
Loading

0 comments on commit 8ebca98

Please sign in to comment.