Skip to content

Commit

Permalink
Merge branch 'feat/collection_discovery'
Browse files Browse the repository at this point in the history
* feat/collection_discovery:
  feat: change discovery intervall
  • Loading branch information
ansgarschulte committed Jan 18, 2024
2 parents 657a190 + d8365b4 commit 54e7898
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion config/specification.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ package config

type Specification struct {
PostmanBaseUrl string `json:"postmanBaseUrl" split_words:"true" required:"false" default:"https://api.getpostman.com"`
PostmanApiKey string `json:"postmanApiKey" split_words:"true" required:"true"`
PostmanApiKey string `json:"postmanApiKey" split_words:"true" required:"true"`
PostmanCollectionDiscoveryInterval string `json:"postmanCollectionDiscoveryInterval" split_words:"true" required:"false" default:"3h"`
}
4 changes: 4 additions & 0 deletions extpostman/collection_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ func GetPostmanCollections() []PostmanCollection {
log.Error().Msgf("Failed to get collections from postman api. Got error: %s", err)
return nil
}
if response.StatusCode != 200 {
log.Error().Msgf("Failed to get collections from postman api. Got status code: %s", response.Status)
return nil
}

defer func(Body io.ReadCloser) {
err := Body.Close()
Expand Down
9 changes: 8 additions & 1 deletion extpostman/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ package extpostman

import (
"context"
"github.com/rs/zerolog/log"
"github.com/steadybit/discovery-kit/go/discovery_kit_api"
"github.com/steadybit/discovery-kit/go/discovery_kit_commons"
"github.com/steadybit/discovery-kit/go/discovery_kit_sdk"
"github.com/steadybit/extension-kit/extbuild"
"github.com/steadybit/extension-kit/extutil"
"github.com/steadybit/extension-postman/config"
"time"
)

Expand All @@ -24,9 +26,14 @@ var (

func NewPostmanCollectionDiscovery() discovery_kit_sdk.TargetDiscovery {
discovery := &collectionDiscovery{}
interval, err := time.ParseDuration(config.Config.PostmanCollectionDiscoveryInterval)
if err != nil {
log.Error().Msgf("Failed to parse Postman collection discovery interval: %s", err)
return nil
}
return discovery_kit_sdk.NewCachedTargetDiscovery(discovery,
discovery_kit_sdk.WithRefreshTargetsNow(),
discovery_kit_sdk.WithRefreshTargetsInterval(context.Background(), 1*time.Minute),
discovery_kit_sdk.WithRefreshTargetsInterval(context.Background(), interval),
)
}

Expand Down

0 comments on commit 54e7898

Please sign in to comment.