Skip to content
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

Allow read data from stdin on Windows #1104

Closed
wants to merge 2 commits into from
Closed

Conversation

jkroepke
Copy link
Contributor

@jkroepke jkroepke commented Aug 8, 2022

Fixes #739

Allow - as cross platform alternative to /dev/stdin for reading data from STDIN.

% cat secrets.yaml | ~/go/src/go.mozilla.org/sops/cmd/sops/sops --input-type yaml --output-type yaml -d -
podAnnotations:
    secret: value
% ~/go/src/go.mozilla.org/sops/cmd/sops/sops -d secrets.yaml
podAnnotations:
    secret: value

@jkroepke jkroepke changed the title Allow read data from stdin Allow read data from stdin on window Aug 8, 2022
@jkroepke jkroepke changed the title Allow read data from stdin on window Allow read data from stdin on Windows Aug 8, 2022
@jkroepke
Copy link
Contributor Author

In case tests are missing, please give me a hint where should I add the tests, thanks.

Copy link

@mulder999 mulder999 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems mostly OK for me. A few improvements needed now that error message is managed centrally.

cmd/sops/encrypt.go Outdated Show resolved Hide resolved
cmd/sops/main.go Show resolved Hide resolved
cmd/sops/common/common.go Outdated Show resolved Hide resolved
@jkroepke jkroepke requested a review from mulder999 September 29, 2022 13:47
@jkroepke
Copy link
Contributor Author

jkroepke commented Oct 3, 2022

How to move forward here?

@jkroepke
Copy link
Contributor Author

@ajvb (chosen as an active maintainer) could you take a look here?

@iverberk
Copy link

iverberk commented Dec 9, 2022

@ajvb any change of taking a look and merging? This is a nice fix that resolves having to use a custom build of SOPS on Windows

@jkroepke jkroepke changed the base branch from master to develop December 30, 2022 23:58
@jkroepke
Copy link
Contributor Author

Changing merge target to develop

@jkroepke
Copy link
Contributor Author

jkroepke commented Jan 6, 2023

Reading #927, its like it will take some time.

@hiddeco hiddeco modified the milestones: v3.8.0, v3.9.0 Jul 4, 2023
@@ -441,3 +441,19 @@ func PrettyPrintDiffs(diffs []Diff) {
}
}
}

func ReadFile(path string) (content []byte, err error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this tries to do two things which really should be separate things.

In my opinion, handling of files should really be just handling of files, with os.Stdin not classifying as such. Part because from the perspective of SOPS as an SDK, decrypt.Decrypt magically reading from os.Stdin would be kind of surprising.

Having said this, I would deal with - as a special path case within commands, and e.g. create another wrapper around DataWithFormat for an io.Reader.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

files should really be just handling of files

I don't know. On Unix, stdin is just an other file descriptor and could be handle as file, too. (like /dev/stdin)

Living the unix philosophy, there should not be a difference between /mnt/file and /proc/self/fd/1.

From technical point of view, it may should fine.

Creating an other wrapper, it possible. But the other wrapper would be the exact same copy/paste code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this the same copy/paste code?

func Reader(r io.Reader, format string) (cleartext []byte, err error) {
        encryptedData, err := io.ReadAll(r)
	if err != nil {
		return nil, err
	}
	return DataWithFormat(encryptedData, FormatFromString(format))
}

Copy link
Member

@hiddeco hiddeco Jul 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NB: I am fine with a function called ReadContent (or something something) existing (and utilized) within cmd/sops, but I wouldn't want this to be the default for decrypt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Piping using /dev/stdin doesn't work on Windows
5 participants