Git Product home page Git Product logo

stree's Introduction

S3 directory tree visualization

๐Ÿ“stree

Directory trees of S3

MIT License badge Release workflow status badge Tag PR workflow status badge MegaLinter badge

Demonstration of stree tool in action

Overview

stree is a CLI tool designed to visualize the directory tree structure of an S3 bucket.
By inputting an S3 bucket/prefix and utilizing various flags to customize your request, you can obtain a colorized or non-colorized directory tree right in your terminal.

Whether it's for verifying the file structure, sharing the structure with your team, or any other purpose, stree offers an easy and convenient way to explore your S3 buckets.

ๆ—ฅๆœฌ่ชžใฎ็ดนไป‹่จ˜ไบ‹โ†’stree๏ผšS3ใƒใ‚ฑใƒƒใƒˆใ‚’treeใ™ใ‚‹CLIใ‚ณใƒžใƒณใƒ‰

Community | AWS open source newsletter, #189

Features

  • Colorized Output: By default, stree provides a colorized tree structure, making it easy to differentiate between directories and files at a glance. This feature can be turned off with the -n or --no-color flag.
  • LocalStack Support: stree supports local testing with LocalStack, a fully functional local AWS cloud stack, thanks to the --local and --endpoint-url flags.
  • Custom AWS Profile and Region: Specify the AWS profile and region with the --profile and --region flags to override the default settings as needed.
  • Ease of Installation: Install stree via Go, Homebrew, or by downloading the latest compiled binaries from the GitHub releases page.
  • Depth level Specification: With the new --L flag, you can now specify how many levels deep in the directory structure you'd like to visualize. This offers a more focused view, especially for large S3 buckets.
  • Role Switching Support: stree is now enhanced with the ability to switch AWS roles with MFA using the --mfa flag. This makes it easier to manage and view S3 buckets that require different IAM roles for access.
  • Environment Variable Support: stree now prioritizes environment variables for AWS Profile and Region settings. The tool will use the AWS_PROFILE environment variable if set, falling back to the default profile otherwise. Similarly, it will use the AWS_REGION or AWS_DEFAULT_REGION environment variables for the AWS region, if available. (see AWS CLI Environment Variables for more information)

Install

Go

go install github.com/orangekame3/stree@latest

Homebrew

brew install orangekame3/tap/stree

Download

Download the latest compiled binaries and put it anywhere in your executable path.

Download here

How to Use

Warning

Prerequisite
You must set up the config and credentials to be used with aws cli in advance

From here on, it is assumed that the config and credentials are set as follows.

~/.aws/config
[my_profile]
region = ap-northeast-1
output = json
~/.aws/credentials
[my_profile]
aws_access_key_id=XXXXXXXXXXXXXXXXXXXXX
aws_secret_access_key=XXXXXXXXXXXXXXXXX

Basic Commands

Specify the bucket name and profile, and execute the following command. The profile is specified with --profile (-p).

stree my-bucket -p my_profile

You will get the following output.

my-bucket
โ””โ”€โ”€ test
    โ”œโ”€โ”€ dir1
    โ”‚   โ”œโ”€โ”€ dir1_1
    โ”‚   โ”‚   โ””โ”€โ”€ dir1_1_1
    โ”‚   โ”‚       โ”œโ”€โ”€ file1.csv
    โ”‚   โ”‚       โ””โ”€โ”€ file2.csv
    โ”‚   โ””โ”€โ”€ dir1_2
    โ”‚       โ”œโ”€โ”€ file1.csv
    โ”‚       โ”œโ”€โ”€ file2.csv
    โ”‚       โ””โ”€โ”€ file3.csv
    โ”œโ”€โ”€ dir2
    โ”‚   โ””โ”€โ”€ dir2_1
    โ”‚       โ””โ”€โ”€ dir2_1_1
    โ”‚           โ”œโ”€โ”€ file1.csv
    โ”‚           โ”œโ”€โ”€ file2.csv
    โ”‚           โ””โ”€โ”€ file3.csv
    โ””โ”€โ”€ dir3
        โ”œโ”€โ”€ file1.csv
        โ””โ”€โ”€ file2.csv

9 directories, 10 files

Specifying Prefix

stree my-bucket/test/dir2 -p my_profile

The result of executing this command is as follows.

my-bucket
โ””โ”€โ”€ test
    โ””โ”€โ”€ dir2
        โ””โ”€โ”€ dir2_1
            โ””โ”€โ”€ dir2_1_1
                โ”œโ”€โ”€ file1.csv
                โ”œโ”€โ”€ file2.csv
                โ””โ”€โ”€ file3.csv

4 directories, 3 files

Overriding Region

You can specify the region with --region (-r). Use the --region flag to override when you want to specify a region other than the one listed in the profile.

Usage with Localstack

It can also be used with Localstack. When using it with Localstack, the endpoint and region are set to the following by default.

endpoint = http://localhost:4566
region = us-east-1

Since the majority of cases are expected to use the above settings, we have added a flag for Localstack, which is --local (-l).

stree my-bucket/test/dir2 -l

In case you need to change the endpoint and region due to special circumstances, you can override with --region (-r) flag and --endpoint (-e).

stree my-bucket/test/dir2 -r us-east-1 -e http://localhost:4537

Disable Color Output

You can disable color output with --no-color (-n).

With color

with color

Without color

without color

Specifying Depth Level

You can specify the depth level with --level (-L). The default is 0, which means that all directories are displayed.

stree my-bucket -p my_profile -L 3
my-bucket
โ””โ”€โ”€ test
    โ”œโ”€โ”€ dir3
    โ”‚   โ”œโ”€โ”€ file1.csv
    โ”‚   โ””โ”€โ”€ file2.csv
    โ”œโ”€โ”€ dir1
    โ”‚   โ”œโ”€โ”€ dir1_1
    โ”‚   โ””โ”€โ”€ dir1_2
    โ””โ”€โ”€ dir2
        โ””โ”€โ”€ dir2_1

Role Switching Support

You can switch roles with MFA using the --mfa flag. This makes it easier to manage and view S3 buckets that require different IAM roles for access.

To use this feature, you must first set up the config and credentials to be used with aws cli in advance.

[profile dev_david]
source_profile = my_profile
# MFA device
mfa_serial = arn:aws:iam::820544363308:mfa/david_mfa_device
# Role to assume
role_arn = arn:aws:iam::820544363308:role/david_role

see Assume AWS IAM Roles with MFA Using the AWS SDK for Go for more information

And then execute the following command.

stree my-bucket -p dev_david -mfa

Also, if you wish to operate with a profile that assumes a role, you can specify it using the --profile (-p) flag, without the need for MFA.

[profile dev_david]
source_profile = my_profile
# Role to assume
role_arn = arn:aws:iam::820544363308:role/david_role

And then execute the following command.

stree my-bucket -p dev_david

Usage

Usage:
  stree [bucket/prefix] [flags]

Flags:
  -e, --endpoint-url string   AWS endpoint URL to use (useful for local testing with LocalStack)
  -h, --help                  help for stree
  -L, --level int             Descend only level directories
  -l, --local                 Use LocalStack configuration
  -m, --mfa                   Use Multi-Factor Authentication
  -n, --no-color              Disable colorized output
  -p, --profile string        AWS profile to use (default "default")
  -r, --region string         AWS region to use (overrides the region specified in the profile)

License

stree is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

The concept of "stree" was inspired by the pioneering work seen in gtree. I'm grateful for the inspiration.

stree's People

Contributors

ddddddo avatar fujiwara avatar github-actions[bot] avatar lusingander avatar mashiike avatar orangekame3 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

stree's Issues

.Addใƒกใ‚ฝใƒƒใƒ‰ใฎๅผ•ๆ•ฐใซ็ฉบๆ–‡ๅญ—ใŒๅซใพใ‚Œใฆใ„ใ‚‹ใ‹ใ‚‚ใ—ใ‚Œใชใ„

ๆ—ฉ้€ŸCLIใ‚’ไฝฟใ‚ใ›ใฆใ„ใŸใ ใใพใ—ใŸ๏ผใ‚ซใƒฉใƒผใงๅ‡บๅŠ›ใ•ใ‚Œใ‚‹ใฎใŒใจใฆใ‚‚่‰ฏใใฆใƒ‘ใƒƒใจๆง‹้€ ใŒๆŠŠๆกใงใใ‚‹ใฎใ‚คใ‚คใงใ™ใ‚ˆใญ๏ผ
ใ‚ใ‚ŠใŒใจใ†ใ”ใ–ใ„ใพใ™๐Ÿ™‡

ๅฐ‘ใ—่ฉฆใ—ใฆใฟใพใ—ใฆใ€ใ‚‚ใ—ใ‹ใ™ใ‚‹ใจAddใƒกใ‚ฝใƒƒใƒ‰ใซ็ฉบๆ–‡ๅญ—(?)ใŒๆธกใ•ใ‚Œใฆใ„ใ‚‹ใ‹ใ‚‚ใจๆ€ใ„ๅ…ฑๆœ‰ใงใ™๐Ÿ™‡
๏ผˆforkใ—ใฆๅ‹•ไฝœ็ขบ่ช&PRๅ‡บใ—ใŸใ„ใจใ“ใ‚ใชใฎใงใ™ใŒใ€ใกใ‚‡ใฃใจ้…ใใซใชใ‚Šใใ†ใงใ—ใฆ....๏ผ‰

stree ใฎ version

~
00:23:52 > stree --version
stree version 0.0.7 (Built on 2023-09-14 00:24:05.325784283 +0900 JST m=+0.004862551)

AWS S3ไธŠใฎใƒใ‚ฑใƒƒใƒˆๆง‹ๆˆ

~
00:24:05 > aws s3 ls --recursive show-tree-bucket
2023-09-13 21:39:11     593312 demo.gif
2023-09-13 21:38:16          0 first/
2023-09-13 21:39:49          0 first/chil/
2023-09-13 21:40:05          0 first/chil/chilchil/
2023-09-13 21:40:58      34283 first/chil/chilchil/verify.png
2023-09-13 21:40:58    1283720 first/chil/chilchil/web_example.gif

stree show-tree-bucket -p default -r ap-northeast-1 ๅฎŸ่กŒ็ตๆžœ

~
00:23:36 > stree show-tree-bucket -p default -r ap-northeast-1
show-tree-bucket
โ”œโ”€โ”€ demo.gif
โ””โ”€โ”€ first
    โ”œโ”€โ”€                               <- ใ“ใ“ใŒ็ฉบๆ–‡ๅญ—๏ผŸ
    โ””โ”€โ”€ chil
        โ”œโ”€โ”€                           <- ใ“ใ“ใŒ็ฉบๆ–‡ๅญ—๏ผŸ
        โ””โ”€โ”€ chilchil
            โ”œโ”€โ”€                       <- ใ“ใ“ใŒ็ฉบๆ–‡ๅญ—๏ผŸ
            โ”œโ”€โ”€ verify.png
            โ””โ”€โ”€ web_example.gif

3 directories, 3 files

ใ“ใกใ‚‰่ฆ‹ใฆ้ ‚ใ‘ใ‚‹ใจๅฌ‰ใ—ใ„ใงใ™๏ผ

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.