Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions cmd/auth_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,19 @@ func AuthenticatedSnapshotsClient(ctx context.Context) sdpconnect.SnapshotsServi
return sdpconnect.NewSnapshotsServiceClient(httpClient, url)
}

// AuthenticatedInviteClient Returns a Invite client that uses the auth
// embedded in the context and otel instrumentation
func AuthenticatedInviteClient(ctx context.Context) sdpconnect.InviteServiceClient {
httpClient := NewAuthenticatedClient(ctx, otelhttp.DefaultClient)
url := viper.GetString("invite-url")
if url == "" {
url = viper.GetString("url")
viper.Set("invite-url", url)
}
log.WithContext(ctx).WithField("invite-url", url).Debug("Connecting to overmind invite API")
return sdpconnect.NewInviteServiceClient(httpClient, url)
}

// AuthenticatedClient is a http.Client that will automatically add the required
// Authorization header to the request, which is taken from the context that it
// is created with. We also always set the X-overmind-interactive header to
Expand Down
19 changes: 15 additions & 4 deletions cmd/createbookmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,25 @@ var createBookmarkCmd = &cobra.Command{
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)

exitcode := CreateBookmark(sigs, nil)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

// Create a goroutine to watch for cancellation signals
go func() {
select {
case <-sigs:
cancel()
case <-ctx.Done():
}
}()

exitcode := CreateBookmark(ctx, nil)
tracing.ShutdownTracer()
os.Exit(exitcode)
},
}

func CreateBookmark(signals chan os.Signal, ready chan bool) int {
func CreateBookmark(ctx context.Context, ready chan bool) int {
timeout, err := time.ParseDuration(viper.GetString("timeout"))
if err != nil {
log.Errorf("invalid --timeout value '%v', error: %v", viper.GetString("timeout"), err)
Expand All @@ -60,13 +72,12 @@ func CreateBookmark(signals chan os.Signal, ready chan bool) int {
}
}

ctx := context.Background()
ctx, span := tracing.Tracer().Start(ctx, "CLI CreateBookmark", trace.WithAttributes(
attribute.String("om.config", fmt.Sprintf("%v", viper.AllSettings())),
))
defer span.End()

ctx, err = ensureToken(ctx, []string{"changes:write"}, signals)
ctx, err = ensureToken(ctx, []string{"changes:write"})
if err != nil {
log.WithContext(ctx).WithError(err).WithFields(log.Fields{
"url": viper.GetString("url"),
Expand Down
19 changes: 15 additions & 4 deletions cmd/endchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,37 @@ var endChangeCmd = &cobra.Command{
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)

exitcode := EndChange(sigs, nil)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

// Create a goroutine to watch for cancellation signals
go func() {
select {
case <-sigs:
cancel()
case <-ctx.Done():
}
}()

exitcode := EndChange(ctx, nil)
tracing.ShutdownTracer()
os.Exit(exitcode)
},
}

func EndChange(signals chan os.Signal, ready chan bool) int {
func EndChange(ctx context.Context, ready chan bool) int {
timeout, err := time.ParseDuration(viper.GetString("timeout"))
if err != nil {
log.Errorf("invalid --timeout value '%v', error: %v", viper.GetString("timeout"), err)
return 1
}

ctx := context.Background()
ctx, span := tracing.Tracer().Start(ctx, "CLI EndChange", trace.WithAttributes(
attribute.String("om.config", fmt.Sprintf("%v", viper.AllSettings())),
))
defer span.End()

ctx, err = ensureToken(ctx, []string{"changes:write"}, signals)
ctx, err = ensureToken(ctx, []string{"changes:write"})
if err != nil {
log.WithContext(ctx).WithFields(log.Fields{
"url": viper.GetString("url"),
Expand Down
19 changes: 15 additions & 4 deletions cmd/getaffectedbookmarks.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,25 @@ var getAffectedBookmarksCmd = &cobra.Command{
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)

exitcode := GetAffectedBookmarks(sigs, nil)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

// Create a goroutine to watch for cancellation signals
go func() {
select {
case <-sigs:
cancel()
case <-ctx.Done():
}
}()

exitcode := GetAffectedBookmarks(ctx, nil)
tracing.ShutdownTracer()
os.Exit(exitcode)
},
}

func GetAffectedBookmarks(signals chan os.Signal, ready chan bool) int {
func GetAffectedBookmarks(ctx context.Context, ready chan bool) int {
timeout, err := time.ParseDuration(viper.GetString("timeout"))
if err != nil {
log.Errorf("invalid --timeout value '%v', error: %v", viper.GetString("timeout"), err)
Expand All @@ -64,13 +76,12 @@ func GetAffectedBookmarks(signals chan os.Signal, ready chan bool) int {
bookmarkUuids = append(bookmarkUuids, bookmarkUuid[:])
}

ctx := context.Background()
ctx, span := tracing.Tracer().Start(ctx, "CLI GetAffectedBookmarks", trace.WithAttributes(
attribute.String("om.config", fmt.Sprintf("%v", viper.AllSettings())),
))
defer span.End()

ctx, err = ensureToken(ctx, []string{"changes:read"}, signals)
ctx, err = ensureToken(ctx, []string{"changes:read"})
if err != nil {
log.WithContext(ctx).WithError(err).WithFields(log.Fields{
"url": viper.GetString("url"),
Expand Down
19 changes: 15 additions & 4 deletions cmd/getbookmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,25 @@ var getBookmarkCmd = &cobra.Command{
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)

exitcode := GetBookmark(sigs, nil)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

// Create a goroutine to watch for cancellation signals
go func() {
select {
case <-sigs:
cancel()
case <-ctx.Done():
}
}()

exitcode := GetBookmark(ctx, nil)
tracing.ShutdownTracer()
os.Exit(exitcode)
},
}

func GetBookmark(signals chan os.Signal, ready chan bool) int {
func GetBookmark(ctx context.Context, ready chan bool) int {
timeout, err := time.ParseDuration(viper.GetString("timeout"))
if err != nil {
log.Errorf("invalid --timeout value '%v', error: %v", viper.GetString("timeout"), err)
Expand All @@ -54,13 +66,12 @@ func GetBookmark(signals chan os.Signal, ready chan bool) int {
return 1
}

ctx := context.Background()
ctx, span := tracing.Tracer().Start(ctx, "CLI GetBookmark", trace.WithAttributes(
attribute.String("om.config", fmt.Sprintf("%v", viper.AllSettings())),
))
defer span.End()

ctx, err = ensureToken(ctx, []string{"changes:read"}, signals)
ctx, err = ensureToken(ctx, []string{"changes:read"})
if err != nil {
log.WithContext(ctx).WithError(err).WithFields(log.Fields{
"url": viper.GetString("url"),
Expand Down
19 changes: 15 additions & 4 deletions cmd/getchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,37 @@ var getChangeCmd = &cobra.Command{
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)

exitcode := GetChange(sigs, nil)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

// Create a goroutine to watch for cancellation signals
go func() {
select {
case <-sigs:
cancel()
case <-ctx.Done():
}
}()

exitcode := GetChange(ctx, nil)
tracing.ShutdownTracer()
os.Exit(exitcode)
},
}

func GetChange(signals chan os.Signal, ready chan bool) int {
func GetChange(ctx context.Context, ready chan bool) int {
timeout, err := time.ParseDuration(viper.GetString("timeout"))
if err != nil {
log.Errorf("invalid --timeout value '%v', error: %v", viper.GetString("timeout"), err)
return 1
}

ctx := context.Background()
ctx, span := tracing.Tracer().Start(ctx, "CLI GetChange", trace.WithAttributes(
attribute.String("om.config", fmt.Sprintf("%v", viper.AllSettings())),
))
defer span.End()

ctx, err = ensureToken(ctx, []string{"changes:read"}, signals)
ctx, err = ensureToken(ctx, []string{"changes:read"})
if err != nil {
log.WithContext(ctx).WithFields(log.Fields{
"url": viper.GetString("url"),
Expand Down
19 changes: 15 additions & 4 deletions cmd/getsnapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,25 @@ var getSnapshotCmd = &cobra.Command{
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)

exitcode := GetSnapshot(sigs, nil)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

// Create a goroutine to watch for cancellation signals
go func() {
select {
case <-sigs:
cancel()
case <-ctx.Done():
}
}()

exitcode := GetSnapshot(ctx, nil)
tracing.ShutdownTracer()
os.Exit(exitcode)
},
}

func GetSnapshot(signals chan os.Signal, ready chan bool) int {
func GetSnapshot(ctx context.Context, ready chan bool) int {
timeout, err := time.ParseDuration(viper.GetString("timeout"))
if err != nil {
log.Errorf("invalid --timeout value '%v', error: %v", viper.GetString("timeout"), err)
Expand All @@ -54,13 +66,12 @@ func GetSnapshot(signals chan os.Signal, ready chan bool) int {
return 1
}

ctx := context.Background()
ctx, span := tracing.Tracer().Start(ctx, "CLI GetSnapshot", trace.WithAttributes(
attribute.String("om.config", fmt.Sprintf("%v", viper.AllSettings())),
))
defer span.End()

ctx, err = ensureToken(ctx, []string{"changes:read"}, signals)
ctx, err = ensureToken(ctx, []string{"changes:read"})
if err != nil {
log.WithContext(ctx).WithError(err).WithFields(log.Fields{
"url": viper.GetString("url"),
Expand Down
Loading