Skip to content

Commit

Permalink
Listing records: allow filters to apply on fetch #144
Browse files Browse the repository at this point in the history
Fixing wording test
  • Loading branch information
simcap committed Jan 30, 2018
1 parent 5ea2cd0 commit a1ffd80
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Fixes

- [#182](https://github.com/wallix/awless/issues/182): Region embedded in profile should be taken into account with the correct precedence
- [#144](https://github.com/wallix/awless/issues/144): Allow to filter on fetch records given a zone name

## v0.1.9 [2018-01-16]

Expand Down
13 changes: 13 additions & 0 deletions aws/fetch/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ func getBoolFromContext(ctx context.Context, key string) bool {
return v && ok
}

func getFiltersFromContext(ctx context.Context) map[string]string {
out := make(map[string]string)
arr, ok := ctx.Value("filters").([]string)
if ok {
for _, keyval := range arr {
if splits := strings.SplitN(keyval, "=", 2); len(splits) == 2 {
out[strings.ToLower(splits[0])] = splits[1]
}
}
}
return out
}

func sliceOfSlice(in []*string, maxLength int) (res [][]*string) {
if maxLength <= 0 {
return
Expand Down
11 changes: 10 additions & 1 deletion aws/fetch/manual_fetchers.go
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,9 @@ func addManualDnsFetchFuncs(conf *Config, funcs map[string]fetch.Func) {
return resources, objects, nil
}

filters := getFiltersFromContext(ctx)
filterOnZoneName, hasNameFilter := filters["name"]

errC := make(chan error)
zoneC := make(chan *route53.HostedZone)
objectsC := make(chan *route53.ResourceRecordSet)
Expand All @@ -796,7 +799,13 @@ func addManualDnsFetchFuncs(conf *Config, funcs map[string]fetch.Func) {
err := conf.APIs.Route53.ListHostedZonesPages(&route53.ListHostedZonesInput{},
func(out *route53.ListHostedZonesOutput, lastPage bool) (shouldContinue bool) {
for _, output := range out.HostedZones {
zoneC <- output
if hasNameFilter {
if strings.Contains(strings.ToLower(*output.Name), strings.ToLower(filterOnZoneName)) {
zoneC <- output
}
} else {
zoneC <- output
}
}
return out.NextMarker != nil
})
Expand Down
3 changes: 2 additions & 1 deletion commands/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ var listSpecificResourceCmd = func(resType string) *cobra.Command {
} else {
srv, err := cloud.GetServiceForType(resType)
exitOn(err)
g, err = srv.FetchByType(context.WithValue(context.Background(), "force", true), resType)
fetchContext := context.WithValue(context.Background(), "force", true)
g, err = srv.FetchByType(context.WithValue(fetchContext, "filters", listingFiltersFlag), resType)
exitOn(err)
}

Expand Down
2 changes: 1 addition & 1 deletion config/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestUpgradeMessaging(t *testing.T) {
t.Fatal(err)
}

exp := fmt.Sprintf("New version 1000.0.0 available. Changelog at https://github.com/wallix/awless/blob/master/CHANGELOG.md\nRun `wget -O awless-1000.0.0.tar.gz https://github.com/wallix/awless/releases/download/1000.0.0/awless-%s-%s.tar.gz`\n", runtime.GOOS, runtime.GOARCH)
exp := fmt.Sprintf("New version 1000.0.0 available. Checkout the latest features at https://github.com/wallix/awless/blob/master/CHANGELOG.md\nRun `wget -O awless-1000.0.0.tar.gz https://github.com/wallix/awless/releases/download/1000.0.0/awless-%s-%s.tar.gz`\n", runtime.GOOS, runtime.GOARCH)
if got, want := buff.String(), exp; got != want {
t.Fatalf("got %s, want %s", got, want)
}
Expand Down

0 comments on commit a1ffd80

Please sign in to comment.