From 3b931809e9bdd556594005743f06e54bd56c0a7a Mon Sep 17 00:00:00 2001 From: Emmanuel Ormancey <emmanuel.ormancey@cern.ch> Date: Mon, 17 Jan 2022 11:55:12 +0100 Subject: [PATCH] [#6] Fix API backend URI and add Powershell simple example --- Node/README.md | 5 ++ Node/send-notification.Node/README.md | 4 -- Node/send-notification/README.md | 8 ++++ .../send-notifications.js | 2 +- Powershell/README.md | 5 ++ .../README.md | 4 ++ .../rss-to-notifications.ps1 | 4 +- Powershell/send-notification/README.md | 8 ++++ .../send-notification/send-notification-ps1 | 11 +++++ Python/README.md | 5 ++ .../README.md | 0 .../api_library/__init__.py | 0 .../api_library/channel.py | 2 +- .../api_library/egroup_from_ldap.py | 0 .../api_library/egroups_api.py | 0 .../api_library/get_api_token.py | 0 .../api_library/grappa_api.py | 0 .../api_library/grappa_get_api_token.py | 0 .../egroup_to_channel.py | 0 .../README.md | 4 ++ .../rss-to-notifications.py | 2 +- Python/send-notification.Python/README.md | 4 -- Python/send-notification/README.md | 8 ++++ .../send-notifications.py | 2 +- curl/README.md | 46 +++++++++++++++++++ curl/send-notification.script/README.md | 5 -- curl/send-notification/README.md | 8 ++++ .../notification.json | 0 .../sendnotification.sh | 2 +- 29 files changed, 120 insertions(+), 19 deletions(-) create mode 100644 Node/README.md delete mode 100644 Node/send-notification.Node/README.md create mode 100644 Node/send-notification/README.md rename Node/{send-notification.Node => send-notification}/send-notifications.js (90%) create mode 100644 Powershell/README.md rename Powershell/{rss-to-notifications.Powershell => rss-to-notifications}/README.md (61%) rename Powershell/{rss-to-notifications.Powershell => rss-to-notifications}/rss-to-notifications.ps1 (93%) create mode 100644 Powershell/send-notification/README.md create mode 100644 Powershell/send-notification/send-notification-ps1 create mode 100644 Python/README.md rename Python/{egroup-to-channel.Python => egroup-to-channel}/README.md (100%) rename Python/{egroup-to-channel.Python => egroup-to-channel}/api_library/__init__.py (100%) rename Python/{egroup-to-channel.Python => egroup-to-channel}/api_library/channel.py (95%) rename Python/{egroup-to-channel.Python => egroup-to-channel}/api_library/egroup_from_ldap.py (100%) rename Python/{egroup-to-channel.Python => egroup-to-channel}/api_library/egroups_api.py (100%) rename Python/{egroup-to-channel.Python => egroup-to-channel}/api_library/get_api_token.py (100%) rename Python/{egroup-to-channel.Python => egroup-to-channel}/api_library/grappa_api.py (100%) rename Python/{egroup-to-channel.Python => egroup-to-channel}/api_library/grappa_get_api_token.py (100%) rename Python/{egroup-to-channel.Python => egroup-to-channel}/egroup_to_channel.py (100%) rename Python/{rss-to-notifications.Python => rss-to-notifications}/README.md (58%) rename Python/{rss-to-notifications.Python => rss-to-notifications}/rss-to-notifications.py (94%) delete mode 100644 Python/send-notification.Python/README.md create mode 100644 Python/send-notification/README.md rename Python/{send-notification.Python => send-notification}/send-notifications.py (90%) create mode 100644 curl/README.md delete mode 100644 curl/send-notification.script/README.md create mode 100644 curl/send-notification/README.md rename curl/{send-notification.script => send-notification}/notification.json (100%) rename curl/{send-notification.script => send-notification}/sendnotification.sh (61%) diff --git a/Node/README.md b/Node/README.md new file mode 100644 index 0000000..6639160 --- /dev/null +++ b/Node/README.md @@ -0,0 +1,5 @@ +# JS scripts +Use corresponding base uri depending on the target infrastructure: +- https://notifications.web.cern.ch/api +- https://notifications-qa.web.cern.ch/api +- https://notifications-dev.web.cern.ch/api diff --git a/Node/send-notification.Node/README.md b/Node/send-notification.Node/README.md deleted file mode 100644 index 558b19f..0000000 --- a/Node/send-notification.Node/README.md +++ /dev/null @@ -1,4 +0,0 @@ -# send-notification Python script - -- Fill ```channelId``` and ```notifications_bearer``` from Notification service information - diff --git a/Node/send-notification/README.md b/Node/send-notification/README.md new file mode 100644 index 0000000..1107e9f --- /dev/null +++ b/Node/send-notification/README.md @@ -0,0 +1,8 @@ +# send-notification script + +- Fill ```channelId``` and ```notifications_bearer``` from Notification service information + +Use corresponding base uri depending on the target infrastructure: +- https://notifications.web.cern.ch/api +- https://notifications-qa.web.cern.ch/api +- https://notifications-dev.web.cern.ch/api diff --git a/Node/send-notification.Node/send-notifications.js b/Node/send-notification/send-notifications.js similarity index 90% rename from Node/send-notification.Node/send-notifications.js rename to Node/send-notification/send-notifications.js index fcb0ac8..b854b13 100644 --- a/Node/send-notification.Node/send-notifications.js +++ b/Node/send-notification/send-notifications.js @@ -1,7 +1,7 @@ const https = require('https'); // Target Notification channel -const notifications_sendapi = "https://api-notifications.app.cern.ch/notifications"; +const notifications_sendapi = "https://notifications.web.cern.ch/api/notifications"; const notifications_bearer = "fill-me with Channel API Key"; const channelId = "fill-me with ChannelID"; diff --git a/Powershell/README.md b/Powershell/README.md new file mode 100644 index 0000000..7b051e3 --- /dev/null +++ b/Powershell/README.md @@ -0,0 +1,5 @@ +# Powershell scripts +Use corresponding base uri depending on the target infrastructure: +- https://notifications.web.cern.ch/api +- https://notifications-qa.web.cern.ch/api +- https://notifications-dev.web.cern.ch/api diff --git a/Powershell/rss-to-notifications.Powershell/README.md b/Powershell/rss-to-notifications/README.md similarity index 61% rename from Powershell/rss-to-notifications.Powershell/README.md rename to Powershell/rss-to-notifications/README.md index f0a4317..b85c735 100644 --- a/Powershell/rss-to-notifications.Powershell/README.md +++ b/Powershell/rss-to-notifications/README.md @@ -5,3 +5,7 @@ - Fill ```channelId``` and ```notifications_bearer``` from Notification service information - In the loop, an old SSO automatic auth with kerberos is provided (commented out by default) +Use corresponding base uri depending on the target infrastructure: +- https://notifications.web.cern.ch/api +- https://notifications-qa.web.cern.ch/api +- https://notifications-dev.web.cern.ch/api diff --git a/Powershell/rss-to-notifications.Powershell/rss-to-notifications.ps1 b/Powershell/rss-to-notifications/rss-to-notifications.ps1 similarity index 93% rename from Powershell/rss-to-notifications.Powershell/rss-to-notifications.ps1 rename to Powershell/rss-to-notifications/rss-to-notifications.ps1 index e74124f..c72f637 100644 --- a/Powershell/rss-to-notifications.Powershell/rss-to-notifications.ps1 +++ b/Powershell/rss-to-notifications/rss-to-notifications.ps1 @@ -10,10 +10,12 @@ $FeedList = @( $datafile = "C:\Program Files\CERN\RSS-To-Notifications\rss-to-notifications.dat" # Target Notification channel -$notifications_sendapi = "https://api-notifications.app.cern.ch/notifications" +$notifications_sendapi = "https://notifications.web.cern.ch/api/notifications" $notifications_bearer = "fill-me with Channel API Key" $channelId = "fill-me with ChannelID" +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 + # Processing all the source RSS Foreach ($OneFeed in $FeedList) { diff --git a/Powershell/send-notification/README.md b/Powershell/send-notification/README.md new file mode 100644 index 0000000..ac94d2f --- /dev/null +++ b/Powershell/send-notification/README.md @@ -0,0 +1,8 @@ +# send-notification Powershell script + +- Fill ```channelId``` and ```notifications_bearer``` from Notification service information + +Use corresponding base uri depending on the target infrastructure: +- https://notifications.web.cern.ch/api +- https://notifications-qa.web.cern.ch/api +- https://notifications-dev.web.cern.ch/api diff --git a/Powershell/send-notification/send-notification-ps1 b/Powershell/send-notification/send-notification-ps1 new file mode 100644 index 0000000..c6e440a --- /dev/null +++ b/Powershell/send-notification/send-notification-ps1 @@ -0,0 +1,11 @@ +# Target Notification channel +$notifications_sendapi = "https://notifications.web.cern.ch/api/notifications" +$notifications_bearer = "......." +$channelId = "......" + +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 + +$Notification = @{ target=$channelId; summary='Title'; priority='NORMAL'; body='description' } +$Payload = @{ notification=$Notification} +$headers = @{Authorization = "Bearer $notifications_bearer"} +Invoke-RestMethod -Uri $notifications_sendapi -Method Post -ContentType 'application/json;charset=utf-8' -Headers $headers -Body (ConvertTo-Json $Payload) \ No newline at end of file diff --git a/Python/README.md b/Python/README.md new file mode 100644 index 0000000..2740bc6 --- /dev/null +++ b/Python/README.md @@ -0,0 +1,5 @@ +# Python scripts +Use corresponding base uri depending on the target infrastructure: +- https://notifications.web.cern.ch/api +- https://notifications-qa.web.cern.ch/api +- https://notifications-dev.web.cern.ch/api diff --git a/Python/egroup-to-channel.Python/README.md b/Python/egroup-to-channel/README.md similarity index 100% rename from Python/egroup-to-channel.Python/README.md rename to Python/egroup-to-channel/README.md diff --git a/Python/egroup-to-channel.Python/api_library/__init__.py b/Python/egroup-to-channel/api_library/__init__.py similarity index 100% rename from Python/egroup-to-channel.Python/api_library/__init__.py rename to Python/egroup-to-channel/api_library/__init__.py diff --git a/Python/egroup-to-channel.Python/api_library/channel.py b/Python/egroup-to-channel/api_library/channel.py similarity index 95% rename from Python/egroup-to-channel.Python/api_library/channel.py rename to Python/egroup-to-channel/api_library/channel.py index 763fdf2..8f00db3 100644 --- a/Python/egroup-to-channel.Python/api_library/channel.py +++ b/Python/egroup-to-channel/api_library/channel.py @@ -2,7 +2,7 @@ import requests import re, sys from api_library.get_api_token import get_api_token -BACKEND_URL='https://api-notifications-dev.app.cern.ch' +BACKEND_URL='https://notifications-dev.web.cern.ch/api' #BACKEND_URL='https://localhost:8080' ACCESS_TOKEN=get_api_token() HEADER={'Authorization': 'Bearer ' + ACCESS_TOKEN} diff --git a/Python/egroup-to-channel.Python/api_library/egroup_from_ldap.py b/Python/egroup-to-channel/api_library/egroup_from_ldap.py similarity index 100% rename from Python/egroup-to-channel.Python/api_library/egroup_from_ldap.py rename to Python/egroup-to-channel/api_library/egroup_from_ldap.py diff --git a/Python/egroup-to-channel.Python/api_library/egroups_api.py b/Python/egroup-to-channel/api_library/egroups_api.py similarity index 100% rename from Python/egroup-to-channel.Python/api_library/egroups_api.py rename to Python/egroup-to-channel/api_library/egroups_api.py diff --git a/Python/egroup-to-channel.Python/api_library/get_api_token.py b/Python/egroup-to-channel/api_library/get_api_token.py similarity index 100% rename from Python/egroup-to-channel.Python/api_library/get_api_token.py rename to Python/egroup-to-channel/api_library/get_api_token.py diff --git a/Python/egroup-to-channel.Python/api_library/grappa_api.py b/Python/egroup-to-channel/api_library/grappa_api.py similarity index 100% rename from Python/egroup-to-channel.Python/api_library/grappa_api.py rename to Python/egroup-to-channel/api_library/grappa_api.py diff --git a/Python/egroup-to-channel.Python/api_library/grappa_get_api_token.py b/Python/egroup-to-channel/api_library/grappa_get_api_token.py similarity index 100% rename from Python/egroup-to-channel.Python/api_library/grappa_get_api_token.py rename to Python/egroup-to-channel/api_library/grappa_get_api_token.py diff --git a/Python/egroup-to-channel.Python/egroup_to_channel.py b/Python/egroup-to-channel/egroup_to_channel.py similarity index 100% rename from Python/egroup-to-channel.Python/egroup_to_channel.py rename to Python/egroup-to-channel/egroup_to_channel.py diff --git a/Python/rss-to-notifications.Python/README.md b/Python/rss-to-notifications/README.md similarity index 58% rename from Python/rss-to-notifications.Python/README.md rename to Python/rss-to-notifications/README.md index 36c3468..03a7cf7 100644 --- a/Python/rss-to-notifications.Python/README.md +++ b/Python/rss-to-notifications/README.md @@ -6,3 +6,7 @@ - Edit ```$datafile``` path - Fill ```channelId``` and ```notifications_bearer``` from Notification service information +Use corresponding base uri depending on the target infrastructure: +- https://notifications.web.cern.ch/api +- https://notifications-qa.web.cern.ch/api +- https://notifications-dev.web.cern.ch/api diff --git a/Python/rss-to-notifications.Python/rss-to-notifications.py b/Python/rss-to-notifications/rss-to-notifications.py similarity index 94% rename from Python/rss-to-notifications.Python/rss-to-notifications.py rename to Python/rss-to-notifications/rss-to-notifications.py index 5213f9e..8ab8bf6 100644 --- a/Python/rss-to-notifications.Python/rss-to-notifications.py +++ b/Python/rss-to-notifications/rss-to-notifications.py @@ -9,7 +9,7 @@ FeedList = ["https://home.cern/api/news/feed.rss"] datafile = "rss-to-notifications.dat" # Target Notification channel -notifications_sendapi = "https://api-notifications.app.cern.ch/notifications" +notifications_sendapi = "https://notifications.web.cern.ch/api/notifications" notifications_bearer = "fill-me with Channel API Key" channelId = "fill-me with ChannelID" diff --git a/Python/send-notification.Python/README.md b/Python/send-notification.Python/README.md deleted file mode 100644 index 558b19f..0000000 --- a/Python/send-notification.Python/README.md +++ /dev/null @@ -1,4 +0,0 @@ -# send-notification Python script - -- Fill ```channelId``` and ```notifications_bearer``` from Notification service information - diff --git a/Python/send-notification/README.md b/Python/send-notification/README.md new file mode 100644 index 0000000..070d5bb --- /dev/null +++ b/Python/send-notification/README.md @@ -0,0 +1,8 @@ +# send-notification Python script + +- Fill ```channelId``` and ```notifications_bearer``` from Notification service information + +Use corresponding base uri depending on the target infrastructure: +- https://notifications.web.cern.ch/api +- https://notifications-qa.web.cern.ch/api +- https://notifications-dev.web.cern.ch/api diff --git a/Python/send-notification.Python/send-notifications.py b/Python/send-notification/send-notifications.py similarity index 90% rename from Python/send-notification.Python/send-notifications.py rename to Python/send-notification/send-notifications.py index 23d1518..95b5d3a 100644 --- a/Python/send-notification.Python/send-notifications.py +++ b/Python/send-notification/send-notifications.py @@ -1,7 +1,7 @@ import requests # Target Notification channel -notifications_sendapi = "https://api-notifications.app.cern.ch/notifications" +notifications_sendapi = "https://notifications.web.cern.ch/api/notifications" notifications_bearer = "fill-me with Channel API Key" channelId = "fill-me with ChannelID" diff --git a/curl/README.md b/curl/README.md new file mode 100644 index 0000000..2703e36 --- /dev/null +++ b/curl/README.md @@ -0,0 +1,46 @@ +# Simple curl examples +Use corresponding base uri depending on the target infrastructure: +- https://notifications.web.cern.ch/api +- https://notifications-qa.web.cern.ch/api +- https://notifications-dev.web.cern.ch/api + +## Basic Curl example: +``` +curl -X POST https://notifications.web.cern.ch/api/notifications \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer <api-key>" \ + --insecure \ + --data '{ + "notification": + { + "target": 'channel id that you can find in your browser url bar' + "summary":"Test notification", + "priority":"NORMAL", + "body":"<p>This is a test notification sent via the API</p>" + } + }' +``` +## Curl example for a targeted notification: +``` +curl -X POST https://notifications.web.cern.ch/api/notifications \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer <api-key>" \ + --insecure \ + --data '{ + "notification": + { + "target": 'channel id that you can find in your browser url bar' + "summary":"Test targeted notification", + "priority":"NORMAL", + "body":"<p>This is a test targeted notification sent via the API</p>", + "private": true, + "targetUsers": [{"email": ""some-member@some.domain"}, ...], + "targetGroups": [{"groupIdentifier": "some-group"}, ...], + "targetData": ["some-member@some.domain", "some-group", ...] + } + } +``` +Notes: +- ```targetUser```: can contain only user objects with an email address, +- ```targetGroups```: can contain only group objects with a groupIdentifier containing the name, +- ```targetData```: can contain mixed strings emails and group names (but degraded performance therefore not the recommended option). diff --git a/curl/send-notification.script/README.md b/curl/send-notification.script/README.md deleted file mode 100644 index e504115..0000000 --- a/curl/send-notification.script/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# send-notification shell script - -- Fill ```channelId``` in ```notification.json``` with the Channel ID -- Fill ```bearer``` in ```sendnotification.sh``` with the Channel API Key - diff --git a/curl/send-notification/README.md b/curl/send-notification/README.md new file mode 100644 index 0000000..f99ef9c --- /dev/null +++ b/curl/send-notification/README.md @@ -0,0 +1,8 @@ +# send-notification shell script +- Fill ```channelId``` in ```notification.json``` with the Channel ID +- Fill ```bearer``` in ```sendnotification.sh``` with the Channel API Key + +Use corresponding base uri depending on the target infrastructure: +- https://notifications.web.cern.ch/api +- https://notifications-qa.web.cern.ch/api +- https://notifications-dev.web.cern.ch/api diff --git a/curl/send-notification.script/notification.json b/curl/send-notification/notification.json similarity index 100% rename from curl/send-notification.script/notification.json rename to curl/send-notification/notification.json diff --git a/curl/send-notification.script/sendnotification.sh b/curl/send-notification/sendnotification.sh similarity index 61% rename from curl/send-notification.script/sendnotification.sh rename to curl/send-notification/sendnotification.sh index 30e060e..a985334 100644 --- a/curl/send-notification.script/sendnotification.sh +++ b/curl/send-notification/sendnotification.sh @@ -1,6 +1,6 @@ #!/bin/bash -curl -X POST https://api-notifications.app.cern.ch/notifications/notifications/apisend \ +curl -X POST https://notifications.web.cern.ch/api/notifications \ -H "Content-Type: application/json" \ -H "Authorization: Bearer fill-me-with-APIKey" \ --data '@notification.json' -- GitLab