Skip to content
This repository has been archived by the owner on Dec 3, 2024. It is now read-only.

Commit

Permalink
feat: add basic actions for cockpit (#25)
Browse files Browse the repository at this point in the history
* feat: add basic actions for cockpit

* chore: bump version in readme
  • Loading branch information
cyclimse authored Nov 19, 2023
1 parent 6c3e4f3 commit 2e9155c
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 11 deletions.
24 changes: 14 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand All @@ -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=
Expand Down
12 changes: 12 additions & 0 deletions internal/resource/scaleway/cockpit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
},
},
}
}
2 changes: 1 addition & 1 deletion internal/resource/scaleway/job_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
27 changes: 27 additions & 0 deletions internal/resource/scaleway/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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))
},
},
}
}
7 changes: 7 additions & 0 deletions internal/store/sqlite/queries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 2e9155c

Please sign in to comment.