Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export function template #11923

Merged
merged 13 commits into from
May 30, 2019
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
*Functionbeat*

- New options to configure roles and VPC. {pull}11779[11779]
- Export automation templates used to create functions. {pull}11923[11923]

*Winlogbeat*

Expand Down
12 changes: 12 additions & 0 deletions libbeat/tests/system/beat/beat.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,18 @@ def get_log(self, logfile=None):

return data

def get_log_lines(self, logfile=None):
"""
Returns the log lines as a list of strings
"""
if logfile is None:
logfile = self.beat_name + ".log"

with open(os.path.join(self.working_dir, logfile), 'r') as f:
data = f.readlines()

return data

def wait_log_contains(self, msg, logfile=None,
max_timeout=10, poll_interval=0.1,
name="log_contains",
Expand Down
36 changes: 33 additions & 3 deletions x-pack/functionbeat/cmd/provider_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package cmd

import (
"fmt"
"os"
"path/filepath"

Expand All @@ -18,8 +19,7 @@ import (

var output string

// TODO: Add List() subcommand.
func handler() (*cliHandler, error) {
func initProvider() (provider.Provider, error) {
b, err := instance.NewInitializedBeat(instance.Settings{Name: Name})
if err != nil {
return nil, err
Expand All @@ -35,7 +35,12 @@ func handler() (*cliHandler, error) {
return nil, err
}

provider, err := provider.NewProvider(cfg)
return provider.NewProvider(cfg)
}

// TODO: Add List() subcommand.
func handler() (*cliHandler, error) {
provider, err := initProvider()
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -99,3 +104,28 @@ func genPackageCmd() *cobra.Command {
cmd.Flags().StringVarP(&output, "output", "o", "", "full path to the package")
return cmd
}

func genExportFunctionCmd() *cobra.Command {
return &cobra.Command{
Use: "function",
Short: "Export function template",
Run: cli.RunWith(func(_ *cobra.Command, args []string) error {
p, err := initProvider()
if err != nil {
return err
}
builder, err := p.TemplateBuilder()
if err != nil {
return err
}
for _, name := range args {
template, err := builder.RawTemplate(name)
if err != nil {
return fmt.Errorf("error generating raw template for %s: %+v", name, err)
}
fmt.Println(template)
}
return nil
}),
}
}
kvch marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 7 additions & 0 deletions x-pack/functionbeat/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,11 @@ func init() {
RootCmd.AddCommand(genUpdateCmd())
RootCmd.AddCommand(genRemoveCmd())
RootCmd.AddCommand(genPackageCmd())

addBeatSpecificSubcommands()
}

func addBeatSpecificSubcommands() {
RootCmd.ExportCmd.Short = "Export current config, index template or function"
RootCmd.ExportCmd.AddCommand(genExportFunctionCmd())
}
2 changes: 1 addition & 1 deletion x-pack/functionbeat/provider/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
// Bundle exposes the trigger supported by the AWS provider.
var Bundle = provider.MustCreate(
"aws",
provider.NewDefaultProvider("aws", NewCLI),
provider.NewDefaultProvider("aws", NewCLI, NewTemplateBuilder),
feature.NewDetails("AWS Lambda", "listen to events on AWS lambda", feature.Stable),
).MustAddFunction("cloudwatch_logs",
NewCloudwatchLogs,
Expand Down
Loading