Swyctl Reference Guide

Vladimir Porokhov

Installing Swyctl for Mac

Aside from using the swifty.dashboard web panel, you can also manage Swifty with the swyctl command-line tool that lets you do even more.

The swyctl CLI tool is available for Mac via brew. It will be available for Linux later. Install it as follows:

# brew tap swiftycloud/swyctl
# brew install swyctl

Now you can use swyctl. To update swyctl in a future please do:

# brew update swyctl

Installing Swyctl for Linux

To install swyctl on Ubuntu or CentOS please do the following:

# wget https://raw.githubusercontent.com/swiftycloud/swyctl/master/swyctl
# chmod +x swyctl
# mv swyctl /usr/local/bin/swyctl

It is ready!

Quick Login

To login as user you need to use the following command:

# swyctl login user:pass@gate:port
Example for swifty.cloud:
# swyctl login youremail@gmail.com:password@api.swifty.cloud:443
Example for Rusonyx serverless cloud:
# swyctl login youremail@gmail.com:password@swifty-gw.rusonyx.ru:443

Using Swyctl

A typical swyctl command looks like this:

# swyctl <op> <args> [-<option> <value> ...]

where <op> (operation) specifies an object and an action to perform on it. Objects are (f)unctions, (m)iddleware, (d)eployments, (r)epos, (a)ccounts, and (e)vents. Actions are (l)ist, (a)dd, (d)elete, (u)pdate (modify), (i)nfo, and other, which can be longer than one letter.

When run without arguments, swyctl prints a complete list of supported operations, arguments, and options.

The following sections list commands that you may need the most.

Looking Around

Identify the current user:

# swyctl me
user@gate:8686 (http)

Show supported languages and pre-installed packages:

# swyctl lng
ruby
version: ruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-linux]
packages:
bigdecimal (default: 1.3.4)
bson (4.3.0)
bundler (1.17.1, default: 1.16.6)

Show supported mwares:

# swyctl mt
maria
mongo
authjwt 

Working with Functions

Add a function:

# swyctl fa <name> -src <path-to-file>

List functions:

# swyctl fl
ID                              NAME                STATE
5b3e3bcffd65c307ee564f6b        foo                 ready
5b57535dfd65c37ce175da12        bar                 starting

Print information about a specific function. Either by name, e.g., foo:

# swyctl fi foo
Lang:        python
Version:     1 (1)
State:       ready
...

Or by ID:

# swyctl fi :<id>

The important fields are version and state.

Version is the sequence number typically bumped on source updates. The one or more numbers in braces indicate the currently running version. If it is smaller than the number before the braces, it means the function is being updated.

States can be ready, starting, or stalled. The latter means that there is a problem that prevents a function from running. To find out the reason, check the function logs and/or fix the source code (see further).

The :<ID> notation applies to all operations on functions described further.

Remove a function:

# swyctl fd foo

Update function sources:

# swyctl fu foo -src <path-to-file>

Note that the gate does not check that the file (i.e. sources) actually differs from what is currently running.

Add an URL trigger or (e)vent for a function:

# swyctl ea foo <trigger-name> <URL>

Print triggers and information about them:

# swyctl el foo
5b6a643efd65c36eb9828da0                 <name>   url

# swyctl ei foo <name>
Name:          <name>
Source:        url
URL:           gate:8686/call/b4ee91f0a97615906a44420d311a2d8317867678022b42f824b6a36a9f09715f

The same URL is shown in function information as well:

# swyctl fi foo
...
URL:         gate:8686/call/b4...5f
...

Check how the function works. Either with a query:

# curl gate:8686/call/b4...5f?<args>

Or with a body:

# curl -H 'Content-Type: text/plain' -d <body> gate:8686/call/b4...5f
# curl -H 'Content-Type: application/json' -d @<file-with-body> gate:8686/call/b4...5f

Or with an exact method:

# curl -X <method> gate:8686/call/b4...5f

Add additional language-specific packages to functions

We already installed the most popular packages for supported languages, but if you need your own packages you can add them.

Add a package:

# swyctl pka <language> <package-name>

Installing a package is done with language-specific package management tool:

– python: pip
– golang: go get
– node: npm

List packages (this command list only packages installed by user!):

# swyctl pkl <language>

This will show not only installed packages, but also all the deps that were
brought by the install procedure

Remove a package:

# swyctl pkd <language> <package>

This may or may not remove dependencies, depending on the language package management tool.

See stats about packages:

# swyctl pks

This will show some stats about packages, mainly the disk usage. The installed packages are ready to use in functions as they all get added to the language-specific PATH-s.

Working with Middleware (e.g., MongoDB)

Add middleware:

# swyctl ma <name> <type>

List middleware:

# swyctl ml
ID                              NAME                TYPE
5b50a1d6fd65c37b42265d64        x                   mongo
5b50a1d9fd65c37b42265d65        y                   maria

Print information about middleware:

# swyctl mi x
Name:         x
Type:         mongo
Disk usage:   0 bytes

The :<ID> notation applies to middleware as well:

# swyctl mi :5b50a1d6fd65c37b42265d64

Attach middleware to a function by updating the function:

# swyctl fu foo -mw +x

Detach middleware from a function by updating the function:

# swyctl fu foo -mw -x

Attached middleware is also listed in function information:

# swyctl fi foo
...
Mware:
x mongo     (id:5b50a1d6fd65c37b42265d64)

Working with Accounts (GitHub)

Add an account. Either by name:

# swyctl aa github -name <name>

Or by personal access token (name will be resolved automatically):

# swyctl aa github -token <value>

List accounts:

# swyctl al
ID                              TYPE
5b684455fd65c3123a244380        github

Print information about an account. Use ID as there are no name for accounts:

# swyctl ai 5b684455fd65c3123a244380
Type:          github
GitHub name:   <name>
GitHub token:  2a79fc...

Remove an account:

# swyctl ad 5b684455fd65c3123a244380

Working with Repositories

Only GitHub is currently supported.

Add a repo by URL:

# swyctl ra https://github.com/xemul/repo.git

Add a repo that is private to the account, so cloning is only possible with PAT:

# swyctl ra https://github.com/xemul/privrepo.git -acc 5b684455fd65c3123a244380

List all repos accessible by the current user:

# swyctl rl
ID                              TYPE    STATE       URL
5b4ca23afd65c34a68c47e90        github  ready       https://github.com/xemul/repo.git
5b4d687efd65c30b73407196        github* ready       https://github.com/xemul/priv-repo.git
                                github  unattached  https://github.com/xemul/random-repo.git

The presence of ID and the state ready mean that the repo is cloned and functions can be created for it. An asterisk near the github type means the repo has an account associated with it.

If no ID is present and the state is unattached, the repo is just found on user’s account and can be attached with the ra operation.

List attached repos:

# swyctl rl -at true
ID                              TYPE    STATE       URL
5b4ca23afd65c34a68c47e90        github  ready       https://github.com/xemul/repo.git
5b4d687efd65c30b73407196        github* ready       https://github.com/xemul/priv-repo.git

List unattached repos:

# swyctl rl -at false
ID                              TYPE    STATE       URL
                                github  unattached  https://github.com/xemul/random-repo.git

Print repo contents:

# swyctl rl <ID>
.gitignore ()
.swifty.yml ()
README.md ()
functions/fn.py (python)
functions/fn.go (golang)

Pretty-print repo contents:

# swyctl rl <ID> -pretty tree
.gitignore ()
.swifty.yml ()
README.md ()
functions
  fn.py (python)
  fn.go (golang)

Print repo contents descriptions if .swifty.yml exists:

# swyctl rl <ID> -pretty desc
Some demo functions
Hello world: Golang hello-world example
    functions/fn.go (golang)
Hello world: Python hello-world example
    functions/fn.py (python)

Authentication as a Service

Enable authentication:

# swyctl auth on

Disable authorization:

# swyctl auth off

See authentication status. Since AaaS is a deployment, run

# swyctl dl
ID                              NAME                
5b5b080efd65c3714310b76f        simple_auth          (3 items) auth
# swyctl di simple_auth
State:        ready
Items:
        simple_auth_um: function, ready
        simple_auth_jwt: mware, ready
        simple_auth_mgo: mware, ready

Note that the same components can be accessed with fi and mi operations.

Authorize a function:

# swyctl fu foo -auth simple_auth_jwt

Logging w/o SSL and as Administrator

Login over HTTP instead of default HTTPS:

# swyctl login user:pass@gate:port -tls no

Login and simultaneously configure admd:

# swyctl login user:pass@gate:port -admd admd:port

Login directly to a gate/admd, bypassing NGINX proxy:

# swyctl login user:pass@gate:port -proxy no

When logged in as admin, you can perform all actions described in the next sections for any other user. You can do this by either setting a user once:

# swyctl me for another-user

Or by specifying a username in each command with the -for option:

# swyctl <op> <args> [-<option> <value> ...] -for another-user

The name of another user, as well as some runtime data, is stored in the ~/.swifty.conf file.

Share this post

Share on facebook
Share on twitter
Share on email
Share on print