Skip to content

Commit

Permalink
Merge pull request #349 from fujiwara/fix/status
Browse files Browse the repository at this point in the history
Fix/status
  • Loading branch information
fujiwara authored Jan 27, 2024
2 parents f4f4c59 + 0f925be commit a5c03b3
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 10 deletions.
2 changes: 1 addition & 1 deletion deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type DeployOption struct {
DryRun bool `help:"dry run" default:"false"`
SkipArchive bool `help:"skip to create zip archive. requires Code.S3Bucket and Code.S3Key in function definition" default:"false"`
KeepVersions int `help:"Number of latest versions to keep. Older versions will be deleted. (Optional value: default 0)." default:"0"`
FunctionURL string `help:"path to function-url definiton" default:""`
FunctionURL string `help:"path to function-url definiton" default:"" env:"LAMBROLL_FUNCTION_URL"`
SkipFunction bool `help:"skip to deploy a function. deploy function-url only" default:"false"`

ExcludeFileOption
Expand Down
4 changes: 2 additions & 2 deletions diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ type DiffOption struct {
Src string `help:"function zip archive or src dir" default:"."`
CodeSha256 bool `help:"diff of code sha256" default:"false"`
Unified bool `help:"unified diff" default:"true" negatable:"" short:"u"`
Qualifier *string `help:"compare with"`
FunctionURL string `help:"path to function-url definiton" default:""`
Qualifier *string `help:"the qualifier to compare"`
FunctionURL string `help:"path to function-url definiton" default:"" env:"LAMBROLL_FUNCTION_URL"`

ExcludeFileOption
}
Expand Down
2 changes: 1 addition & 1 deletion render.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

type RenderOption struct {
Jsonnet bool `default:"false" help:"render function.json as jsonnet"`
FunctionURL string `help:"render function-url definiton file" default:""`
FunctionURL string `help:"render function-url definiton file" default:"" env:"LAMBROLL_FUNCTION_URL"`
}

// Invoke invokes function
Expand Down
69 changes: 64 additions & 5 deletions status.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,50 @@ package lambroll

import (
"context"
"errors"
"fmt"
"strings"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/lambda"
"github.com/aws/aws-sdk-go-v2/service/lambda/types"
"github.com/olekukonko/tablewriter"
)

// StatusOption represents options for Status()
type StatusOption struct {
Qualifier *string `help:"compare with"`
Output string `help:"output format" default:"table" enum:"table,json"`
}

type StatusOutput struct {
FunctionName string `json:"FunctionName"`
FunctionArn string `json:"FunctionArn"`
Version string `json:"Version"`
Runtime string `json:"Runtime,omitempty"`
PackageType string `json:"PackageType"`
State string `json:"State"`
LastUpdateState string `json:"LastUpdateState"`
FunctionURL string `json:"FunctionURL,omitempty"`
}

func (o *StatusOutput) String() string {
buf := new(strings.Builder)
w := tablewriter.NewWriter(buf)
w.Append([]string{"FunctionName", o.FunctionName})
w.Append([]string{"FunctionArn", o.FunctionArn})
w.Append([]string{"Version", o.Version})
if o.Runtime != "" {
w.Append([]string{"Runtime", o.Runtime})
}
w.Append([]string{"PackageType", o.PackageType})
w.Append([]string{"State", o.State})
w.Append([]string{"LastUpdateState", o.LastUpdateState})
if o.FunctionURL != "" {
w.Append([]string{"FunctionURL", o.FunctionURL})
}
w.Render()
return buf.String()
}

// Status prints status of function
Expand All @@ -28,10 +63,34 @@ func (app *App) Status(ctx context.Context, opt *StatusOption) error {
if err != nil {
return fmt.Errorf("failed to GetFunction %s: %w", name, err)
}
fmt.Printf("FunctionName: %s\n", aws.ToString(res.Configuration.FunctionName))
fmt.Printf("Version: %s\n", aws.ToString(res.Configuration.Version))
fmt.Printf("FunctionArn: %s\n", aws.ToString(res.Configuration.FunctionArn))
fmt.Printf("State: %s\n", string(res.Configuration.State))
fmt.Printf("LastUpdateStatus: %s\n", string(res.Configuration.LastUpdateStatus))
out := &StatusOutput{
FunctionName: aws.ToString(res.Configuration.FunctionName),
FunctionArn: aws.ToString(res.Configuration.FunctionArn),
Version: aws.ToString(res.Configuration.Version),
Runtime: string(res.Configuration.Runtime),
PackageType: string(res.Configuration.PackageType),
State: string(res.Configuration.State),
LastUpdateState: string(res.Configuration.LastUpdateStatus),
}
if res, err := app.lambda.GetFunctionUrlConfig(ctx, &lambda.GetFunctionUrlConfigInput{
FunctionName: &name,
Qualifier: opt.Qualifier,
}); err != nil {
var nfe *types.ResourceNotFoundException
if errors.As(err, &nfe) {
// do nothing
} else {
return fmt.Errorf("failed to GetFunctionUrlConfig %s: %w", name, err)
}
} else {
out.FunctionURL = aws.ToString(res.FunctionUrl)
}
switch opt.Output {
case "table":
fmt.Print(out.String())
case "json":
b, _ := marshalJSON(out)
fmt.Print(string(b))
}
return nil
}
2 changes: 1 addition & 1 deletion versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

// VersionsOption represents options for Versions()
type VersionsOption struct {
Output string `default:"table" enum:"table,json,tsv" help:"output format"`
Output string `default:"table" enum:"table,json,tsv" help:"output format (table,json,tsv)"`
Delete bool `default:"false" help:"delete older versions"`
KeepVersions int `default:"0" help:"Number of latest versions to keep. Older versions will be deleted with --delete."`
}
Expand Down

0 comments on commit a5c03b3

Please sign in to comment.