@@ -21,6 +21,7 @@ import (
2121 "gopkg.in/src-d/go-git.v4"
2222
2323 ackgenconfig "github.com/aws-controllers-k8s/code-generator/pkg/generate/config"
24+ ackmetadata "github.com/aws-controllers-k8s/code-generator/pkg/metadata"
2425 ackmodel "github.com/aws-controllers-k8s/code-generator/pkg/model"
2526 "github.com/aws-controllers-k8s/code-generator/pkg/util"
2627)
@@ -35,31 +36,36 @@ var (
3536// of each non-deprecated version with their correspending ackmodel.Model
3637// and APIInfos.
3738type APIVersionManager struct {
38- gitRepo * git.Repository
39+ gitRepo * git.Repository
40+ metadata ackmetadata.ServiceMetadata
3941
4042 hubVersion string
4143 spokeVersions []string
4244
43- deprecatedVersions []string
44- removedVersions []string
45-
46- apiInfos map [string ]APIInfo
45+ apiInfos map [string ]ackmetadata.APIInfo
4746 models map [string ]* ackmodel.Model
4847}
4948
5049// NewAPIVersionManager initialises and returns a new APIVersionManager.
5150func NewAPIVersionManager (
5251 sdkCacheDir string ,
52+ metadataPath string ,
5353 serviceAlias string ,
5454 hubVersion string ,
55- apisInfo map [string ]APIInfo ,
55+ apisInfo map [string ]ackmetadata. APIInfo ,
5656 defaultConfig ackgenconfig.Config ,
5757) (* APIVersionManager , error ) {
5858 if len (apisInfo ) == 0 {
5959 return nil , fmt .Errorf ("empty apisInfo" )
6060 }
6161
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+
6369 gitRepo , err := util .LoadRepository (sdkCacheDir )
6470 if err != nil {
6571 return nil , fmt .Errorf ("cannot read sdk git repository: %v" , err )
@@ -68,11 +74,19 @@ func NewAPIVersionManager(
6874 SDKAPIHelper := ackmodel .NewSDKHelper (sdkCacheDir )
6975
7076 // 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 )
7690 }
7791
7892 err = SDKAPIHelper .WithSDKVersion (apiInfo .AWSSDKVersion )
@@ -87,25 +101,26 @@ func NewAPIVersionManager(
87101
88102 i , err := ackmodel .New (
89103 SDKAPI ,
90- apiVersion ,
104+ version . APIVersion ,
91105 apiInfo .GeneratorConfigPath ,
92106 defaultConfig ,
93107 )
94108 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 )
96110 }
97- models [apiVersion ] = i
111+ models [version . APIVersion ] = i
98112 }
99113
100114 sort .Strings (spokeVersions )
101115 model := & APIVersionManager {
102116 gitRepo : gitRepo ,
117+ metadata : metadata ,
103118 hubVersion : hubVersion ,
104119 spokeVersions : spokeVersions ,
105120 apiInfos : apisInfo ,
106121 models : models ,
107122 }
108- // TODO(hilalymh): Audit deprecated and removed versions
123+
109124 return model , nil
110125}
111126
@@ -140,10 +155,10 @@ func (m *APIVersionManager) VerifyAPIVersions(apiVersions ...string) error {
140155 if ! ok {
141156 return fmt .Errorf ("%v: %s" , ErrAPIVersionNotFound , apiVersion )
142157 }
143- if apiInfo .Status == APIStatusDeprecated {
158+ if apiInfo .Status == ackmetadata . APIStatusDeprecated {
144159 return fmt .Errorf ("%v: %s" , ErrAPIVersionDeprecated , apiVersion )
145160 }
146- if apiInfo .Status == APIStatusRemoved {
161+ if apiInfo .Status == ackmetadata . APIStatusRemoved {
147162 return fmt .Errorf ("%v: %s" , ErrAPIVersionRemoved , apiVersion )
148163 }
149164 }
0 commit comments