-
Notifications
You must be signed in to change notification settings - Fork 18
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
Add general citrine support #58
Merged
shankari
merged 6 commits into
EVerest:main
from
ChrisWeissmann:feature/add-citrine-support-signedoff
Jun 26, 2024
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a499947
feat: add general citrine support with own device-model. Run bash com…
ChrisWeissmann 17b26dd
slight adjustment from static code analysis action to avoid globbing
ChrisWeissmann 35fb981
fixing issues from pr feedback preventing maeve from working
thanaParis 8563062
adding rfid token generation to script
thanaParis 0b1584a
adding execution permissions to add-charger-and-rfid-card.sh
ChrisWeissmann 2f400af
fixing add rfid card call
ChrisWeissmann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
-----BEGIN RSA PRIVATE KEY----- | ||
MIIEowIBAAKCAQEA8ul5QIk9qf+grKDCN1sKPPYsxT4HegfPOm4APr3pISo3rJNy | ||
Ns8MfEryn58h8QJ8w7vSh0ZPlLpJq8oY8Y9ckaiJkNIWvRJYfFjwbMeWTLKteCOQ | ||
lYTUzKEwxhRmQB1HlKPZYo1SFjgqF7ww4q98YFQQw67gzgs/rpLeEZ4pWzOVn4qM | ||
+cBw2B0EgLFER6MI6dVja3t2NkNYRo6Jx0zs+UPKoYci7c9WETFcGOQwv2GjpOrm | ||
ekkCLnp7/3/5tmkKmUFbkTZU8+Qoq+Hgj8pAqgRYik2dl9WyE21PHygL7a6psKZR | ||
kjvOCPUqCkwjVdf/7oOfp8JAWSnWtyU4sKV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J3OYCw+mCYFjk/3o2t2cha43ag6JWcmD/joxeLxN5R9+wx0KG | ||
j/Cj6QKBgF0WuXRkQwItF2F/swibuFcnqlGjz6I5k5wBuuZiRk8PcPgCPSyoWald | ||
YzN6CLKfQSIZjO0fj7S329hc+CbKx1o+HNPjC72lP9fC/KCh8FAxMhUkcCwP7Bvt | ||
fpRG66KTIz6EZtWWAI/VjWxUo9LOX4YVTBSVLeMI+bNmKHw4VLKI | ||
-----END RSA PRIVATE KEY----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Configuration | ||
DIRECTUS_API_URL="http://localhost:8055" | ||
CHARGEPOINT_ID="cp001" | ||
CP_PASSWORD="DEADBEEFDEADBEEF" | ||
DIRECTUS_EMAIL="[email protected]" | ||
DIRECTUS_PASSWORD="CitrineOS!" | ||
|
||
#TODO put github images | ||
PROJECT_LOGO_IMAGE_URL="https://public-citrineos-logo.s3.amazonaws.com/Citrine-Directus-Project-Logo.png" | ||
PUBLIC_BACKGROUND_IMAGE_URL="https://public-citrineos-logo.s3.amazonaws.com/Citrine-Directus-Public-Background.png" | ||
|
||
# Function to get the Directus token | ||
get_directus_token() { | ||
local login_url="${DIRECTUS_API_URL}/auth/login" | ||
local json_body=$(printf '{"email": "%s", "password": "%s"}' "$DIRECTUS_EMAIL" "$DIRECTUS_PASSWORD") | ||
local response=$(curl -s -X POST "$login_url" -H "Content-Type: application/json" -d "$json_body") | ||
|
||
# Extract token from the response | ||
local token=$(jq -r '.data.access_token' <<< "$response") | ||
echo "$token" | ||
} | ||
|
||
# Function to upload an image via URL to Directus | ||
upload_image() { | ||
|
||
local token=$1 | ||
local image_url=$2 | ||
local title=$3 | ||
local response=$(curl -s -X POST "${DIRECTUS_API_URL}/files/import" \ | ||
-H "Authorization: Bearer ${token}" \ | ||
-H "Content-Type: application/json" \ | ||
-d "{ | ||
\"url\": \"${image_url}\", | ||
\"data\": { | ||
|
||
\"title\": \"${title}\" | ||
} | ||
}"| tee /dev/tty && echo) | ||
|
||
local file_id=$(jq -r '.data.id' <<< "$response") | ||
|
||
echo "$file_id" | ||
} | ||
|
||
# Function to set the project image | ||
set_project_image() { | ||
local token=$1 | ||
local project_logo=$2 | ||
local project_background=$3 | ||
curl -s -X PATCH "${DIRECTUS_API_URL}/settings" \ | ||
-H "Authorization: Bearer ${token}" \ | ||
-H "Content-Type: application/json" \ | ||
-d "{ | ||
\"project_logo\": \"${project_logo}\", | ||
\"public_background\": \"${project_background}\" | ||
}" | tee /dev/tty && echo | ||
} | ||
|
||
# Function to add a new location | ||
add_location() { | ||
local token=$1 | ||
local response=$(curl -s -X POST "${DIRECTUS_API_URL}/items/Locations" \ | ||
-H "Content-Type: application/json" \ | ||
-H "Authorization: Bearer ${token}" \ | ||
-d '{ | ||
"id": "2", | ||
"name": "New EVerst", | ||
"coordinates": { | ||
"type": "Point", | ||
"coordinates": [-74.0620872, 41.041548] | ||
} | ||
}' | tee /dev/tty && echo) | ||
|
||
local location_id=$(jq -r '.data.id' <<< "$response") | ||
echo "$location_id" | ||
} | ||
|
||
# Function to add a charging station | ||
add_charging_station() { | ||
local token="$1" | ||
local location_id="$2" | ||
local chargepointId="$3" | ||
curl -s --request POST \ | ||
--url "${DIRECTUS_API_URL}/items/ChargingStations" \ | ||
--header "Authorization: Bearer $token" \ | ||
--header "Content-Type: application/json" \ | ||
--data '{ | ||
"id": "'"$chargepointId"'", | ||
"locationId": "'"$location_id"'" | ||
}' | tee /dev/tty && echo | ||
} | ||
|
||
# Function to update SP1 password | ||
add_cp001_password() { | ||
local response | ||
local success=false | ||
local attempt=1 | ||
local passwordString=$1 | ||
|
||
until $success; do | ||
echo "Attempt $attempt: Updating SP1 password..." | ||
response=$(curl -s -o /dev/null -w "%{http_code}" --location --request PUT "http://localhost:8080/data/monitoring/variableAttribute?stationId=${CHARGEPOINT_ID}&setOnCharger=true" \ | ||
--header "Content-Type: application/json" \ | ||
--data-raw '{ | ||
"component": { | ||
"name": "SecurityCtrlr" | ||
}, | ||
"variable": { | ||
"name": "BasicAuthPassword" | ||
}, | ||
"variableAttribute": [ | ||
{ | ||
"value": "'"$passwordString"'" | ||
} | ||
], | ||
"variableCharacteristics": { | ||
"dataType": "passwordString", | ||
"supportsMonitoring": false | ||
} | ||
}' | tee /dev/tty) | ||
|
||
|
||
if [[ $response -ge 200 && $response -lt 300 ]]; then | ||
echo "Password update successful." | ||
success=true | ||
else | ||
echo "Password update failed with HTTP status: $response. Retrying in 2 second..." | ||
sleep 2 | ||
((attempt++)) | ||
fi | ||
done | ||
} | ||
|
||
# Main script execution | ||
TOKEN=$(get_directus_token) | ||
echo "Received Token: $TOKEN" | ||
|
||
if [ -z "$TOKEN" ]; then | ||
echo "Failed to retrieve access token." | ||
exit 1 | ||
fi | ||
|
||
# Upload image and set as project logo | ||
echo "Uploading project images..." | ||
FILE_ID_LOGO=$(upload_image "$TOKEN" "$PROJECT_LOGO_IMAGE_URL" "Citrine Logo") | ||
|
||
if [ -z "$FILE_ID_LOGO" ]; then | ||
echo "Failed to upload project image." | ||
exit 1 | ||
fi | ||
FILE_ID_BACKGROUND=$(upload_image "$TOKEN" "$PUBLIC_BACKGROUND_IMAGE_URL" "Citrine Background") | ||
if [ -z "$FILE_ID_BACKGROUND" ]; then | ||
echo "Failed to upload project image." | ||
exit 1 | ||
fi | ||
|
||
echo "Setting project image..." | ||
set_project_image "$TOKEN" "$FILE_ID_LOGO" "$FILE_ID_BACKGROUND" | ||
|
||
echo "Adding a new location..." | ||
LOCATION_ID=$(add_location "$TOKEN") | ||
|
||
if [ -z "$LOCATION_ID" ]; then | ||
echo "Failed to add new location." | ||
exit 1 | ||
fi | ||
|
||
echo "Location ID: $LOCATION_ID" | ||
|
||
echo "Adding new station..." | ||
add_charging_station "$TOKEN" "$LOCATION_ID" "$CHARGEPOINT_ID" | ||
|
||
echo "Add cp001 password to citrine..." | ||
add_cp001_password "$CP_PASSWORD" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you could put in an extra function to support adding in EVerest's authorization token to Citrine that would be great. I put more context regarding this in my comment here.