Skip to content

Commit

Permalink
feat: log confirm topic messages
Browse files Browse the repository at this point in the history
Heavily inspired by the verify reject command
this command now prints the messages from
confirm-topic.
  • Loading branch information
andrbo committed Apr 18, 2024
1 parent c01f681 commit 2b169c4
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 19 deletions.
15 changes: 14 additions & 1 deletion cmd/verify/confirm/confirm.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package confirm

import (
"context"
"fmt"
"github.com/segmentio/kafka-go"
"github.com/spf13/cobra"
"hermetic/internal/common_flags"
"hermetic/internal/teams"
confirmImplementation "hermetic/internal/verify/confirm"
"os"
"os/signal"
)

func NewCommand() *cobra.Command {
Expand All @@ -29,7 +33,16 @@ func parseArgumentsAndCallVerify(cmd *cobra.Command, args []string) error {
return fmt.Errorf("failed to get confirm-topic flag, cause: `%w`", err)
}

err = confirmImplementation.Verify(confirmTopicName)
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
defer cancel()

reader := kafka.NewReader(kafka.ReaderConfig{
Brokers: common_flags.KafkaEndpoints,
Topic: confirmTopicName,
GroupID: "nettarkivet-hermetic-verify",
})

err = confirmImplementation.ReadConfirmTopic(ctx, reader)
if err != nil {
err = fmt.Errorf("verification error, cause: `%w`", err)
fmt.Printf("Sending error message to Teams\n")
Expand Down
24 changes: 20 additions & 4 deletions internal/verify/confirm/confirm.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
package confirmImplmentation

import (
"context"
"fmt"
"github.com/segmentio/kafka-go"
"hermetic/internal/dps"
)

func Verify(confirmTopicName string) error {
fmt.Printf("Reading messages from topic '%s'\n", confirmTopicName)
fmt.Printf("This command is not implemented yet\n" +
"Aims to solve issue https://github.com/nlnwa/hermetic/issues/3 ")
func ReadConfirmTopic(ctx context.Context, reader *kafka.Reader) error {
err := dps.ReadMessages(ctx, reader, ProcessMessagesFromConfirmTopic)
if err != nil {
return fmt.Errorf("failed to read confirm-topic: `%w`", err)
}

return nil
}

func ProcessMessagesFromConfirmTopic(response *dps.KafkaResponse, err error) {
if err != nil {
fmt.Errorf("failed to read message, cause: `%w`", err)

Check failure on line 21 in internal/verify/confirm/confirm.go

View workflow job for this annotation

GitHub Actions / Lint

unusedresult: result of fmt.Errorf call not used (govet)
}
if response == nil {
fmt.Println("No response found")
} else {
fmt.Printf("SIP successfully perserved: %+v\n", response)
}
}
14 changes: 0 additions & 14 deletions internal/verify/confirm/confirm_test.go

This file was deleted.

0 comments on commit 2b169c4

Please sign in to comment.