Skip to content

Commit

Permalink
Merge branch 'main' into 3760-add-editor-dashboard-button
Browse files Browse the repository at this point in the history
  • Loading branch information
joepavitt committed Apr 26, 2024
2 parents 5c12906 + 94f923f commit bd4bcb5
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 32 deletions.
3 changes: 3 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
deploy:pr:
- changed-files:
- any-glob-to-any-file: '!docs/**'
62 changes: 43 additions & 19 deletions .github/scripts/initial-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ create_user() {
local PASSWORD="${INIT_CONFIG_PASSWORD}"

echo "Creating $USERNAME user"
curl -ks -XPOST \
curl -ks -w "\n" -XPOST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $INIT_CONFIG_ACCESS_TOKEN" \
-d '{
Expand All @@ -35,7 +35,7 @@ create_team() {
local TEAM_TYPE_ID
TEAM_TYPE_ID=$(curl -ks -XGET -H "Authorization: Bearer $INIT_CONFIG_ACCESS_TOKEN" https://$FLOWFUSE_URL/api/v1/team-types/ | jq -r --arg TYPE "$TEAM_TYPE_SELECTOR" '.types[] | select(.name==$TYPE) | .id')
echo "Creating $TEAM_NAME team"
curl -ks -XPOST \
curl -ks -w "\n" -XPOST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $INIT_CONFIG_ACCESS_TOKEN" \
-d '{
Expand All @@ -51,6 +51,16 @@ get_team_id() {
echo "$TEAM_ID"
}

get_latest_image_tag() {
local NR_VERSION=$1
local IMAGE="flowfuse/node-red"
local TOKEN
local TAG
TOKEN=$(curl -s "https://auth.docker.io/token?service=registry.docker.io&scope=repository:${IMAGE}:pull" | jq -r '.token')
TAG=$(curl -s -H "Authorization: Bearer $TOKEN" https://registry-1.docker.io/v2/${IMAGE}/tags/list | jq -r '.tags[]' | grep -vE '^v' | grep "${NR_VERSION}" | sort -rV | head -n 1)
echo "$TAG"
}

create_suspended_instance() {
local INSTANCE_NAME=$1
local TEAM_APPLICATION_ID=$2
Expand All @@ -66,7 +76,7 @@ create_suspended_instance() {
"template": "'"$templateId"'"
}' https://$FLOWFUSE_URL/api/v1/projects/ | jq -r '.id')
sleep 5
curl -ks -XPOST \
curl -ks -w "\n" -XPOST \
-H "Authorization: Bearer $INIT_CONFIG_ACCESS_TOKEN" \
https://$FLOWFUSE_URL/api/v1/projects/$INSTANCE_ID/actions/suspend
}
Expand All @@ -77,17 +87,32 @@ create_device() {
local TEAM_NAME=$3
TEAM_ID=$(get_team_id "${TEAM_NAME}")
echo "Creating $DEVICE_NAME@$TEAM_ID device"
curl -ks -XPOST \
curl -ks -w "\n" -XPOST -o /dev/null \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $INIT_CONFIG_ACCESS_TOKEN" \
-d '{
"name": "'"$DEVICE_NAME"'",
"type": "'"$DEVICE_TYPE"'",
"team": "'"$TEAM_ID"'"
}' https://$FLOWFUSE_URL/api/v1/devices/
}

create_stack() {
local STACK_NAME=$1
local STACK_LABEL=$2
local STACK_CPU=$3
local STACK_MEMORY=$4
local STACK_CONTAINER=$5
echo "Creating $STACK_NAME stack"
projectTypeId=$(curl -ks -XGET -H "Authorization: Bearer $INIT_CONFIG_ACCESS_TOKEN" https://$FLOWFUSE_URL/api/v1/project-types/ | jq -r '.types[].id')
curl -ks -w "\n" -XPOST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $INIT_CONFIG_ACCESS_TOKEN" \
-d '{"name":"'"$STACK_NAME"'","label":"'"$STACK_LABEL"'", "projectType":"'"$projectTypeId"'","properties":{ "cpu":'"$STACK_CPU"',"memory":'"$STACK_MEMORY"',"container":"'"$STACK_CONTAINER"'"}}' \
https://$FLOWFUSE_URL/api/v1/stacks/
}

### Create first user
DBPASSWORD=$(kubectl --namespace "pr-$PR_NUMBER" get secret flowfuse-pr-$PR_NUMBER-postgresql -o jsonpath='{.data.password}' | base64 -d)
kubectl run flowfuse-setup-0 \
--namespace "pr-$PR_NUMBER" \
Expand All @@ -98,6 +123,8 @@ kubectl run flowfuse-setup-0 \
-- psql -h flowfuse-pr-$PR_NUMBER-postgresql -U forge -d flowforge -c \
"INSERT INTO public.\"Users\" (username,name,email,email_verified,sso_enabled,mfa_enabled,\"password\",password_expired,\"admin\",avatar,tcs_accepted,suspended,\"createdAt\",\"updatedAt\",\"defaultTeamId\") \
VALUES ('flowfusedeveloper','flowfusedeveloper','noreply@flowfuse.dev',true,false,false,'$INIT_CONFIG_PASSWORD_HASH',false,true,'/avatar/Zmxvd2Z1c2VkZXZlbG9wZXI',NULL,false,'2024-03-15 19:51:49.449+01','2024-03-15 19:51:49.449+01',NULL);"

### Mark platform as configured
kubectl run flowfuse-setup-1 \
--namespace "pr-$PR_NUMBER" \
-it --rm \
Expand All @@ -107,6 +134,7 @@ kubectl run flowfuse-setup-1 \
-- psql -h flowfuse-pr-$PR_NUMBER-postgresql -U forge -d flowforge -c \
"INSERT INTO public.\"PlatformSettings\" (\"key\",value,\"valueType\",\"createdAt\",\"updatedAt\")\
VALUES ('setup:initialised','true',1,'2024-03-15 19:51:52.287','2024-03-15 19:51:52.287')"
### Configure access token
kubectl run flowfuse-setup-2 \
--namespace "pr-$PR_NUMBER" \
-it --rm \
Expand All @@ -119,24 +147,20 @@ kubectl run flowfuse-setup-2 \

### Create project type
echo "Creating project type"
curl -ks -XPOST \
curl -ks -w "\n" -XPOST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $INIT_CONFIG_ACCESS_TOKEN" \
-d '{"name":"Default", "description":"DefaultInstanceType","active": true}' \
https://$FLOWFUSE_URL/api/v1/project-types/

### Create stack
echo "Creating stack"
projectTypeId=$(curl -ks -XGET -H "Authorization: Bearer $INIT_CONFIG_ACCESS_TOKEN" https://$FLOWFUSE_URL/api/v1/project-types/ | jq -r '.types[].id')
curl -ks -XPOST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $INIT_CONFIG_ACCESS_TOKEN" \
-d '{"name":"Default","label":"Default", "projectType":"'"$projectTypeId"'","properties":{ "cpu":10,"memory":256,"container":"flowfuse/node-red"}}' \
https://$FLOWFUSE_URL/api/v1/stacks/
### Create stacks
create_stack "Default" "Default" 100 256 "flowfuse/node-red"
create_stack "NR-31x" "3.1.x" 100 256 "flowfuse/node-red:$(get_latest_image_tag "3.1.x")"
create_stack "NR-40x" "4.0.x" 100 256 "flowfuse/node-red:$(get_latest_image_tag "4.0.x")"

### Link stack to project type
### Link Default to project type
echo "Linking stack to project type"
stackId=$(curl -ks -XGET -H "Authorization: Bearer $INIT_CONFIG_ACCESS_TOKEN" https://$FLOWFUSE_URL/api/v1/stacks/ | jq -r '.stacks[].id')
stackId=$(curl -ks -XGET -H "Authorization: Bearer $INIT_CONFIG_ACCESS_TOKEN" https://$FLOWFUSE_URL/api/v1/stacks/ | jq -r '.stacks[] | select(.name=="Default") | .id')
curl -ks -XPUT \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $INIT_CONFIG_ACCESS_TOKEN" \
Expand All @@ -146,11 +170,11 @@ curl -ks -XPUT \
### Delete default team type
echo "Removing default team type"
defaultTeamTypeId=$(curl -ks -XGET -H "Authorization: Bearer $INIT_CONFIG_ACCESS_TOKEN" https://$FLOWFUSE_URL/api/v1/team-types/ | jq -r '.types[] | select(.name=="starter") | .id')
curl -ks -XDELETE -H "Content-Type: application/json" -H "Authorization: Bearer $INIT_CONFIG_ACCESS_TOKEN" https://$FLOWFUSE_URL/api/v1/team-types/$defaultTeamTypeId
curl -ks -w "\n" -XDELETE -H "Content-Type: application/json" -H "Authorization: Bearer $INIT_CONFIG_ACCESS_TOKEN" https://$FLOWFUSE_URL/api/v1/team-types/$defaultTeamTypeId

### Create Starter team type
echo "Creating Starter team type"
curl -ks -XPOST \
curl -ks -w "\n" -XPOST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $INIT_CONFIG_ACCESS_TOKEN" \
-d '{
Expand Down Expand Up @@ -190,7 +214,7 @@ curl -ks -XPOST \

### Create Team team type
echo "Creating Team team type"
curl -ks -XPOST \
curl -ks -w "\n" -XPOST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $INIT_CONFIG_ACCESS_TOKEN" \
-d '{
Expand Down Expand Up @@ -230,7 +254,7 @@ curl -ks -XPOST \

### Create Enterprise team type
echo "Creating Enterprise team type"
curl -ks -XPOST \
curl -ks -w "\n" -XPOST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $INIT_CONFIG_ACCESS_TOKEN" \
-d '{
Expand Down
13 changes: 13 additions & 0 deletions .github/workflows/labeler.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: "Pull Request Labeler"
on:
- pull_request_target

jobs:
labeler:
permissions:
contents: read
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/labeler@v5
3 changes: 0 additions & 3 deletions docs/install/kubernetes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,8 @@ To enable the MQTT broker with Kubernetes install you need to add the following
forge:
broker:
enabled: true
url: mqtt://forge:1883
```

The `forge.broker.public_url` value will be generated by prepending `ws://mqtt` to the supplied `forge.domain` value.

## First Run Setup

The first time you access the platform in your browser, it will take you through
Expand Down
Binary file added docs/upgrade/images/catalogue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/upgrade/images/npmrc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions docs/upgrade/open-source-to-premium.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,27 @@ a restart of the `forge` app is required.
After the forge application has restarted, the Node-RED runtimes need to be
updated to leverage these features. As restarting Node-RED might need to be
coordinated, FlowFuse will not automatically restart all instances.


## Enabling FlowFuse User Authentication for @flowfuse/node-red-dashboard

Included with the Enterprise licensed FlowFuse is the ability to use
FlowFuse Authentication to control access to Dashboards and to have the
user information passed to the Node-RED Flow.

This is enabled by installing a Node-RED plugin `@flowfuse/node-red-dashboard-2-user-addon`.
To install this plugin you will require a npm authentication token. To request
one please contact <a href="mailto:support@flowfuse.com?subject=Dashboard 2 User addon">support@flowfuse.com</a>.

Once you have been supplied with a authentication token please follow these steps:

1. Under the Admin Settings page, open the Templates tab and edit the template
2. On the Palette page of the Template settings add the following to the "Node Catalogues" list `https://catalog.flowfuse.com/catalogue.json`
3. In the "NPM configuration file" section you will need to add
```
//registry.npmjs.org/:_authToken=<npm_auth_token>
```
replacing `<npm_auth_token>` with the token supplied earlier
4. Click on the "Save changes" button
5. Any existing Node-RED instances will need to be restarted to pick up the changes to the template
6. Once restarted you should be able to install the `@flowfuse/node-red-dashboard-2-user-addon` from the Palette Manage menu in the Node-RED instance.
4 changes: 4 additions & 0 deletions forge/ee/routes/sharedLibrary/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ module.exports = async function (app) {
})
reply.push(...subPaths)
}

// add meta info to headers
response.header('x-meta-type', direct ? direct.type : 'folder')

response.send(reply)
})

Expand Down
8 changes: 7 additions & 1 deletion frontend/src/api/team.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,13 @@ const getTeamDevices = async (teamId, cursor, limit, query, extraParams = {}) =>
const getTeamLibrary = async (teamId, parentDir, cursor, limit) => {
const url = paginateUrl(`/storage/library/${teamId}/${parentDir || ''}`, cursor, limit)
const res = await client.get(url)
return res.data
const meta = {}
// get meta.type from `x-meta-type` header
meta.type = res.headers['x-meta-type']
return {
meta,
data: res.data
}
}

/**
Expand Down
16 changes: 7 additions & 9 deletions frontend/src/pages/team/Library.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<ff-data-table-row v-for="row in rows" :key="row" :selectable="true" @click="entrySelected(row)">
<ff-data-table-cell><TypeIcon :type="row.type" /></ff-data-table-cell>
<ff-data-table-cell>{{ row.name }}</ff-data-table-cell>
<ff-data-table-cell>{{ formatDateTime(row.updatedAt) }}</ff-data-table-cell>
<ff-data-table-cell>{{ row.updatedAt ? formatDateTime(row.updatedAt) : '' }}</ff-data-table-cell>
<template #context-menu>
<ff-list-item class="ff-list-item--danger" label="Delete" @click.stop="deleteFile(row)" />
</template>
Expand Down Expand Up @@ -154,9 +154,7 @@ export default {
}
const entryPath = entryPathArray.join('/')
const entryIsFile = /\.\w+/.test(entryPath)
const contents = await teamApi.getTeamLibrary(this.team.id, entryPath)
const { meta, data: content } = await teamApi.getTeamLibrary(this.team.id, entryPath)
this.breadcrumbs = [{
name: 'Library',
Expand All @@ -166,12 +164,12 @@ export default {
this.breadcrumbs.push(this.formatEntry(entry, this.breadcrumbs.at(-1)))
}
this.viewingFile = entryIsFile
if (entryIsFile) {
this.contents = contents
this.viewingFile = meta.type !== 'folder'
if (this.viewingFile) {
this.contents = content
} else {
this.contents = null // clear selection so that copy to clipboard is hidden
this.rows = this.formatEntries(contents, this.breadcrumbs.at(-1))
this.rows = this.formatEntries(content, this.breadcrumbs.at(-1))
}
},
entrySelected (entry) {
Expand All @@ -188,7 +186,7 @@ export default {
return {
type,
name,
updatedAt: contents.updatedAt,
updatedAt: contents.updatedAt || 0, // directory listings do not have an updatedAt
path: parent.path ? (parent.path + '/' + name) : name
}
},
Expand Down
1 change: 1 addition & 0 deletions frontend/src/ui-components/stylesheets/ff-components.scss
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,7 @@ li.ff-list-item {
&--close {
cursor: pointer;
position: relative;
display: flex;
svg {
position: relative;
z-index: 2;
Expand Down

0 comments on commit bd4bcb5

Please sign in to comment.