-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Filebrowser #3053
Open
kasbert
wants to merge
3
commits into
derailed:master
Choose a base branch
from
kasbert:filebrowser
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Filebrowser #3053
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright Authors of K9s | ||
|
||
package dao | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/derailed/k9s/internal" | ||
"github.com/derailed/k9s/internal/client" | ||
"github.com/derailed/k9s/internal/render" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
) | ||
|
||
var _ Accessor = (*Dir)(nil) | ||
|
||
// DirLocal tracks standard and custom command aliases. | ||
type DirLocal struct { | ||
NonResource | ||
} | ||
|
||
// NewDirLocal returns a new set of aliases. | ||
func NewDirLocal(f Factory) *Dir { | ||
var a Dir | ||
a.Init(f, client.NewGVR("dirlocal")) | ||
return &a | ||
} | ||
|
||
// List returns a collection of aliases. | ||
func (a *DirLocal) List(ctx context.Context, _ string) ([]runtime.Object, error) { | ||
dir, ok := ctx.Value(internal.KeyPath).(string) | ||
if !ok { | ||
return nil, errors.New("no dir in context") | ||
} | ||
|
||
files, err := os.ReadDir(dir) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
oo := make([]runtime.Object, 0, len(files)) | ||
for _, f := range files { | ||
oo = append(oo, render.DirRes{ | ||
Path: filepath.Join(dir, f.Name()), | ||
Entry: f, | ||
}) | ||
} | ||
|
||
return oo, err | ||
} | ||
|
||
// Get fetch a resource. | ||
func (a *DirLocal) Get(_ context.Context, _ string) (runtime.Object, error) { | ||
return nil, errors.New("nyi") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright Authors of K9s | ||
|
||
package dao | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/derailed/k9s/internal" | ||
"github.com/derailed/k9s/internal/client" | ||
"github.com/derailed/k9s/internal/render" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
) | ||
|
||
var _ Accessor = (*DirRemote)(nil) | ||
|
||
// Dir tracks standard and custom command aliases. | ||
type DirRemote struct { | ||
NonResource | ||
} | ||
|
||
// NewDirRemote returns a new set of aliases. | ||
func NewDirRemote(f Factory) *DirRemote { | ||
var a DirRemote | ||
a.Init(f, client.NewGVR("dirremote")) | ||
return &a | ||
} | ||
|
||
// List returns a collection of aliases. | ||
func (a *DirRemote) List(ctx context.Context, _ string) ([]runtime.Object, error) { | ||
dir, ok := ctx.Value(internal.KeyPath).(string) | ||
if !ok { | ||
return nil, errors.New("no dir in context") | ||
} | ||
|
||
// It would be better to list files here ? | ||
// No access to view/exec.go, though | ||
txt, ok := ctx.Value(internal.KeyContents).(string) | ||
if !ok { | ||
return nil, errors.New("no contents in context") | ||
} | ||
|
||
var err error = nil | ||
lines := strings.Split(txt, "\n") | ||
oo := make([]runtime.Object, 0, len(lines)) | ||
for _, name := range lines { | ||
if len(name) == 0 { | ||
continue | ||
} | ||
name = strings.TrimSuffix(name, "\n") | ||
name = strings.TrimSuffix(name, "\r") | ||
if name == "./" { | ||
continue | ||
} | ||
if name == "../" && dir == "/" { | ||
continue | ||
} | ||
//if strings.HasSuffix(name, "/") { // directory | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ? |
||
// do not strip the trailing slash | ||
//name = strings.TrimSuffix(name, "/") | ||
//} | ||
name = strings.TrimSuffix(name, "*") // executable | ||
if strings.HasSuffix(name, "@") { // symlink | ||
continue // kubectl cp ignores symlinks | ||
} | ||
if strings.HasSuffix(name, "|") { // pipe | ||
continue | ||
} | ||
if strings.HasSuffix(name, "=") { // socket | ||
continue | ||
} | ||
oo = append(oo, render.DirRemoteRes{ | ||
Path: filepath.Join(dir, name), | ||
Name: name, | ||
}) | ||
} | ||
|
||
return oo, err | ||
} | ||
|
||
// Get fetch a resource. | ||
func (a *DirRemote) Get(_ context.Context, _ string) (runtime.Object, error) { | ||
return nil, errors.New("nyi") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright Authors of K9s | ||
|
||
package render | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/derailed/k9s/internal/model1" | ||
"github.com/derailed/tcell/v2" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
) | ||
|
||
// DirRemote renders a directory entry to screen. | ||
type DirRemote struct{} | ||
|
||
// IsGeneric identifies a generic handler. | ||
func (DirRemote) IsGeneric() bool { | ||
return false | ||
} | ||
|
||
// ColorerFunc colors a resource row. | ||
func (DirRemote) ColorerFunc() model1.ColorerFunc { | ||
return func(ns string, _ model1.Header, re *model1.RowEvent) tcell.Color { | ||
return tcell.ColorCadetBlue | ||
} | ||
} | ||
|
||
// Header returns a header row. | ||
func (DirRemote) Header(ns string) model1.Header { | ||
return model1.Header{ | ||
model1.HeaderColumn{Name: "NAME"}, | ||
} | ||
} | ||
|
||
// Render renders a K8s resource to screen. | ||
// BOZO!! Pass in a row with pre-alloc fields?? | ||
func (DirRemote) Render(o interface{}, ns string, r *model1.Row) error { | ||
d, ok := o.(DirRemoteRes) | ||
if !ok { | ||
return fmt.Errorf("expected DirRemoteRes, but got %T", o) | ||
} | ||
var name string | ||
var path = d.Path | ||
if strings.HasSuffix(d.Name, "/") { // directory | ||
name = "📁 " + strings.TrimSuffix(d.Name, "/") | ||
path = path + "/" // was stripped by filepath | ||
} else { | ||
name = "📄 " + d.Name | ||
} | ||
r.ID, r.Fields = path, append(r.Fields, name) | ||
|
||
return nil | ||
} | ||
|
||
// ---------------------------------------------------------------------------- | ||
// Helpers... | ||
|
||
// DirRes represents an alias resource. | ||
type DirRemoteRes struct { | ||
Name string | ||
Path string | ||
} | ||
|
||
// GetObjectKind returns a schema object. | ||
func (DirRemoteRes) GetObjectKind() schema.ObjectKind { | ||
return nil | ||
} | ||
|
||
// DeepCopyObject returns a container copy. | ||
func (d DirRemoteRes) DeepCopyObject() runtime.Object { | ||
return d | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed! Not keen on stuffing the dir contents into the context. Best if it worked like
local
list. I think we should have a util call to list out dir content on a pod. If the container is not specified, we can use the main container.