@@ -21,6 +21,7 @@ import (
21
21
"gopkg.in/src-d/go-git.v4"
22
22
23
23
ackgenconfig "github.com/aws-controllers-k8s/code-generator/pkg/generate/config"
24
+ ackmetadata "github.com/aws-controllers-k8s/code-generator/pkg/metadata"
24
25
ackmodel "github.com/aws-controllers-k8s/code-generator/pkg/model"
25
26
"github.com/aws-controllers-k8s/code-generator/pkg/util"
26
27
)
@@ -35,31 +36,36 @@ var (
35
36
// of each non-deprecated version with their correspending ackmodel.Model
36
37
// and APIInfos.
37
38
type APIVersionManager struct {
38
- gitRepo * git.Repository
39
+ gitRepo * git.Repository
40
+ metadata ackmetadata.ServiceMetadata
39
41
40
42
hubVersion string
41
43
spokeVersions []string
42
44
43
- deprecatedVersions []string
44
- removedVersions []string
45
-
46
- apiInfos map [string ]APIInfo
45
+ apiInfos map [string ]ackmetadata.APIInfo
47
46
models map [string ]* ackmodel.Model
48
47
}
49
48
50
49
// NewAPIVersionManager initialises and returns a new APIVersionManager.
51
50
func NewAPIVersionManager (
52
51
sdkCacheDir string ,
52
+ metadataPath string ,
53
53
serviceAlias string ,
54
54
hubVersion string ,
55
- apisInfo map [string ]APIInfo ,
55
+ apisInfo map [string ]ackmetadata. APIInfo ,
56
56
defaultConfig ackgenconfig.Config ,
57
57
) (* APIVersionManager , error ) {
58
58
if len (apisInfo ) == 0 {
59
59
return nil , fmt .Errorf ("empty apisInfo" )
60
60
}
61
61
62
- spokeVersions := make ([]string , 0 , len (apisInfo )- 1 )
62
+ metadata , err := ackmetadata .NewServiceMetadata (metadataPath )
63
+ if err != nil {
64
+ return nil , err
65
+ }
66
+
67
+ spokeVersions := []string {}
68
+
63
69
gitRepo , err := util .LoadRepository (sdkCacheDir )
64
70
if err != nil {
65
71
return nil , fmt .Errorf ("cannot read sdk git repository: %v" , err )
@@ -68,11 +74,19 @@ func NewAPIVersionManager(
68
74
SDKAPIHelper := ackmodel .NewSDKHelper (sdkCacheDir )
69
75
70
76
// create model for each non-deprecated api version
71
- models := make (map [string ]* ackmodel.Model , len (apisInfo ))
72
- for apiVersion , apiInfo := range apisInfo {
73
- // TODO(a-hilaly) filter deprecated and removed api versions
74
- if apiVersion != hubVersion {
75
- spokeVersions = append (spokeVersions , apiVersion )
77
+ models := map [string ]* ackmodel.Model {}
78
+ for _ , version := range metadata .APIVersions {
79
+ if version .Status == ackmetadata .APIStatusDeprecated || version .Status == ackmetadata .APIStatusRemoved {
80
+ continue
81
+ }
82
+
83
+ if version .APIVersion != hubVersion {
84
+ spokeVersions = append (spokeVersions , version .APIVersion )
85
+ }
86
+
87
+ apiInfo , ok := apisInfo [version .APIVersion ]
88
+ if ! ok {
89
+ return nil , fmt .Errorf ("could not find API info for API version %s" , version .APIVersion )
76
90
}
77
91
78
92
err = SDKAPIHelper .WithSDKVersion (apiInfo .AWSSDKVersion )
@@ -87,25 +101,26 @@ func NewAPIVersionManager(
87
101
88
102
i , err := ackmodel .New (
89
103
SDKAPI ,
90
- apiVersion ,
104
+ version . APIVersion ,
91
105
apiInfo .GeneratorConfigPath ,
92
106
defaultConfig ,
93
107
)
94
108
if err != nil {
95
- return nil , fmt .Errorf ("cannot create model for API version %s: %v" , apiVersion , err )
109
+ return nil , fmt .Errorf ("cannot create model for API version %s: %v" , version . APIVersion , err )
96
110
}
97
- models [apiVersion ] = i
111
+ models [version . APIVersion ] = i
98
112
}
99
113
100
114
sort .Strings (spokeVersions )
101
115
model := & APIVersionManager {
102
116
gitRepo : gitRepo ,
117
+ metadata : metadata ,
103
118
hubVersion : hubVersion ,
104
119
spokeVersions : spokeVersions ,
105
120
apiInfos : apisInfo ,
106
121
models : models ,
107
122
}
108
- // TODO(hilalymh): Audit deprecated and removed versions
123
+
109
124
return model , nil
110
125
}
111
126
@@ -140,10 +155,10 @@ func (m *APIVersionManager) VerifyAPIVersions(apiVersions ...string) error {
140
155
if ! ok {
141
156
return fmt .Errorf ("%v: %s" , ErrAPIVersionNotFound , apiVersion )
142
157
}
143
- if apiInfo .Status == APIStatusDeprecated {
158
+ if apiInfo .Status == ackmetadata . APIStatusDeprecated {
144
159
return fmt .Errorf ("%v: %s" , ErrAPIVersionDeprecated , apiVersion )
145
160
}
146
- if apiInfo .Status == APIStatusRemoved {
161
+ if apiInfo .Status == ackmetadata . APIStatusRemoved {
147
162
return fmt .Errorf ("%v: %s" , ErrAPIVersionRemoved , apiVersion )
148
163
}
149
164
}
0 commit comments