-
Notifications
You must be signed in to change notification settings - Fork 187
/
mark_latest_storage_variant_as_hub_version.go
52 lines (42 loc) · 1.72 KB
/
mark_latest_storage_variant_as_hub_version.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT license.
*/
package pipeline
import (
"context"
"github.com/pkg/errors"
"github.com/Azure/azure-service-operator/v2/tools/generator/internal/astmodel"
)
// MarkLatestStorageVariantAsHubVersionID is the unique identifier for this pipeline stage
const MarkLatestStorageVariantAsHubVersionID = "markLatestStorageVariantAsHubVersion"
// MarkLatestStorageVariantAsHubVersion creates a Stage to mark the latest non-preview storage variant of a resource
// as the hub version of that resource for persistence
func MarkLatestStorageVariantAsHubVersion() *Stage {
stage := NewStage(
MarkLatestStorageVariantAsHubVersionID,
"Mark the latest GA storage variant of each resource as the hub version",
func(ctx context.Context, state *State) (*State, error) {
updatedDefs, err := astmodel.FindResourceDefinitions(state.Definitions()).Process(
func(def astmodel.TypeDefinition) (*astmodel.TypeDefinition, error) {
rsrc := astmodel.MustBeResourceType(def.Type())
hub, err := state.ConversionGraph().FindHub(def.Name(), state.Definitions())
if err != nil {
return nil, errors.Wrapf(err, "finding hub type for %s", def.Name())
}
if astmodel.TypeEquals(def.Name(), hub) {
// We have the hub type, modify it and return for Process() to accumulate into updatedDefs
def = def.WithType(rsrc.MarkAsStorageVersion())
return &def, nil
}
// Nothing to modify, nothing to return
return nil, nil
})
if err != nil {
return nil, errors.Wrap(err, "marking storage versions")
}
return state.WithOverlaidDefinitions(updatedDefs), nil
})
stage.RequiresPrerequisiteStages(CreateConversionGraphStageId)
return stage
}