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

implement get tenant history command #215

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
34 changes: 33 additions & 1 deletion cmd/tenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ package cmd
import (
"errors"
"fmt"
"strconv"
"time"

"github.com/go-openapi/strfmt"
tenantmodel "github.com/metal-stack/metal-go/api/client/tenant"
"github.com/metal-stack/metal-go/api/models"
"github.com/metal-stack/metal-lib/pkg/genericcli"
Expand Down Expand Up @@ -54,7 +57,18 @@ func newTenantCmd(c *config) *cobra.Command {
},
}

return genericcli.NewCmds(cmdsConfig)
tenantHistoryCmd := &cobra.Command{
Use: "history",
Short: "get tenant at given timestamp",
RunE: func(cmd *cobra.Command, args []string) error {
return w.GetTenantHistory()
},
}

tenantHistoryCmd.Flags().StringP("id", "", "", "ID of tenant")
tenantHistoryCmd.Flags().StringP("at", "", "", "tenant will be returned at it was at this timestamp")

return genericcli.NewCmds(cmdsConfig, tenantHistoryCmd)
}

func (c tenantCmd) Get(id string) (*models.V1TenantResponse, error) {
Expand Down Expand Up @@ -208,3 +222,21 @@ func (w *tenantCmd) createFromCLI() (*models.V1TenantCreateRequest, error) {
},
nil
}

func (c tenantCmd) GetTenantHistory() error {
id, err := strconv.ParseInt(viper.GetString("at"), 10, 64)
if err != nil {
return err
}

params := tenantmodel.NewGetTenantHistoryParams().WithID(viper.GetString("id")).WithBody(&models.V1TenantGetHistoryRequest{
At: strfmt.DateTime(time.Unix(id, 0)),
})

resp, err := c.client.Tenant().GetTenantHistory(params, nil)
if err != nil {
return err
}

return c.listPrinter.Print(resp.Payload)
}
1 change: 1 addition & 0 deletions docs/metalctl_tenant.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ a tenant belongs to a tenant and groups together entities in metal-stack.
* [metalctl tenant delete](metalctl_tenant_delete.md) - deletes the tenant
* [metalctl tenant describe](metalctl_tenant_describe.md) - describes the tenant
* [metalctl tenant edit](metalctl_tenant_edit.md) - edit the tenant through an editor and update
* [metalctl tenant history](metalctl_tenant_history.md) - get tenant at given timestamp
* [metalctl tenant list](metalctl_tenant_list.md) - list all tenants
* [metalctl tenant update](metalctl_tenant_update.md) - updates the tenant

48 changes: 48 additions & 0 deletions docs/metalctl_tenant_history.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
## metalctl tenant history

get tenant at given timestamp

```
metalctl tenant history [flags]
```

### Options

```
--at string tenant will be returned at it was at this timestamp
-h, --help help for history
--id string ID of tenant
```

### Options inherited from parent commands

```
--api-token string api token to authenticate. Can be specified with METALCTL_API_TOKEN environment variable.
--api-url string api server address. Can be specified with METALCTL_API_URL environment variable.
-c, --config string alternative config file path, (default is ~/.metalctl/config.yaml).
Example config.yaml:

---
apitoken: "alongtoken"
...


--debug debug output
--force-color force colored output even without tty
--kubeconfig string Path to the kube-config to use for authentication and authorization. Is updated by login. Uses default path if not specified.
--no-headers do not print headers of table output format (default print headers)
-o, --output-format string output format (table|wide|markdown|json|yaml|template), wide is a table with more columns. (default "table")
--template string output template for template output-format, go template format.
For property names inspect the output of -o json or -o yaml for reference.
Example for machines:

metalctl machine list -o template --template "{{ .id }}:{{ .size.id }}"


--yes-i-really-mean-it skips security prompts (which can be dangerous to set blindly because actions can lead to data loss or additional costs)
```

### SEE ALSO

* [metalctl tenant](metalctl_tenant.md) - manage tenant entities

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/go-openapi/runtime v0.26.0
github.com/go-openapi/strfmt v0.21.7
github.com/google/go-cmp v0.5.9
github.com/metal-stack/metal-go v0.24.1
github.com/metal-stack/metal-go v0.24.2-0.20231006065021-96e01902da6a
github.com/metal-stack/metal-lib v0.13.3
github.com/metal-stack/updater v1.1.5
github.com/metal-stack/v v1.0.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,8 @@ github.com/mdlayher/sdnotify v1.0.0 h1:Ma9XeLVN/l0qpyx1tNeMSeTjCPH6NtuD6/N9XdTlQ
github.com/mdlayher/sdnotify v1.0.0/go.mod h1:HQUmpM4XgYkhDLtd+Uad8ZFK1T9D5+pNxnXQjCeJlGE=
github.com/mdlayher/socket v0.4.1 h1:eM9y2/jlbs1M615oshPQOHZzj6R6wMT7bX5NPiQvn2U=
github.com/mdlayher/socket v0.4.1/go.mod h1:cAqeGjoufqdxWkD7DkpyS+wcefOtmu5OQ8KuoJGIReA=
github.com/metal-stack/metal-go v0.24.1 h1:S4g3LXeWBELCKIyyCsRMa9B1pC5EClqcX35oV/8xv2U=
github.com/metal-stack/metal-go v0.24.1/go.mod h1:jNJ0dWIBRwKeJoP+RGqTyE5qLsdZFISFrNHU5m3IDwA=
github.com/metal-stack/metal-go v0.24.2-0.20231006065021-96e01902da6a h1:QNNX5jguRm07QKSJ2CX7C7/82qgTFhMYwsgwUDhbUtc=
github.com/metal-stack/metal-go v0.24.2-0.20231006065021-96e01902da6a/go.mod h1:jNJ0dWIBRwKeJoP+RGqTyE5qLsdZFISFrNHU5m3IDwA=
github.com/metal-stack/metal-lib v0.13.3 h1:BOhwcKHILmBZd2pz2YMOhj8QxzDaz3G0F/CGuYhnu8o=
github.com/metal-stack/metal-lib v0.13.3/go.mod h1:BAR7fjdoV7DDg8i9GpJQBDaNSFirOcBs0vLYTBnhHQU=
github.com/metal-stack/security v0.6.7 h1:8wstGy0pdUmphVclAlT+9RKQmx9lF+cIGklJZAB5cIc=
Expand Down