diff --git a/README.md b/README.md index ed184af..7286f57 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ It allows you to view all the resources in your Scaleway account and perform bas The easiest way to run `scwtui` is to use Docker. ```bash -docker run -it --rm -v "$HOME/.config/scw:/root/.config/scw" cyclimse/scwtui:0.1 +docker run -it --rm -v "$HOME/.config/scw:/root/.config/scw" cyclimse/scwtui:0.2 ``` You can also provide your Scaleway credentials using environment variables. See the [scaleway-cli](https://github.com/scaleway/scaleway-cli/blob/master/docs/commands/config.md) documentation for more information. @@ -59,15 +59,19 @@ Quick actions are available for some resources. You can view the available actio ## Supported Resources -| Resource | List | Describe | Delete | Logs | Actions | -|----------------------|:----:|:--------:|:------:|:----:|:----------------:| -| Serverless Function | ✅ | ✅ | ✅ | ✅ | (planned) | -| Serverless Container | ✅ | ✅ | ✅ | ✅ | (planned) | -| Serverless Job | ✅ | ✅ | ✅ | ✅ | `Start`, `Stop` | -| Registry Namespace | ✅ | ✅ | ✅ | ❌ | | -| RDB Instance | ✅ | ✅ | ✅ | ✅ | | -| Kapsule Cluster | ✅ | ✅ | ✅ | ✅ | | -| Instance | ✅ | ✅ | ✅ | ❌ | (planned) | +| Resource | List | Describe | Delete | Logs | Actions | +|----------------------|:----:|:--------:|:------:|:----:|:------------------:| +| Project | ✅ | ✅ | ✅ | ❌ | `Activate Cockpit` | +| Cockpit | ✅ | ✅ | ✅ | ❌ | `Open Grafana` | +| Serverless Function | ✅ | ✅ | ✅ | ✅ | (planned) | +| Serverless Container | ✅ | ✅ | ✅ | ✅ | (planned) | +| Serverless Job | ✅ | ✅ | ✅ | ✅ | `Start`, `Stop` | +| Registry Namespace | ✅ | ✅ | ✅ | ❌ | | +| RDB Instance | ✅ | ✅ | ✅ | ✅ | | +| Kapsule Cluster | ✅ | ✅ | ✅ | ✅ | | +| Instance | ✅ | ✅ | ✅ | ❌ | (planned) | + +While it is possible to delete projects, it will require you to have deleted all the resources in the project first. In the future, this could be improved by deleting all the resources in the project first. ## Troubleshooting diff --git a/go.mod b/go.mod index 2eed654..9386d22 100644 --- a/go.mod +++ b/go.mod @@ -48,6 +48,7 @@ require ( github.com/muesli/cancelreader v0.2.2 // indirect github.com/muesli/reflow v0.3.0 // indirect github.com/muesli/termenv v0.15.2 // indirect + github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/rivo/uniseg v0.4.4 // indirect github.com/rogpeppe/go-internal v1.10.0 // indirect diff --git a/go.sum b/go.sum index f7e0376..0711e48 100644 --- a/go.sum +++ b/go.sum @@ -115,6 +115,8 @@ github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s= github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8= github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo= github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8= +github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU= +github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= @@ -141,6 +143,7 @@ go.etcd.io/bbolt v1.3.8 h1:xs88BrvEv273UsB79e0hcVrlUWmS0a8upikMFhSyAtA= go.etcd.io/bbolt v1.3.8/go.mod h1:N9Mkw9X8x5fupy0IKsmuqVtoGDyxsaDlbk4Rd05IAQw= golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE= golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/internal/resource/scaleway/cockpit.go b/internal/resource/scaleway/cockpit.go index 8de7ce5..8815669 100644 --- a/internal/resource/scaleway/cockpit.go +++ b/internal/resource/scaleway/cockpit.go @@ -4,6 +4,7 @@ import ( "context" "github.com/cyclimse/scwtui/internal/resource" + "github.com/pkg/browser" sdk "github.com/scaleway/scaleway-sdk-go/api/cockpit/v1beta1" "github.com/scaleway/scaleway-sdk-go/scw" ) @@ -47,3 +48,14 @@ func (c Cockpit) Delete(ctx context.Context, s resource.Storer, client *scw.Clie return s.DeleteResource(ctx, c) } + +func (c Cockpit) Actions() []resource.Action { + return []resource.Action{ + { + Name: "Open Grafana", + Do: func(ctx context.Context, s resource.Storer, client *scw.Client) error { + return browser.OpenURL(c.Endpoints.GrafanaURL) + }, + }, + } +} diff --git a/internal/resource/scaleway/job_run.go b/internal/resource/scaleway/job_run.go index f91fac0..a31ce14 100644 --- a/internal/resource/scaleway/job_run.go +++ b/internal/resource/scaleway/job_run.go @@ -17,7 +17,7 @@ type JobRun struct { func (run JobRun) Metadata() resource.Metadata { return resource.Metadata{ ID: run.ID, - Name: run.ID, + Name: run.JobDefinition.Name, ProjectID: run.JobDefinition.ProjectID, Status: statusPtr(run.State), Type: resource.TypeJobRun, diff --git a/internal/resource/scaleway/project.go b/internal/resource/scaleway/project.go index 89f04f7..145ffab 100644 --- a/internal/resource/scaleway/project.go +++ b/internal/resource/scaleway/project.go @@ -5,6 +5,7 @@ import ( "github.com/cyclimse/scwtui/internal/resource" sdk "github.com/scaleway/scaleway-sdk-go/api/account/v3" + cockpit_sdk "github.com/scaleway/scaleway-sdk-go/api/cockpit/v1beta1" "github.com/scaleway/scaleway-sdk-go/scw" ) @@ -40,3 +41,29 @@ func (p Project) Delete(ctx context.Context, s resource.Storer, client *scw.Clie return s.DeleteResource(ctx, p) } + +func (p Project) Actions() []resource.Action { + return []resource.Action{ + { + Name: "Activate Cockpit", + Do: func(ctx context.Context, s resource.Storer, client *scw.Client) error { + api := cockpit_sdk.NewAPI(client) + _, err := api.ActivateCockpit(&cockpit_sdk.ActivateCockpitRequest{ + ProjectID: p.ID, + }) + if err != nil { + return err + } + + cockpit, err := api.WaitForCockpit(&cockpit_sdk.WaitForCockpitRequest{ + ProjectID: p.ID, + }) + if err != nil { + return err + } + + return s.Store(ctx, Cockpit(*cockpit)) + }, + }, + } +} diff --git a/internal/store/sqlite/queries_test.go b/internal/store/sqlite/queries_test.go index e652224..b129ed1 100644 --- a/internal/store/sqlite/queries_test.go +++ b/internal/store/sqlite/queries_test.go @@ -67,6 +67,13 @@ func TestStore(t *testing.T) { Status: cockpit_sdk.CockpitStatusCreating, }, }, + { + name: "scaleway project", + resource: scaleway.Project{ + ID: "project-id", + Name: "project-name", + }, + }, } for _, tc := range testCases {