Skip to content
Merged
15 changes: 15 additions & 0 deletions custom/cloudfront/distributions/dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,21 @@ func (d *DistributionDAO) Get(ctx context.Context, id string) (dao.Resource, err
}

res := NewDistributionResource(summary)

// Fetch tags (only on Get/describe, not on List)
if arn := appaws.Str(dist.ARN); arn != "" {
tagsOutput, err := d.client.ListTagsForResource(ctx, &cloudfront.ListTagsForResourceInput{
Resource: &arn,
})
if err == nil && tagsOutput.Tags != nil {
for _, tag := range tagsOutput.Tags.Items {
if tag.Key != nil && tag.Value != nil {
res.Tags[*tag.Key] = *tag.Value
}
}
}
}

// Store the invalidation batches from the full distribution
if dist.InProgressInvalidationBatches != nil {
res.InProgressInvalidations = *dist.InProgressInvalidationBatches
Expand Down
54 changes: 29 additions & 25 deletions custom/cloudfront/distributions/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package distributions

import (
"fmt"
"slices"
"strings"

"github.com/clawscli/claws/internal/dao"
Expand All @@ -25,11 +26,10 @@ func NewDistributionRenderer() *DistributionRenderer {
Resource: "distributions",
Cols: []render.Column{
{Name: "ID", Width: 16, Getter: getDistributionId},
{Name: "DOMAIN", Width: 32, Getter: getDomainName},
{Name: "DOMAIN", Width: 35, Getter: getDomainName},
{Name: "STATUS", Width: 12, Getter: getStatus},
{Name: "ORIGIN", Width: 25, Getter: getDefaultOrigin},
{Name: "ALIASES", Width: 8, Getter: getAliasCount},
{Name: "AGE", Width: 10, Getter: getAge},
{Name: "ALIASES", Width: 20, Getter: getAllAliases}, // last column: expands to fill screen
},
},
}
Expand Down Expand Up @@ -60,37 +60,26 @@ func getStatus(r dao.Resource) string {
return ""
}

func getDefaultOrigin(r dao.Resource) string {
func getAge(r dao.Resource) string {
if dist, ok := r.(*DistributionResource); ok {
origin := dist.DefaultOrigin()
if len(origin) > 23 {
return origin[:23] + "..."
if dist.Item.LastModifiedTime != nil {
return render.FormatAge(*dist.Item.LastModifiedTime)
}
return origin
}
return ""
return "-"
}

func getAliasCount(r dao.Resource) string {
func getAllAliases(r dao.Resource) string {
if dist, ok := r.(*DistributionResource); ok {
count := dist.AliasCount()
if count > 0 {
return fmt.Sprintf("%d", count)
aliases := dist.Aliases()
if len(aliases) == 0 {
return "-"
}
return "-"
return strings.Join(aliases, ", ")
}
return ""
}

func getAge(r dao.Resource) string {
if dist, ok := r.(*DistributionResource); ok {
if dist.Item.LastModifiedTime != nil {
return render.FormatAge(*dist.Item.LastModifiedTime)
}
}
return "-"
}

// RenderDetail renders detailed distribution information
func (r *DistributionRenderer) RenderDetail(resource dao.Resource) string {
dist, ok := resource.(*DistributionResource)
Expand All @@ -116,7 +105,9 @@ func (r *DistributionRenderer) RenderDetail(resource dao.Resource) string {
// Aliases
if aliases := dist.Aliases(); len(aliases) > 0 {
d.Section("Alternate Domain Names (CNAMEs)")
d.Field("Aliases", strings.Join(aliases, ", "))
for _, alias := range aliases {
d.Field("Alias", alias)
}
}

// Origins
Expand Down Expand Up @@ -198,7 +189,20 @@ func (r *DistributionRenderer) RenderDetail(resource dao.Resource) string {
d.Field("WAF Web ACL", webAclId)
}

// Status
// Tags (only available after d:describe / Enter)
if tags := dist.GetTags(); len(tags) > 0 {
d.Section("Tags")
keys := make([]string, 0, len(tags))
for k := range tags {
keys = append(keys, k)
}
slices.Sort(keys)
for _, key := range keys {
d.Field(key, tags[key])
}
}

// In-progress invalidations
if batches := dist.InProgressInvalidationBatches(); batches > 0 {
d.Section("In Progress")
d.Field("Invalidation Batches", fmt.Sprintf("%d", batches))
Expand Down
Loading