Skip to content

Commit

Permalink
feat: added dependency support to azure
Browse files Browse the repository at this point in the history
  • Loading branch information
AvineshTripathi committed Jun 19, 2024
1 parent fa02724 commit 9a46f08
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
27 changes: 27 additions & 0 deletions providers/azure/compute/snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func Snapshots(ctx context.Context, client providers.ProviderClient) ([]models.R
ResourceId: *snapshot.ID,
Cost: 0,
Name: *snapshot.Name,
Relations: getSnapshotRelation(snapshot),
FetchedAt: time.Now(),
Tags: tags,
CreatedAt: *snapshot.Properties.TimeCreated,
Expand All @@ -62,3 +63,29 @@ func Snapshots(ctx context.Context, client providers.ProviderClient) ([]models.R
}).Info("Fetched resources")
return resources, nil
}

func getSnapshotRelation(snp *armcompute.Snapshot) []models.Link {
var rel []models.Link

if snp.Properties.CreationData != nil {
if snp.Properties.CreationData.ImageReference != nil && snp.Properties.CreationData.ImageReference.ID != nil {
rel = append(rel, models.Link{
ResourceID: *snp.Properties.CreationData.ImageReference.ID,
Type: "Image",
Name: *snp.Properties.CreationData.ImageReference.ID,
Relation: "USES",
})
}

if snp.Properties.CreationData.SourceResourceID != nil {
rel = append(rel, models.Link{
ResourceID: *snp.Properties.CreationData.SourceResourceID,
Type: "Disk",
Name: *snp.Properties.CreationData.SourceResourceID,
Relation: "USES",
})
}

}
return rel
}
27 changes: 27 additions & 0 deletions providers/azure/compute/virtual_machines.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func VirtualMachines(ctx context.Context, client providers.ProviderClient) ([]mo
Cost: cost,
Name: *vm.Name,
FetchedAt: time.Now(),
Relations: getVmRelation(vm),
Tags: tags,
Link: fmt.Sprintf("https://portal.azure.com/#resource%s", *vm.ID),
})
Expand All @@ -87,3 +88,29 @@ func VirtualMachines(ctx context.Context, client providers.ProviderClient) ([]mo
}).Info("Fetched resources")
return resources, nil
}

func getVmRelation(vm *armcompute.VirtualMachine) []models.Link {

var rel []models.Link

if vm.Properties.StorageProfile != nil && vm.Properties.StorageProfile.DataDisks != nil {
for _, disk := range vm.Properties.StorageProfile.DataDisks {
rel = append(rel, models.Link{
ResourceID: *disk.ManagedDisk.ID,
Type: "Disk",
Name: *disk.Name,
Relation: "USES",
})
}

if vm.Properties.StorageProfile.ImageReference != nil {
rel = append(rel, models.Link{
ResourceID: *vm.Properties.StorageProfile.ImageReference.ID,
Type: "Image",
Name: *vm.Properties.StorageProfile.ImageReference.ID,
Relation: "USES",
})
}
}
return rel
}

0 comments on commit 9a46f08

Please sign in to comment.