minio / mc

Unix like utilities for object store
https://min.io/download
GNU Affero General Public License v3.0
2.88k stars 550 forks source link

"Initialization" Output Returned as Stdout #5003

Open BoweFlex opened 3 months ago

BoweFlex commented 3 months ago

The first time that any mc command is run, the following output is given:

mc: Configuration written to `/root/.mc/config.json`. Please update your access credentials.
mc: Successfully created `/root/.mc/share`.
mc: Initialized share uploads `/root/.mc/share/uploads.json` file.
mc: Initialized share downloads `/root/.mc/share/downloads.json` file.

Because of this, some situations cannot be automated properly due to this being returned when retrieving stdout from a command that just happens to be the first execution of mc (i.e. putting the output of an mc cat command into a variable. This is especially problematic with something like running an automated job pushing data through mc on a docker container with environment variables to control MC access.

Expected behavior

I think there are a few potential fixes, but without looking more I'm not positive what makes the most sense for this project:

  1. Add an optional --quiet flag to filter out some "informational" messages like this.
  2. Add an mc init command, to create this configuration without any other expected output.
  3. Change sections that output informational messages (i.e. https://github.com/minio/mc/blob/master/cmd/main.go#L271) to use console.Errorln rather than console.Infoln, which should route these messages to stderr rather than stdout and allow users to filter to receive only the output they want.

Actual behavior

When run for the first time, or after removing config (i.e. rm -rf /root/.mc):

mc cat my_subdir/base_timestamp
mc: Configuration written to `/root/.mc/config.json`. Please update your access credentials.
mc: Successfully created `/root/.mc/share`.
mc: Initialized share uploads `/root/.mc/share/uploads.json` file.
mc: Initialized share downloads `/root/.mc/share/downloads.json` file.
<contents of file>

Results are the same with something like:

mc cat my_subdir/base_timestamp 2>/dev/null
mc: Configuration written to `/root/.mc/config.json`. Please update your access credentials.
mc: Successfully created `/root/.mc/share`.
mc: Initialized share uploads `/root/.mc/share/uploads.json` file.
mc: Initialized share downloads `/root/.mc/share/downloads.json` file.
<contents of file>

Steps to reproduce the behavior

Start docker container w/ mc installed, and/or remove /root/.mc, and try running an mc command.

mc --version

Confirmed on both:

System information

Tested on rocky linux 9

taran-p commented 3 months ago

Does the --quiet flag fit your needs?

harshavardhana commented 3 months ago

we will fix this @BoweFlex

BoweFlex commented 3 months ago

Does the --quiet flag fit your needs?

No, this output is returned either way. I didn't realize the flag was already included, it must not be working as expected.

Thanks @harshavardhana