Skip to content

Commit

Permalink
Merge pull request #973 from jinroh/apps-flavor
Browse files Browse the repository at this point in the history
Konnectors flavor and parameters
  • Loading branch information
nono committed Sep 27, 2017
2 parents c295cef + 2381a92 commit f44b6b5
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 22 deletions.
15 changes: 1 addition & 14 deletions docs/konnectors.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,15 @@ type | the type of the konnector source ("node" is the only supported
slug | the default slug (it can be changed at install time)
icon | an icon for the home
description | a short description of the konnector
fields | the list of required fields with their type
source | where the files of the app can be downloaded
developer | `name` and `url` for the developer
default_locale | the locale used for the name and description fields
locales | translations of the name and description fields in other locales
version | the current version number
parameters | any json object that will be passed to the konnector on execution in the `COZY_PARAMETERS` environment variable
license | [the SPDX license identifier](https://spdx.org/licenses/)
permissions | a map of permissions needed by the app (see [here](permissions.md) for more details)

For the "fields" field here is an example :
```
{
"fields": {
"login": "string",
"password": "password",
"folderPath": "path"
}
}
```

This will allow the "My accounts" application to get the list of fields to display and their type. The list of possible types still needs to be defined.

### POST /konnectors/:slug

Install a konnector, ie download the files and put them in `/konnectors/:slug` in the virtual file system of the user, create an `io.cozy.konnectors` document, register the permissions, etc.
Expand Down
7 changes: 4 additions & 3 deletions docs/konnectors_design.md
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,10 @@ directory](https://github.com/cozy-labs/konnectors/tree/master/server/lib).

The konnector will be run with the following environment variables :

- COZY_CREDENTIALS : containing the response to Oauth request as json string
- COZY_URL : to know what instance is running the konnector
- COZY_FIELDS : as a json string with all the values from the account associated to the konnector. This should correspond to fields defined in the manifest.konnectors with the "fields" attribute.
- `COZY_CREDENTIALS` : containing the response to Oauth request as json string
- `COZY_URL` : to know what instance is running the konnector
- `COZY_FIELDS` : as a json string with all the values from the account associated to the konnector.
- `COZY_PARAMETERS` : optional json string associated with the application, used to parameterize a konnector based on a common set of code.

In the end of the konnector execution (or timeout), the logs are read in the log.txt file and added
to the konnector own log file (in VFS) and the run directory is then destroyed.
Expand Down
1 change: 1 addition & 0 deletions docs/konnectors_workflow_example.md
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ Start the konnector through Rkt, passing as ENV variables :

- `COZY_CREDENTIALS`: security token to communicate with Cozy
- `COZY_FIELDS`: JSON-encoded worker_arguments
- `COZY_PARAMETERS`: JSON-encoded parameters associated with the konnector
- `COZY_TYPE`: the type field of the konnector (eg. "node" etc.)
- `COZY_LOCALE`: the locale of the user (eg. "en" etc.)
- `COZY_URL`: the starting instance URL
Expand Down
15 changes: 10 additions & 5 deletions docs/registry-publish.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Then you can adapt this script as your [`after_deploy` or `after_success`](https

It contains environment variables that you can adapt as your need:
- `COZY_APP_VERSION`: the version string of the deployed version
- `COZY_APP_PARAMETERS`: an optional JSON object (string, object or array) that will parameterize the application on its execution.
- `COZY_BUILD_URL`: the URL of the deployed tarball for your application
- `COZY_BUILD_BRANCH`: the name of the build branch from which the script creates dev releases

Expand All @@ -44,9 +45,8 @@ set -e
# COZY_BUILD_BRANCH: the name of the build branch from which the script
# creates dev releases

if [ -z "${COZY_BUILD_BRANCH}" ]; then
COZY_BUILD_BRANCH="master"
fi
[ -z "${COZY_BUILD_BRANCH}" ] && COZY_BUILD_BRANCH="master"
[ -z "${COZY_APP_PARAMETERS}" ] && COZY_APP_PARAMETERS="null"

if [ "${TRAVIS_PULL_REQUEST}" != "false" ]; then
echo "No deployment: in pull-request"
Expand All @@ -58,6 +58,11 @@ if [ "${TRAVIS_BRANCH}" != "${COZY_BUILD_BRANCH}" ] && [ -z "${TRAVIS_TAG}" ]; t
exit 0
fi

if ! jq <<< "${COZY_APP_PARAMETERS}" > /dev/null; then
printf "Could not parse COZY_APP_PARAMETERS=%s as JSON\n" "${COZY_APP_PARAMETERS}"
exit 1
fi

if [ -z "${COZY_APP_VERSION}" ]; then
if [ -n "${TRAVIS_TAG}" ]; then
COZY_APP_VERSION="${TRAVIS_TAG}"
Expand All @@ -78,12 +83,12 @@ fi

shasum=$(curl -sSL --fail "${COZY_BUILD_URL}" | shasum -a 256 | cut -d" " -f1)

printf 'Publishing version "%s" from "%s" (%s)\n' "${COZY_APP_VERSION}" "${COZY_BUILD_URL}" "${shasum}"
printf 'Publishing version "%s" from "%s" (%s)\n' "${COZY_APP_VERSION}" "${COZY_BUILD_URL}\n" "${shasum}"

curl -sS --fail -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Token ${REGISTRY_TOKEN}" \
-d "{\"version\": \"${COZY_APP_VERSION}\", \"url\": \"${COZY_BUILD_URL}\", \"sha256\": \"${shasum}\"}" \
-d "{\"version\": \"${COZY_APP_VERSION}\", \"url\": \"${COZY_BUILD_URL}\", \"sha256\": \"${shasum}\", \"parameters\": ${COZY_APP_PARAMETERS}}" \
"https://registry.cozy.io/registry/versions"
```

Expand Down
1 change: 1 addition & 0 deletions pkg/apps/konnector.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type KonnManifest struct {
DefaultLocale string `json:"default_locale"`
Locales Locales `json:"locales"`

Parameters json.RawMessage `json:"parameters"`
DocVersion string `json:"version"`
License string `json:"license"`
DocPermissions permissions.Set `json:"permissions"`
Expand Down
6 changes: 6 additions & 0 deletions pkg/workers/exec/konnector.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,19 @@ func (w *konnectorWorker) PrepareCmdEnv(i *instance.Instance, m *jobs.Message) (
return
}

paramsJSON, err := json.Marshal(w.man.Parameters)
if err != nil {
return
}

token := i.BuildKonnectorToken(w.man)

cmd = config.GetConfig().Konnectors.Cmd
env = []string{
"COZY_URL=" + i.PageURL("/", nil),
"COZY_CREDENTIALS=" + token,
"COZY_FIELDS=" + string(fieldsJSON),
"COZY_PARAMETERS=" + string(paramsJSON),
"COZY_TYPE=" + w.man.Type,
"COZY_LOCALE=" + i.Locale,
"COZY_JOB_ID=" + jobID,
Expand Down
2 changes: 2 additions & 0 deletions scripts/konnector-nsjail-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ nsjail \
--log "nsjail-${log_name}.log" \
-E "COZY_URL=${COZY_URL}" \
-E "COZY_FIELDS=${COZY_FIELDS}" \
-E "COZY_PARAMETERS=${COZY_PARAMETERS}" \
-E "COZY_CREDENTIALS=${COZY_CREDENTIALS}" \
-E "COZY_LOCALE=${COZY_LOCALE}" \
-R "${rundir}:/usr/src/konnector/" \
Expand Down Expand Up @@ -146,6 +147,7 @@ nsjail \
# --seccomp_string "${seccomp_string}" \
# -E "COZY_URL=${COZY_URL}" \
# -E "COZY_FIELDS=${COZY_FIELDS}" \
# -E "COZY_PARAMETERS=${COZY_PARAMETERS}" \
# -E "COZY_CREDENTIALS=${COZY_CREDENTIALS}" \
# -E "COZY_LOCALE=${COZY_LOCALE}" \
# -R "${rundir}:/usr/src/konnector/" \
Expand Down
1 change: 1 addition & 0 deletions scripts/konnector-rkt-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ node_image="$(dirname ${0})/nodeslim.aci"

echo "COZY_URL=${COZY_URL}" > "${env_file}"
echo "COZY_FIELDS=${COZY_FIELDS}" >> "${env_file}"
echo "COZY_PARAMETERS=${COZY_PARAMETERS}" >> "${env_file}"
echo "COZY_CREDENTIALS=${COZY_CREDENTIALS}" >> "${env_file}"
echo "COZY_LOCALE=${COZY_LOCALE}" >> "${env_file}"

Expand Down

0 comments on commit f44b6b5

Please sign in to comment.