База знаний: Serverless
Swyctl Reference Guide
Опубликовано Денис Завьялов on 21 November 2018 10:23

Installing Swyctl 

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. Install it as follows:

# brew tap swiftycloud/swyctl
# brew install swyctl

Now you can use swyctl.

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.

Logging In and Looking Around 

Login as user:

# swyctl login user:pass@gate:port

Login over HTTP instead of default HTTPS:

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

Login and simultaneously configure admd (for swifty.admin only):

# 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

Identify the current user:

# swyctl me
user@gate:8686 (http)

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.

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 readystarting, 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

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
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 ()
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)

Authorizing as a Service

 Enable authorization:

# swyctl auth on

Disable authorization:

# swyctl auth off

See authorization status. Since AaaS is a deployment, run

# swyctl dl
ID                              NAME                
5b5b080efd65c3714310b76f        simple_auth          (3 items) auth
# swyctl di simple_auth
State:        ready
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


(0 голос(а))
Эта статья помогла
Эта статья не помогла

Коментарии (0)