Skip to content

Commit

Permalink
Apply golangci-lint autofixes
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidS-ovm committed Feb 12, 2024
1 parent 1a390d2 commit 5a7246b
Show file tree
Hide file tree
Showing 14 changed files with 168 additions and 168 deletions.
14 changes: 7 additions & 7 deletions cmd/createbookmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,23 +113,23 @@ func CreateBookmark(ctx context.Context, ready chan bool) int {
return 1
}
log.WithContext(ctx).WithFields(log.Fields{
"bookmark-uuid": uuid.UUID(response.Msg.Bookmark.Metadata.UUID),
"bookmark-created": response.Msg.Bookmark.Metadata.Created,
"bookmark-name": response.Msg.Bookmark.Properties.Name,
"bookmark-description": response.Msg.Bookmark.Properties.Description,
"bookmark-uuid": uuid.UUID(response.Msg.GetBookmark().GetMetadata().GetUUID()),
"bookmark-created": response.Msg.GetBookmark().GetMetadata().GetCreated(),
"bookmark-name": response.Msg.GetBookmark().GetProperties().GetName(),
"bookmark-description": response.Msg.GetBookmark().GetProperties().GetDescription(),
}).Info("created bookmark")
for _, q := range response.Msg.Bookmark.Properties.Queries {
for _, q := range response.Msg.GetBookmark().GetProperties().GetQueries() {
log.WithContext(ctx).WithFields(log.Fields{
"bookmark-query": q,
}).Info("created bookmark query")
}
for _, i := range response.Msg.Bookmark.Properties.ExcludedItems {
for _, i := range response.Msg.GetBookmark().GetProperties().GetExcludedItems() {
log.WithContext(ctx).WithFields(log.Fields{
"bookmark-excluded-item": i,
}).Info("created bookmark excluded item")
}

b, err := json.MarshalIndent(response.Msg.Bookmark.Properties, "", " ")
b, err := json.MarshalIndent(response.Msg.GetBookmark().GetProperties(), "", " ")
if err != nil {
log.Infof("Error rendering bookmark: %v", err)
} else {
Expand Down
6 changes: 3 additions & 3 deletions cmd/endchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ func EndChange(ctx context.Context, ready chan bool) int {
for stream.Receive() {
msg := stream.Msg()
log.WithContext(ctx).WithFields(lf).WithFields(log.Fields{
"state": msg.State,
"items": msg.NumItems,
"edges": msg.NumEdges,
"state": msg.GetState(),
"items": msg.GetNumItems(),
"edges": msg.GetNumEdges(),
}).Info("progress")
}
if stream.Err() != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/getaffectedbookmarks.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func GetAffectedBookmarks(ctx context.Context, ready chan bool) int {
}).Error("failed to get affected bookmarks")
return 1
}
for _, u := range response.Msg.BookmarkUUIDs {
for _, u := range response.Msg.GetBookmarkUUIDs() {
bookmarkUuid := uuid.UUID(u)
log.WithContext(ctx).WithFields(log.Fields{
"uuid": bookmarkUuid,
Expand Down
10 changes: 5 additions & 5 deletions cmd/getbookmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ func GetBookmark(ctx context.Context, ready chan bool) int {
return 1
}
log.WithContext(ctx).WithFields(log.Fields{
"bookmark-uuid": uuid.UUID(response.Msg.Bookmark.Metadata.UUID),
"bookmark-created": response.Msg.Bookmark.Metadata.Created.AsTime(),
"bookmark-name": response.Msg.Bookmark.Properties.Name,
"bookmark-description": response.Msg.Bookmark.Properties.Description,
"bookmark-uuid": uuid.UUID(response.Msg.GetBookmark().GetMetadata().GetUUID()),
"bookmark-created": response.Msg.GetBookmark().GetMetadata().GetCreated().AsTime(),
"bookmark-name": response.Msg.GetBookmark().GetProperties().GetName(),
"bookmark-description": response.Msg.GetBookmark().GetProperties().GetDescription(),
}).Info("found bookmark")

b, err := json.MarshalIndent(response.Msg.Bookmark.ToMap(), "", " ")
b, err := json.MarshalIndent(response.Msg.GetBookmark().ToMap(), "", " ")
if err != nil {
log.Infof("Error rendering bookmark: %v", err)
} else {
Expand Down
70 changes: 35 additions & 35 deletions cmd/getchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,15 @@ fetch:
return 1
}
log.WithContext(ctx).WithFields(log.Fields{
"change-uuid": uuid.UUID(changeRes.Msg.Change.Metadata.UUID),
"change-created": changeRes.Msg.Change.Metadata.CreatedAt.AsTime(),
"change-status": changeRes.Msg.Change.Metadata.Status.String(),
"change-name": changeRes.Msg.Change.Properties.Title,
"change-description": changeRes.Msg.Change.Properties.Description,
"change-uuid": uuid.UUID(changeRes.Msg.GetChange().GetMetadata().GetUUID()),
"change-created": changeRes.Msg.GetChange().GetMetadata().GetCreatedAt().AsTime(),
"change-status": changeRes.Msg.GetChange().GetMetadata().GetStatus().String(),
"change-name": changeRes.Msg.GetChange().GetProperties().GetTitle(),
"change-description": changeRes.Msg.GetChange().GetProperties().GetDescription(),
}).Info("found change")

if changeRes.Msg.Change.Metadata.RiskCalculationStatus.Status == sdp.RiskCalculationStatus_STATUS_INPROGRESS {
log.WithContext(ctx).WithField("status", changeRes.Msg.Change.Metadata.RiskCalculationStatus.Status.String()).Info("waiting for risk calculation")
if changeRes.Msg.GetChange().GetMetadata().GetRiskCalculationStatus().GetStatus() == sdp.RiskCalculationStatus_STATUS_INPROGRESS {
log.WithContext(ctx).WithField("status", changeRes.Msg.GetChange().GetMetadata().GetRiskCalculationStatus().GetStatus().String()).Info("waiting for risk calculation")
time.Sleep(10 * time.Second)
// retry
} else {
Expand All @@ -144,9 +144,9 @@ fetch:

switch viper.GetString("format") {
case "json":
b, err := json.MarshalIndent(changeRes.Msg.Change.ToMap(), "", " ")
b, err := json.MarshalIndent(changeRes.Msg.GetChange().ToMap(), "", " ")
if err != nil {
log.WithContext(ctx).WithField("input", fmt.Sprintf("%#v", changeRes.Msg.Change.ToMap())).WithError(err).Error("Error rendering change")
log.WithContext(ctx).WithField("input", fmt.Sprintf("%#v", changeRes.Msg.GetChange().ToMap())).WithError(err).Error("Error rendering change")
return 1
}

Expand Down Expand Up @@ -230,25 +230,25 @@ fetch:
ChangeUrl: fmt.Sprintf("%v/changes/%v", frontend, changeUuid.String()),
ExpectedChanges: []TemplateItem{},
UnmappedChanges: []TemplateItem{},
BlastItems: int(changeRes.Msg.Change.Metadata.NumAffectedItems),
BlastEdges: int(changeRes.Msg.Change.Metadata.NumAffectedEdges),
BlastItems: int(changeRes.Msg.GetChange().GetMetadata().GetNumAffectedItems()),
BlastEdges: int(changeRes.Msg.GetChange().GetMetadata().GetNumAffectedEdges()),
Risks: []TemplateRisk{},
AssetPath: fmt.Sprintf("https://raw.githubusercontent.com/overmindtech/ovm-cli/%v/assets", assetVersion),
}

for _, item := range changeRes.Msg.Change.Properties.PlannedChanges {
for _, item := range changeRes.Msg.GetChange().GetProperties().GetPlannedChanges() {
var before, after string
if item.Before != nil {
bb, err := yaml.Marshal(item.Before.Attributes.AttrStruct.AsMap())
if item.GetBefore() != nil {
bb, err := yaml.Marshal(item.GetBefore().GetAttributes().GetAttrStruct().AsMap())
if err != nil {
log.WithContext(ctx).WithError(err).Error("error marshalling 'before' attributes")
before = ""
} else {
before = string(bb)
}
}
if item.After != nil {
ab, err := yaml.Marshal(item.After.Attributes.AttrStruct.AsMap())
if item.GetAfter() != nil {
ab, err := yaml.Marshal(item.GetAfter().GetAttributes().GetAttrStruct().AsMap())
if err != nil {
log.WithContext(ctx).WithError(err).Error("error marshalling 'after' attributes")
after = ""
Expand All @@ -259,40 +259,40 @@ fetch:
edits := myers.ComputeEdits(diffspan.URIFromPath("current"), before, after)
diff := fmt.Sprint(gotextdiff.ToUnified("current", "planned", before, edits))

if item.Item != nil {
if item.GetItem() != nil {
data.ExpectedChanges = append(data.ExpectedChanges, TemplateItem{
StatusAlt: status[item.Status].StatusAlt,
StatusIcon: status[item.Status].StatusIcon,
Type: item.Item.Type,
Title: item.Item.UniqueAttributeValue,
StatusAlt: status[item.GetStatus()].StatusAlt,
StatusIcon: status[item.GetStatus()].StatusIcon,
Type: item.GetItem().GetType(),
Title: item.GetItem().GetUniqueAttributeValue(),
Diff: diff,
})
} else {
var typ, title string
if item.After != nil {
typ = item.After.Type
title = item.After.UniqueAttributeValue()
} else if item.Before != nil {
typ = item.Before.Type
title = item.Before.UniqueAttributeValue()
if item.GetAfter() != nil {
typ = item.GetAfter().GetType()
title = item.GetAfter().UniqueAttributeValue()
} else if item.GetBefore() != nil {
typ = item.GetBefore().GetType()
title = item.GetBefore().UniqueAttributeValue()
}
data.UnmappedChanges = append(data.UnmappedChanges, TemplateItem{
StatusAlt: status[item.Status].StatusAlt,
StatusIcon: status[item.Status].StatusIcon,
StatusAlt: status[item.GetStatus()].StatusAlt,
StatusIcon: status[item.GetStatus()].StatusIcon,
Type: typ,
Title: title,
Diff: diff,
})
}
}

for _, risk := range changeRes.Msg.Change.Metadata.Risks {
for _, risk := range changeRes.Msg.GetChange().GetMetadata().GetRisks() {
data.Risks = append(data.Risks, TemplateRisk{
SeverityAlt: severity[risk.Severity].SeverityAlt,
SeverityIcon: severity[risk.Severity].SeverityIcon,
SeverityText: severity[risk.Severity].SeverityText,
Title: risk.Title,
Description: risk.Description,
SeverityAlt: severity[risk.GetSeverity()].SeverityAlt,
SeverityIcon: severity[risk.GetSeverity()].SeverityIcon,
SeverityText: severity[risk.GetSeverity()].SeverityText,
Title: risk.GetTitle(),
Description: risk.GetDescription(),
})
}

Expand Down
16 changes: 8 additions & 8 deletions cmd/getsnapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,28 +96,28 @@ func GetSnapshot(ctx context.Context, ready chan bool) int {
return 1
}
log.WithContext(ctx).WithFields(log.Fields{
"snapshot-uuid": uuid.UUID(response.Msg.Snapshot.Metadata.UUID),
"snapshot-created": response.Msg.Snapshot.Metadata.Created.AsTime(),
"snapshot-name": response.Msg.Snapshot.Properties.Name,
"snapshot-description": response.Msg.Snapshot.Properties.Description,
"snapshot-uuid": uuid.UUID(response.Msg.GetSnapshot().GetMetadata().GetUUID()),
"snapshot-created": response.Msg.GetSnapshot().GetMetadata().GetCreated().AsTime(),
"snapshot-name": response.Msg.GetSnapshot().GetProperties().GetName(),
"snapshot-description": response.Msg.GetSnapshot().GetProperties().GetDescription(),
}).Info("found snapshot")
for _, q := range response.Msg.Snapshot.Properties.Queries {
for _, q := range response.Msg.GetSnapshot().GetProperties().GetQueries() {
log.WithContext(ctx).WithFields(log.Fields{
"snapshot-query": q,
}).Info("found snapshot query")
}
for _, i := range response.Msg.Snapshot.Properties.ExcludedItems {
for _, i := range response.Msg.GetSnapshot().GetProperties().GetExcludedItems() {
log.WithContext(ctx).WithFields(log.Fields{
"snapshot-excluded-item": i,
}).Info("found snapshot excluded item")
}
for _, i := range response.Msg.Snapshot.Properties.Items {
for _, i := range response.Msg.GetSnapshot().GetProperties().GetItems() {
log.WithContext(ctx).WithFields(log.Fields{
"snapshot-item": i,
}).Info("found snapshot item")
}

b, err := json.MarshalIndent(response.Msg.Snapshot.ToMap(), "", " ")
b, err := json.MarshalIndent(response.Msg.GetSnapshot().ToMap(), "", " ")
if err != nil {
log.Infof("Error rendering snapshot: %v", err)
} else {
Expand Down
4 changes: 2 additions & 2 deletions cmd/invite.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ func InvitesList(ctx context.Context) int {
t.SetOutputMirror(os.Stdout)
t.AppendHeader(table.Row{"Email", "Status"})

for _, invite := range resp.Msg.Invites {
t.AppendRow(table.Row{invite.Email, invite.Status.String()})
for _, invite := range resp.Msg.GetInvites() {
t.AppendRow(table.Row{invite.GetEmail(), invite.GetStatus().String()})
}

t.Render()
Expand Down
28 changes: 14 additions & 14 deletions cmd/listchanges.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,14 @@ func ListChanges(ctx context.Context, ready chan bool) int {
log.WithContext(ctx).WithError(err).Error("failed to list changes")
return 1
}
for _, change := range response.Msg.Changes {
changeUuid := uuid.UUID(change.Metadata.UUID)
for _, change := range response.Msg.GetChanges() {
changeUuid := uuid.UUID(change.GetMetadata().GetUUID())
log.WithContext(ctx).WithFields(log.Fields{
"change-uuid": changeUuid,
"change-created": change.Metadata.CreatedAt.AsTime(),
"change-status": change.Metadata.Status.String(),
"change-name": change.Properties.Title,
"change-description": change.Properties.Description,
"change-created": change.GetMetadata().GetCreatedAt().AsTime(),
"change-status": change.GetMetadata().GetStatus().String(),
"change-name": change.GetProperties().GetTitle(),
"change-description": change.GetProperties().GetDescription(),
}).Info("found change")

b, err := json.MarshalIndent(change.ToMap(), "", " ")
Expand All @@ -111,7 +111,7 @@ func ListChanges(ctx context.Context, ready chan bool) int {
}

if viper.GetBool("fetch-data") {
ciUuid := uuid.UUID(change.Properties.ChangingItemsBookmarkUUID)
ciUuid := uuid.UUID(change.GetProperties().GetChangingItemsBookmarkUUID())
if ciUuid != uuid.Nil {
changingItems, err := bookmarks.GetBookmark(ctx, &connect.Request[sdp.GetBookmarkRequest]{
Msg: &sdp.GetBookmarkRequest{
Expand All @@ -128,7 +128,7 @@ func ListChanges(ctx context.Context, ready chan bool) int {
return 1
}

b, err := json.MarshalIndent(changingItems.Msg.Bookmark.ToMap(), "", " ")
b, err := json.MarshalIndent(changingItems.Msg.GetBookmark().ToMap(), "", " ")
if err != nil {
log.WithContext(ctx).WithFields(log.Fields{
"change-uuid": changeUuid,
Expand All @@ -144,7 +144,7 @@ func ListChanges(ctx context.Context, ready chan bool) int {
}
}

brUuid := uuid.UUID(change.Properties.BlastRadiusSnapshotUUID)
brUuid := uuid.UUID(change.GetProperties().GetBlastRadiusSnapshotUUID())
if brUuid != uuid.Nil {
brSnap, err := snapshots.GetSnapshot(ctx, &connect.Request[sdp.GetSnapshotRequest]{
Msg: &sdp.GetSnapshotRequest{
Expand All @@ -161,7 +161,7 @@ func ListChanges(ctx context.Context, ready chan bool) int {
return 1
}

b, err := json.MarshalIndent(brSnap.Msg.Snapshot.ToMap(), "", " ")
b, err := json.MarshalIndent(brSnap.Msg.GetSnapshot().ToMap(), "", " ")
if err != nil {
log.WithContext(ctx).WithFields(log.Fields{
"change-uuid": changeUuid,
Expand All @@ -177,7 +177,7 @@ func ListChanges(ctx context.Context, ready chan bool) int {
}
}

sbsUuid := uuid.UUID(change.Properties.SystemBeforeSnapshotUUID)
sbsUuid := uuid.UUID(change.GetProperties().GetSystemBeforeSnapshotUUID())
if sbsUuid != uuid.Nil {
brSnap, err := snapshots.GetSnapshot(ctx, &connect.Request[sdp.GetSnapshotRequest]{
Msg: &sdp.GetSnapshotRequest{
Expand All @@ -194,7 +194,7 @@ func ListChanges(ctx context.Context, ready chan bool) int {
return 1
}

b, err := json.MarshalIndent(brSnap.Msg.Snapshot.ToMap(), "", " ")
b, err := json.MarshalIndent(brSnap.Msg.GetSnapshot().ToMap(), "", " ")
if err != nil {
log.WithContext(ctx).WithFields(log.Fields{
"change-uuid": changeUuid,
Expand All @@ -210,7 +210,7 @@ func ListChanges(ctx context.Context, ready chan bool) int {
}
}

sasUuid := uuid.UUID(change.Properties.SystemAfterSnapshotUUID)
sasUuid := uuid.UUID(change.GetProperties().GetSystemAfterSnapshotUUID())
if sasUuid != uuid.Nil {
brSnap, err := snapshots.GetSnapshot(ctx, &connect.Request[sdp.GetSnapshotRequest]{
Msg: &sdp.GetSnapshotRequest{
Expand All @@ -227,7 +227,7 @@ func ListChanges(ctx context.Context, ready chan bool) int {
return 1
}

b, err := json.MarshalIndent(brSnap.Msg.Snapshot.ToMap(), "", " ")
b, err := json.MarshalIndent(brSnap.Msg.GetSnapshot().ToMap(), "", " ")
if err != nil {
log.WithContext(ctx).WithFields(log.Fields{
"change-uuid": changeUuid,
Expand Down
6 changes: 3 additions & 3 deletions cmd/manualchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func ManualChange(ctx context.Context, ready chan bool) int {
return 1
}

maybeChangeUuid := createResponse.Msg.Change.Metadata.GetUUIDParsed()
maybeChangeUuid := createResponse.Msg.GetChange().GetMetadata().GetUUIDParsed()
if maybeChangeUuid == nil {
log.WithContext(ctx).WithError(err).WithFields(lf).Error("failed to read change id")
return 1
Expand Down Expand Up @@ -182,7 +182,7 @@ func ManualChange(ctx context.Context, ready chan bool) int {
// log the first message and at most every 250ms during discovery
// to avoid spanning the cli output
time_since_last_log := time.Since(last_log)
if first_log || msg.State != sdp.CalculateBlastRadiusResponse_STATE_DISCOVERING || time_since_last_log > 250*time.Millisecond {
if first_log || msg.GetState() != sdp.CalculateBlastRadiusResponse_STATE_DISCOVERING || time_since_last_log > 250*time.Millisecond {
log.WithContext(ctx).WithFields(lf).WithField("msg", msg).Info("status update")
last_log = time.Now()
first_log = false
Expand All @@ -208,7 +208,7 @@ func ManualChange(ctx context.Context, ready chan bool) int {
return 1
}

for _, a := range fetchResponse.Msg.Change.Properties.AffectedAppsUUID {
for _, a := range fetchResponse.Msg.GetChange().GetProperties().GetAffectedAppsUUID() {
appUuid, err := uuid.FromBytes(a)
if err != nil {
log.WithContext(ctx).WithFields(lf).WithError(err).WithField("app", a).Error("received invalid app uuid")
Expand Down
Loading

0 comments on commit 5a7246b

Please sign in to comment.