Skip to content
Draft
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
22 changes: 14 additions & 8 deletions cmd/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ func NewCmdPkg() *cobra.Command {
Args: cobra.ExactArgs(1),
RunE: runPkgConfigure,
}
pkgConfigureCmd.Flags().StringVarP(&pkgParamsPath, "params", "p", pkgParamsPath, "Path to params json, tfvars or yaml file. This file supports bash interpolation.")

pkgDeployCmd := &cobra.Command{
Use: `deploy <project>-<env>-<manifest>`,
Expand Down Expand Up @@ -78,7 +77,7 @@ func NewCmdPkg() *cobra.Command {
Args: cobra.ExactArgs(1),
RunE: runPkgGet,
}
pkgGetCmd.Flags().StringP("output", "o", "text", "Output format (text or json)")
pkgGetCmd.Flags().StringP("output", "o", "text", "Output format (text or json). Defaults to text (markdown).")

pkgPatchCmd := &cobra.Command{
Use: `patch <project>-<env>-<manifest>`,
Expand Down Expand Up @@ -149,7 +148,7 @@ func runPkgGet(cmd *cobra.Command, args []string) error {
return fmt.Errorf("error initializing massdriver client: %w", mdClientErr)
}

pkg, err := api.GetPackageByName(ctx, mdClient, pkgID)
pkg, err := api.GetPackage(ctx, mdClient, pkgID)
if err != nil {
return err
}
Expand Down Expand Up @@ -229,8 +228,15 @@ func runPkgConfigure(cmd *cobra.Command, args []string) error {
packageSlugOrID := args[0]

params := map[string]any{}
if err := files.Read(pkgParamsPath, &params); err != nil {
return err
if pkgParamsPath == "-" {
// Read from stdin
if err := json.NewDecoder(os.Stdin).Decode(&params); err != nil {
return fmt.Errorf("failed to decode JSON from stdin: %w", err)
}
} else {
if err := files.Read(pkgParamsPath, &params); err != nil {
return err
}
Comment on lines +231 to +239
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved to new pr

Suggested change
if pkgParamsPath == "-" {
// Read from stdin
if err := json.NewDecoder(os.Stdin).Decode(&params); err != nil {
return fmt.Errorf("failed to decode JSON from stdin: %w", err)
}
} else {
if err := files.Read(pkgParamsPath, &params); err != nil {
return err
}

}

mdClient, mdClientErr := client.New()
Expand All @@ -246,7 +252,7 @@ func runPkgConfigure(cmd *cobra.Command, args []string) error {
fmt.Printf("✅ Package `%s` configured successfully\n", configuredPkg.Slug)

// Get package details to build URL
pkgDetails, err := api.GetPackageByName(ctx, mdClient, configuredPkg.Slug)
pkgDetails, err := api.GetPackage(ctx, mdClient, configuredPkg.Slug)
if err == nil && pkgDetails.Environment != nil && pkgDetails.Environment.Project != nil && pkgDetails.Manifest != nil {
urlHelper, urlErr := api.NewURLHelper(ctx, mdClient)
if urlErr == nil {
Expand Down Expand Up @@ -385,7 +391,7 @@ func runPkgVersion(cmd *cobra.Command, args []string) error {
fmt.Printf("✅ Package `%s` version set successfully\n", updatedPkg.Slug)

// Get package details to build URL
pkgDetails, err := api.GetPackageByName(ctx, mdClient, updatedPkg.Slug)
pkgDetails, err := api.GetPackage(ctx, mdClient, updatedPkg.Slug)
if err == nil && pkgDetails.Environment != nil && pkgDetails.Environment.Project != nil && pkgDetails.Manifest != nil {
urlHelper, urlErr := api.NewURLHelper(ctx, mdClient)
if urlErr == nil {
Expand Down Expand Up @@ -413,7 +419,7 @@ func runPkgDestroy(cmd *cobra.Command, args []string) error {
}

// Get package details for confirmation and URL
pkg, err := api.GetPackageByName(ctx, mdClient, packageSlugOrID)
pkg, err := api.GetPackage(ctx, mdClient, packageSlugOrID)
if err != nil {
return err
}
Expand Down
212 changes: 210 additions & 2 deletions cmd/templates/package.get.md.tmpl
Original file line number Diff line number Diff line change
@@ -1,10 +1,218 @@
# Package: {{.Slug}}

**Bundle:** {{.Bundle.Name}}
**Status:** {{.Status}}

**Environment:** {{.Environment.Slug}}
{{if .Bundle}}
**Bundle:** {{.Bundle.Name}}{{if .Bundle.Version}} ({{.Bundle.Version}}){{end}}
{{end}}

{{if .Manifest}}
**Manifest:** {{.Manifest.Name}} ({{.Manifest.Slug}})
{{if .Manifest.Description}}
{{.Manifest.Description}}
{{end}}
{{end}}

{{if .Environment}}
**Environment:** {{.Environment.Slug}}{{if .Environment.Name}} ({{.Environment.Name}}){{end}}
{{if .Environment.Project}}
**Project:** {{.Environment.Project.Slug}}{{if .Environment.Project.Name}} ({{.Environment.Project.Name}}){{end}}
{{end}}
{{end}}

## Version Information

{{if .Version}}
**Version Constraint:** {{.Version}}
{{end}}
{{if .ResolvedVersion}}
**Resolved Version:** {{.ResolvedVersion}}
{{end}}
{{if .DeployedVersion}}
**Deployed Version:** {{.DeployedVersion}}
{{end}}
{{if .ReleaseStrategy}}
**Release Strategy:** {{.ReleaseStrategy}}
{{end}}
{{if .AvailableUpgrade}}
**Available Upgrade:** {{.AvailableUpgrade}}
{{end}}

## Timestamps

{{if .CreatedAt}}
**Created:** {{.CreatedAt.Format "2006-01-02 15:04:05 MST"}}
{{end}}
{{if .UpdatedAt}}
**Last Updated:** {{.UpdatedAt.Format "2006-01-02 15:04:05 MST"}}
{{end}}

## Deployments

{{if .ActiveDeployment}}
### Active Deployment

- **ID:** {{.ActiveDeployment.ID}}
- **Status:** {{.ActiveDeployment.Status}}
- **Action:** {{.ActiveDeployment.Action}}
- **Version:** {{.ActiveDeployment.Version}}
{{if .ActiveDeployment.Message}}
- **Message:** {{.ActiveDeployment.Message}}
{{end}}
{{if .ActiveDeployment.DeployedBy}}
- **Deployed By:** {{.ActiveDeployment.DeployedBy}}
{{end}}
- **Created:** {{.ActiveDeployment.CreatedAt.Format "2006-01-02 15:04:05 MST"}}
{{if .ActiveDeployment.ElapsedTime}}
- **Elapsed Time:** {{.ActiveDeployment.ElapsedTime}}s
{{end}}
{{end}}

{{if .LatestDeployment}}
### Latest Deployment

- **ID:** {{.LatestDeployment.ID}}
- **Status:** {{.LatestDeployment.Status}}
- **Action:** {{.LatestDeployment.Action}}
- **Version:** {{.LatestDeployment.Version}}
{{if .LatestDeployment.Message}}
- **Message:** {{.LatestDeployment.Message}}
{{end}}
{{if .LatestDeployment.DeployedBy}}
- **Deployed By:** {{.LatestDeployment.DeployedBy}}
{{end}}
- **Created:** {{.LatestDeployment.CreatedAt.Format "2006-01-02 15:04:05 MST"}}
{{if .LatestDeployment.ElapsedTime}}
- **Elapsed Time:** {{.LatestDeployment.ElapsedTime}}s
{{end}}
{{end}}

{{if .Deployments}}
### Recent Deployments

{{range .Deployments}}
- **{{.Status}}** - {{.Action}} ({{.Version}}) - {{.CreatedAt.Format "2006-01-02 15:04:05 MST"}}
{{end}}
{{end}}

## Artifacts

{{if .Artifacts}}
{{range .Artifacts}}
- **{{.Name}}** ({{.Type}}){{if .Field}} - Field: {{.Field}}{{end}}
{{end}}
{{else}}
No artifacts
{{end}}

## Connections

{{if .Connections}}
{{range .Connections}}
- **{{.PackageField}}**{{if .Artifact}} → {{.Artifact.Name}} ({{.Artifact.Type}}){{end}}
{{end}}
{{else}}
No connections
{{end}}

## Remote References

{{if .RemoteReferences}}
{{range .RemoteReferences}}
- **{{.Artifact.Name}}** ({{.Artifact.Type}}){{if .Artifact.Field}} - Field: {{.Artifact.Field}}{{end}}
{{end}}
{{else}}
No remote references
{{end}}

## Alarms

{{if .Alarms}}
{{range .Alarms}}
### {{.DisplayName}}

- **Status:** {{if .CurrentState}}{{.CurrentState.Status}}{{else}}Unknown{{end}}
- **Cloud Resource ID:** {{.CloudResourceID}}
{{if .Namespace}}
- **Namespace:** {{.Namespace}}
{{end}}
{{if .Name}}
- **Metric:** {{.Name}}
{{end}}
{{if .Statistic}}
- **Statistic:** {{.Statistic}}
{{end}}
{{if .Threshold}}
- **Threshold:** {{.Threshold}}
{{end}}
{{if .ComparisonOperator}}
- **Operator:** {{.ComparisonOperator}}
{{end}}
{{if .Dimensions}}
- **Dimensions:**
{{range .Dimensions}}
- {{.Name}}: {{.Value}}
{{end}}
{{end}}
{{if .CurrentState}}
- **Last State Change:** {{.CurrentState.OccurredAt.Format "2006-01-02 15:04:05 MST"}}
{{if .CurrentState.Message}}
- **Message:** {{.CurrentState.Message}}
{{end}}
{{end}}
{{end}}
{{else}}
No alarms configured
{{end}}

## Secret Fields

{{if .SecretFields}}
{{range .SecretFields}}
- **{{.Name}}**{{if .Title}} ({{.Title}}){{end}}
- Required: {{.Required}}
- JSON: {{.JSON}}
{{if .Description}}
- Description: {{.Description}}
{{end}}
{{if .ValueMetadata}}
- Set: Yes (SHA256: {{.ValueMetadata.SHA256}})
- Set At: {{.ValueMetadata.CreatedAt.Format "2006-01-02 15:04:05 MST"}}
{{else}}
- Set: No
{{end}}
{{end}}
{{else}}
No secret fields
{{end}}

## Cost

{{if .Cost}}
{{if .Cost.Monthly}}
**Monthly Average:** ${{printf "%.2f" .Cost.Monthly.Average.Amount}}
{{end}}
{{if .Cost.Daily}}
**Daily Average:** ${{printf "%.2f" .Cost.Daily.Average.Amount}}
{{end}}
{{else}}
No cost data available
{{end}}

## Decommission Status

{{if .Decommissionable}}
**Can be decommissioned:** {{.Decommissionable.Result}}
{{if .Decommissionable.Messages}}
**Messages:**
{{range .Decommissionable.Messages}}
- {{.}}
{{end}}
{{end}}
{{end}}

## Parameters

```json
{{.ParamsJSON}}
```
33 changes: 31 additions & 2 deletions docs/generated/mass_package_configure.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ Your IaC must be published as a [bundle](https://docs.massdriver.cloud/bundles)

This command will replace the full configuration of an infrastructure package in Massdriver.

## Usage

```bash
mass package configure <package-slug> [flags]
```

## Flags

- `-p, --params`: Path to params JSON, tfvars, or YAML file. Use `-` to read from stdin. Defaults to `./params.json`. This file supports bash interpolation.

## Examples

You can configure the package using the `slug` identifier.
Expand All @@ -24,8 +34,27 @@ The `slug` can be found by hovering over the bundle in the Massdriver diagram. T

_Note:_ Parameter files support bash interpolation.

```shell
```bash
# Configure package with params file
mass package configure ecomm-prod-vpc --params=params.json

# Configure package with params file using short flag
mass package configure ecomm-prod-vpc -p params.json

# Configure package by reading params from stdin
mass package configure ecomm-prod-vpc --params=-

# Configure package with tfvars file
mass package configure ecomm-prod-vpc --params=terraform.tfvars

# Configure package with YAML file
mass package configure ecomm-prod-vpc --params=params.yaml

# Pipe params from another command
echo '{"version": "1.0.0"}' | mass package configure ecomm-prod-vpc --params=-

# Clone configurations between environments
mass package get ecomm-staging-vpc -o json | jq .params | mass package cfg ecomm-dev-vpc --params -
```


Expand All @@ -43,7 +72,7 @@ mass package configure ecomm-prod-vpc --params=params.json

```
-h, --help help for configure
-p, --params string Path to params json, tfvars or yaml file. This file supports bash interpolation. (default "./params.json")
-p, --params string Path to params json, tfvars or yaml file. Use '-' to read from stdin. This file supports bash interpolation. (default "./params.json")
```

### SEE ALSO
Expand Down
20 changes: 18 additions & 2 deletions docs/generated/mass_package_get.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,30 @@ Your infrastructure must be published as a [bundle](https://docs.massdriver.clou
## Usage

```bash
mass package get <package-slug>
mass package get <package-slug> [flags]
```

## Flags

- `-o, --output`: Output format (text or json). Defaults to text (markdown).

## Examples

```bash
# Get details for a VPC package in the ecommerce production environment
mass package get ecomm-prod-vpc

# Get package as JSON and extract just the params using jq
mass package get ecomm-prod-vpc -o json | jq .params

# Get package status from JSON output
mass package get ecomm-prod-vpc -o json | jq .status

# Get package environment details
mass package get ecomm-prod-vpc -o json | jq .environment

# Save package configuration to a file
mass package get ecomm-prod-vpc -o json > package.json
```

The package slug can be found by hovering over the bundle in the Massdriver diagram. It follows the format: `<project-slug>-<env-slug>-<manifest-slug>`.
Expand All @@ -46,7 +62,7 @@ mass package get ecomm-prod-vpc

```
-h, --help help for get
-o, --output string Output format (text or json) (default "text")
-o, --output string Output format (text or json). Defaults to text (markdown). (default "text")
```

### SEE ALSO
Expand Down
Loading
Loading