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

.Stdout in HTTP hook body template seems to always be empty #260

Open
guahki opened this issue Sep 29, 2023 · 4 comments
Open

.Stdout in HTTP hook body template seems to always be empty #260

guahki opened this issue Sep 29, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@guahki
Copy link

guahki commented Sep 29, 2023

First: thanks for this awesome tool helping to easily deploy restic!

I just tried to use .Stdout in the body-template of a send-* action as described in the docs (using resticprofile in version 0.23.0). But it seems to always be empty, regardless of error state and output of before running commands.

Am I doing something wrong? Do you need to set some undocumented setting for it to work?

Despite not being familiar with Go I tried to find the place where this variable is set, but could not find it. I found the definition of the struct at

but despite extensive search could not find any place populating this struct value. Is it possible that it was forgotten to populate it in #114? I find only two occurences of Stdout in the diff of this PR and one is the docs, the other the above mentioned definition.

@creativeprojects
Copy link
Owner

I think you're right, it looks like it got missed 😨

@creativeprojects creativeprojects added the bug Something isn't working label Sep 30, 2023
@guahki
Copy link
Author

guahki commented Oct 4, 2023

No problem. Unfortunatelly, I really do know nothing about Go, so I can't help by providing a PR, sorry.

Do you see any way of temporarily work around this by using the schedule-log setting and include the resulting file in the body-template? I tried, but failed to find any method of including a plain file in the Go template language. Might be easy and I just missed it, as (as I said) I'm not familiar with Go at all.

And the long-term question: can you say, if you plan to include the .Stdout correctly? Can you give a (obviously very rough) estimate when this might happen? I would never nail you down on this, but just to get a feel, if you are working on it right now or it's far down on the priority list.

@jkellerer
Copy link
Collaborator

@guahki, I'll reference this case for #207 and look into it. Was a bit busy with other things lastly but will continue to work on the PR soon.

So far we always tried to avoid redirecting stdout to not alter the default behaviour of restic (which does not display any progress when stdout is redirected). But with #207 we will be able to redirect more easily and capture the output so that it can be provided in .Stdout.

Regarding a workaround, how about:

  {{ $body := tempFile "body-template-file" }}
  default:
    backup:
      schedule-log: '{{ tempFile "log-output" }}'

      run-finally: 
        - echo "Log for {{ .Profile.Name }} @ {{ .Hostname }}:" > '{{ $body }}'
        - echo "---------------------------------------------" >> '{{ $body }}'
        - cat '{{ tempFile "log-output" }}' >> '{{ $body }}'
        - echo "---------------------------------------------" >> '{{ $body }}'

      send-finally:
        - body-template: '{{ $body }}'

Regarding including files in templates. So far we do not provide such an extension. I had thought about it beforehand but had no use case that requires it. Maybe I can add an include function for raw includes in in go templates with one of the next releases.

@guahki
Copy link
Author

guahki commented Oct 7, 2023

Thank you so much @jkellerer for your extensive answer. Would be great to see this implemented (at least since it is available regarding to the docs 😆).

I will play around with your great example for a workaround. Did not think about using run-* to "prepare" the body-template used by the hook. This is a neat idea and I will see if I can get what I want.

Finally: take your time on #207 and do not feel bothered by me. I know there is more important things than FOSS projects in life.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants