-
Notifications
You must be signed in to change notification settings - Fork 60
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
Feature request: automated init & usage & fire-and-forget send, GitLab CI use-case #81
Comments
thanks @xurizaemon for your issue. Just a quick first comment:
|
Thanks. What I am looking for is a "one-shot" command to relay a message from CI to developer channel. At it's most minimal, the desired interface might be:
I understand that Matrix auth workflow can use username/password to obtain a token and then use the token to relay messages. Generating the tokens separately will introduce an extra task, and if Matrix Commander is capable of rolling those two into a single step (as I am inferring, perhaps incorrectly), then it's fine (in my use case) for the access token to be used immediately and discarded. I could create an access token - but I would rather not have to maintain access tokens per project if it's possible to hand that off to matrix-commander. (And I'm happy to help make that happen. For context, I'm using a similar approach in hubot-matrix, and login/password works well there, but matrix-commander looks like a better tool for command execution rather than leaving a bot running.) |
I think I understand what you @xurizaemon are suggesting. It is technically possible, I see no show-stopper. Let me repeat and rephrase to see if I understand you correctly:
|
|
Also: For some internal bots using the I'd be happy to contribute a similar scheduled demonstration (once it's possible with matrix-commander). I believe we can do that using the public matrix.org instance where there is a #test-bot:matrix.org channel used for that purpose. If you like that idea, that can be a follow-up issue. If you don't, no pressure - but maybe it's a useful contribution which could give a folks a working example of that "Github Actions (or Gitlab CI) to Matrix" use case? |
I am seeing 2 alternatives:
These 2 alternatives are different.
|
Without much insight (yet!) into the codebase, I'd say the
I can see the use case for the So I'd propose the new behaviour like this:
I believe the required inputs to be Optional inputs would be I suggest Hope these thoughts are useful - I need to stress that I haven't read the existing code! |
Thank you @xurizaemon for sharing your thoughts. I like hearing other people's opinion.
Yes they are. I thought about it a bit. My current inclinations are:
Ok, you also brought up this issue: What to do if So much regarding the user-facing CLI. What is your opinion?
Naming: No sure yet, I am not a big fan of So much regarding user facing CLI. What is your opinion:
Internally the code needs to be restructured, authentication more/better separated from actions, etc. Arg checking needs to be modified, etc. It is not going to be a tiny change. |
Yes, I support the decision to move to an explicit "login" action which creates the required configuration for usage. Seems reasonable to then activate interactive requests in the case where not all details are required. Making authenticate parameter arguments for interactive, sso, cli makes sense. Suggest I am not sure about
(untested example - if the credentials in JSON are expired, the I think
Based on my understanding of the matrix-commander details, it seems like |
Let me rephrase to see if I understand your thoughts correctly @xurizaemon .
So far, I rephrase correctly? 2 follow-up questions:
|
I just looked at the code, currently SSO is also
I now revise my thoughts. Maybe it should be:
What is your view on this?
|
It occurs to me that the labels "password" and "sso" make sense because they are the same type of thing: they describe the Matrix login interface. "interactive" (and "cli" and "web browser") describe a different type of thing: the matrix-commander / user-facing interface. The reason this feels confusing is that same commandline flag sometimes refers to one type and sometimes to another type of thing?
So, for password login that needs to be fully automated:
For SSO:
(I don't think there's a situation where this needs an I expect that exposing 'cli' vs 'interactive' to users would be confusing because I'm enjoying this 😄 I hope I've answered your questions! |
Conceptually I agree to all. In the implementation details, my preferences vary slightly. Follow up question, to clarify:
If so, then this is not a good choice IMHO, because I could envision (not implemented): 3 methods to If an alias for BTW, emoji verify cannot be automated. Both SSO and amoji verify seem natively interactive to me.
I am glad you are enjoying this! 👏 |
Sure, yes. I wasn't sure if the existing CLI options followed the pattern noun-verb or verb-noun. Looking at the README I saw there are lots of |
OK, understood. I suggest the following then:
In the future one might add Whether it is "cli" or "interactive" will be done implicitly. If all info is provided thru command line then nothing needs to be queries from keyboard.
What do you think in general? Ways to improve it? |
Agree, aliases not required, Suggest |
We are 99% there I think.
I also thought about renaming the existing That is the last uncertainty I have. I should look up what the Matrix documentation uses primarily. If they use mostly |
I looked at the Matrix documentation today. They use Maybe I add an alias |
See commit 9a08ecb First draft of this In the end I had to rename some flags, because I realized if I re-use flags like Have a look @xurizaemon and test it out. It should be able to do Try something like:
Note, while device name can be reused, devices will accumulate if you continuously perform new |
It works! (Gitlab CI job output here) This is a CI job which builds the image from the repo's Dockerfile and then uses the built image and creds to post a message to the #test-bot:matrix.org channel. As you say, devices accumulate for repeated This looks great! I will have a chance to test it more once I'm back at my desk next week 😁 Thanks! |
Hi @xurizaemon Have a look at Commit be0a9a4 lines 124 and 125. Feel free to create a PR to explain your use case better.
All voluntarily, share as much or as little as you feel comfortable. |
- all actions (login, verify, room, get, set, send, listen) can now be added at once to the command line and executed in one go - cleanup of code - removal of --no-sso - as with last minor version, now --login is required explicitly and user must explicitly specify login method as "sso" or "password" - see also Issue #81
Regarding accumulating devices.
This is just a possibility to explore. Would be "more complex" (2 more arguments in your command) but also "more clean" for your use case. Thoughts? |
And there is another idea I have, that should be easy to do.
Once implemented (soon?) you should add this to your command. I think this |
see commit 1218268 implements Does this do everything now that you had in mind? |
It does, I think! Great work, and thanks. I thought the Gitlab CI example I linked to was visible, but I'd set the wrong visibility on that repo. It's visible now although there's more change in the MR than intended. Anyway, that was just for testing. I'll try this out in a project this week and share a snippet for using Matrix Commander to signal results from Gitlab CI when I've got that going! |
Anyway, here's an example Gitlab CI config to send a notification after a failed job, and to create a failed job to trigger it for your testing. This configuration will fail every MR, and notify it to the channel configured via those Ref: https://docs.gitlab.com/ee/ci/jobs/job_control.html stages:
- test
- report
# Just here to trigger the report.
failing test:
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
stage: test
script:
- echo "oh no it fail" && /bin/false
report to matrix:
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
when: on_failure
stage: report
image:
name: matrixcommander/matrix-commander
entrypoint: ["/bin/sh", "-c"]
script:
- export PATH=$PATH:/app/matrix_commander
- matrix-commander --login password --user-login "${MATRIX_USERNAME}" --password "${MATRIX_PASSWORD}" --homeserver "${MATRIX_HOMESERVER}" --device "ci" --room-default "${MATRIX_ROOM}" -m "Pipeline ${CI_PROJECT_URL}/-/pipelines/${CI_PIPELINE_ID} for MR ${CI_PROJECT_URL}/-/merge_requests/${CI_MERGE_REQUEST_IID} failed" (This is just to document how you'd use the docker image to post notifications from Gitlab CI to Matrix - I'm not proposing the project moves from Github or anything, to be clear. We could do a similar thing with Github Actions here.) |
I think this can be closed now - if you'd like the above contributed to docs, I'm happy to follow up with an additional PR? |
Excellent, thank you for sharing this I might add a link to this issue to the documentation. Thanks again @xurizaemon |
The fire-and-forget send is now also available on the Rust version, if for whatever reason this is preferable to you. Check out: |
I'm reading this thread with great interest and was wondering if the access token based auth mechanism was ever implemented? I'd like to send messages from CI without giving away the keys to the castle (account password). |
@asmod3us if I recall right, using Let us know how that turns out! |
@xurizaemon thanks for the hint - there is indeed an
|
Just updating this issue with an updated Note that Gitlab now also has a built-in integration, which requires using token auth; Matrix Commander permits using username/password also. Variables to configure in Gitlab CI/CD configuration are:
.notify matrix:
stage: notify
allow_failure: true
image:
name: matrixcommander/matrix-commander
entrypoint: ["/bin/bash", "-l", "-c"]
before_script:
- export PATH=$PATH:/app/matrix_commander
- matrix-commander --version
script:
- |+
matrix-commander --login password \
--user-login "${MATRIX_USERNAME}" \
--password "${MATRIX_PASSWORD}" \
--homeserver "${MATRIX_HOMESERVER}" \
--room-default "${MATRIX_ROOM}" \
--log-level ERROR ERROR \
--device "ci" \
-m "${NOTIFICATION_MESSAGE}"
success notification:
extends: .notify matrix
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
variables:
NOTIFICATION_MESSAGE: "🟢 ${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME}!${CI_MERGE_REQUEST_IID} pipeline passed\n- ${CI_MERGE_REQUEST_PROJECT_URL}/-/merge_requests/${CI_MERGE_REQUEST_IID} - ${CI_PIPELINE_URL}"
failure notification:
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
when: on_failure
extends: .notify matrix
variables:
NOTIFICATION_MESSAGE: "⭕ ${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME}!${CI_MERGE_REQUEST_IID} pipeline failed\n- ${CI_MERGE_REQUEST_PROJECT_URL}/-/merge_requests/${CI_MERGE_REQUEST_IID} - ${CI_PIPELINE_URL}" The |
Thank you @xurizaemon for this updat. This will be helpful to the community! 👏 👏 👏 |
Hi there
Motivation / backstory
I'm interested to use this tool to send messages from Gitlab CI to our internal Matrix to report build success/failure.
Currently from the docs it appears to me that first run requires some interactive usage to configure home server. I see parameters for username and password but not home server.
(I see that the server is in the username, but from other Matrix clients I draw inference that these aren't always the same value.)
Once we have run interactive init it appears from docs we will be able to reuse the generated credentials.json until the token expires.
For this use case this would require interactive logins each week due to limited token lifetime on the target server. An automated login via password works on the target environment (tested with other clients) and is the solution I would like to implement with Matrix Commander.
Questions
Is it possible to automate (no interactive input) a username/password login? If so, am I missing documentation for a
--homeserver
or--init
parameter? (#45 (comment))I'm open to helping test or implement this, and happy to document usage of matrix-commander to send build/test notifications from Gitlab CI or GitHub Actions once I get it working.
The text was updated successfully, but these errors were encountered: