@@ -73,7 +73,7 @@ func main() {
7373 }
7474
7575 // Get CDR configuration (access tier and version)
76- accessTier , cdrVersion , err := GetCdrConfiguration (mappings , aouVersion )
76+ accessTier , cdrVersion , err := GetCdrConfiguration (mappings , * aouVersion )
7777 if err != nil {
7878 log .Fatalf ("Failed to get CDR configuration: %v" , err )
7979 }
@@ -181,31 +181,13 @@ func GetGcpProject(ctx context.Context, client *wsm.ClientWithResponses) (string
181181// GetAoUVersion retrieves the AoU data collection version by inspecting the
182182// lineage of resources in the specified workspace and comparing them to the
183183// known AoU data collection UUIDs.
184- func GetAoUVersion (ctx context.Context , client * wsm.ClientWithResponses , mappings map [uuid.UUID ]DataCollectionMapping ) (AoUVersion , error ) {
184+ func GetAoUVersion (ctx context.Context , client * wsm.ClientWithResponses , mappings map [uuid.UUID ]DataCollectionMapping ) (* AoUVersion , error ) {
185185 resources , err := ListWsmResources (ctx , client , "~" + * workspaceUfid )
186186 if err != nil {
187- return AoUVersion {} , err
187+ return nil , err
188188 }
189189
190- sourceResourceLineage , err := FirstAoUResource (resources , mappings )
191- if err != nil {
192- return AoUVersion {}, err
193- }
194-
195- version , err := GetVersionForResource (
196- ctx ,
197- client ,
198- sourceResourceLineage .SourceResourceId ,
199- sourceResourceLineage .SourceWorkspaceId .String ())
200- if err != nil {
201- return AoUVersion {}, err
202- }
203-
204- aouVersion := AoUVersion {
205- DataCollectionId : sourceResourceLineage .SourceWorkspaceId ,
206- Version : version ,
207- }
208- return aouVersion , nil
190+ return GetVersionFromAoUResource (ctx , client , resources , mappings )
209191}
210192
211193// GetVersionForResource retrieves the version string for a given resource by
@@ -238,6 +220,10 @@ func GetVersionForResource(
238220 continue
239221 }
240222
223+ if resource .Metadata .FolderId == nil {
224+ return "" , fmt .Errorf ("failed to get AoU resource folder" )
225+ }
226+
241227 folder , err = GetRootFolder (* resource .Metadata .FolderId , folders )
242228 if err != nil {
243229 return "" , fmt .Errorf ("failed to get root folder: %v" , err )
@@ -266,21 +252,28 @@ func GetRootFolder(leafFolderId uuid.UUID, folders map[uuid.UUID]*wsm.Folder) (*
266252 return folder , nil
267253}
268254
269- func FirstAoUResource (resources * wsm.ResourceList , mappings map [uuid.UUID ]DataCollectionMapping ) (wsm.ResourceLineageEntry , error ) {
255+ // GetVersionFromAoUResource retrieves the version from the aou resource's parent folder.
256+ // Returns eagerly as soon as a version is found as there should only be one DC version per workspace.
257+ func GetVersionFromAoUResource (ctx context.Context , client * wsm.ClientWithResponses , resources * wsm.ResourceList , mappings map [uuid.UUID ]DataCollectionMapping ) (* AoUVersion , error ) {
270258 for _ , resource := range resources .Resources {
271259 lineage := resource .Metadata .ResourceLineage
272260
273261 for _ , lineageEntry := range * lineage {
274- // Return the first lineage entry whose source workspace ID is
275- // present in the mappings. There should not be multiple versions
276- // of the AoU data collection in the same workspace.
277262 if _ , ok := mappings [lineageEntry .SourceWorkspaceId ]; ok {
278- return lineageEntry , nil
263+ version , err := GetVersionForResource (
264+ ctx ,
265+ client ,
266+ lineageEntry .SourceResourceId ,
267+ lineageEntry .SourceWorkspaceId .String ())
268+ if err != nil {
269+ continue
270+ }
271+ return & AoUVersion {DataCollectionId : lineageEntry .SourceWorkspaceId , Version : version }, nil
279272 }
280273 }
281274 }
282275
283- return wsm. ResourceLineageEntry {} , fmt .Errorf ("no AoU resources in workspace" )
276+ return nil , fmt .Errorf ("no AoU resources in workspace" )
284277}
285278
286279func GetWsmClient (authToken string ) (* wsm.ClientWithResponses , error ) {
0 commit comments