schedrestd

module
v0.0.0-...-b5a3e81 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 18, 2024 License: ISC

README

RESTFUL API Daemon for HPC scheduler

Provide RESTFUL interface to run HPC scheduler commands

Build

It requires golang and make.

Run "make" to build the binary schedrestd.

Deploy

make install
systemctl enable schedrestd
systemctl start schedrestd

This will install schedrestd to /usr/sbin, schedrestd.yaml to /etc/schedrestd, and install the service

API Document

After the schedrestd service is running, in a browser, access the document at http://IP_ADDR:8088/sa/v1/swagger/index.html

Configuration

By default, the servide listens to the port of 8088 on HTTP. The file /etc/scheddrestd/schedrestd.yaml allows changing some configurations like adding SSL certificates, changing port, and etc. Refer to the file comment area for the description of each parameter.

After modifying the configuration file, restart the service is required.

systemctl restart schedrestd
Configuration parameters in /etc/schedrestd/schedrest.yaml
  • ssl: 1 = Enable, 0 = Disable (default)
  • http_port: Speficying listening port, if ssl = 0. The default value is 8088
  • https_port: Specifying listening port in HTTPS, if ssl = 1. The default value is 8043.
  • cert: SSL cert file path. The default is: /opt/cert/server.crt
  • key: SSL cert key path. The default is: /opt/cert/server.key
  • timeout: The token valid duration in minute. The default value is 30. User can change this value upon individual login.
  • log_level: Log level in /var/log/schedrestd.log.hostname. The default is "info".
  • web_url_path: Any prefix path in front of /sa/v1

Example

The example code is in the directory of test.

  1. Login to generate a token
#!/usr/bin/python3
import requests, getpass, json, sys

baseurl = 'http://localhost:8088/sa/v1/'

if len(sys.argv) < 2:
    print("Usage:", sys.argv[0], "username")
    sys.exit(1)

username = sys.argv[1]

try:
    # obtain user password
    password = getpass.getpass(prompt="Password: ")
except Exception as error:
    print('ERROR', error)
    sys.exit(1)

# call API to generate a token that is valid for 120 minutes
reply = requests.post(baseurl + 'login', json = {'username':username, 'password':password, 'duration':120})
res = json.loads(reply.text)
if not 'data' in res:
    print(res["msg"],"")
    sys.exit(1)

# print token
print(res["data"]["token"]["token"])
  1. Run a command
#!/usr/bin/python3
import request, json, sys

baseurl = 'http://localhost:8088/sa/v1/'

if len(sys.argv) < 3:
    print("Usage:", sys.argv[0], "token", "command ...")
    sys.exit(1)

token = sys.argv[1]
command = ' '.join(sys.argv[2:])

headers = {'Authorization': 'Bearer ' + token}

# specify command, current working directory for the command to run (optional),
# and environment variables (optional):
inputvar = {'command':command,
            'cwd':'/var/tmp',
            'envs':['aaa=aaa',
                    'bbb=bbb']
           }

reply = requests.post(baseurl + 'cmd/run', json = inputvar, headers=headers)

res = json.loads(reply.text)

if res['data'] == None:
    print(res['msg'], "")
    sys.exit(1)

print(res['data']['Output'] + res['data']['Error'], end='')

Directories

Path Synopsis
src
github.com/Azure/go-ntlmssp
Package ntlmssp provides NTLM/Negotiate authentication over HTTP
Package ntlmssp provides NTLM/Negotiate authentication over HTTP
github.com/KyleBanks/depth
Package depth provides the ability to traverse and retrieve Go source code dependencies in the form of internal and external packages.
Package depth provides the ability to traverse and retrieve Go source code dependencies in the form of internal and external packages.
github.com/PuerkitoBio/purell
Package purell offers URL normalization as described on the wikipedia page: http://en.wikipedia.org/wiki/URL_normalization
Package purell offers URL normalization as described on the wikipedia page: http://en.wikipedia.org/wiki/URL_normalization
github.com/PuerkitoBio/urlesc
Package urlesc implements query escaping as per RFC 3986.
Package urlesc implements query escaping as per RFC 3986.
github.com/Sirupsen/logrus
Package logrus is a structured logger for Go, completely API compatible with the standard library logger.
Package logrus is a structured logger for Go, completely API compatible with the standard library logger.
github.com/boltdb/bolt
Package bolt implements a low-level key/value store in pure Go.
Package bolt implements a low-level key/value store in pure Go.
github.com/davecgh/go-spew/spew
Package spew implements a deep pretty printer for Go data structures to aid in debugging.
Package spew implements a deep pretty printer for Go data structures to aid in debugging.
github.com/dgrijalva/jwt-go
Package jwt is a Go implementation of JSON Web Tokens: http://self-issued.info/docs/draft-jones-json-web-token.html
Package jwt is a Go implementation of JSON Web Tokens: http://self-issued.info/docs/draft-jones-json-web-token.html
github.com/dgrijalva/jwt-go/cmd/jwt
A useful example app.
A useful example app.
github.com/dgrijalva/jwt-go/request
Utility package for extracting JWT tokens from HTTP requests.
Utility package for extracting JWT tokens from HTTP requests.
github.com/golang/glog
Package glog implements logging analogous to the Google-internal C++ INFO/ERROR/V setup.
Package glog implements logging analogous to the Google-internal C++ INFO/ERROR/V setup.
github.com/golang/protobuf/proto
Package proto converts data structures to and from the wire format of protocol buffers.
Package proto converts data structures to and from the wire format of protocol buffers.
github.com/kardianos/osext
Extensions to the standard "os" package.
Extensions to the standard "os" package.
github.com/pkg/errors
Package errors provides simple error handling primitives.
Package errors provides simple error handling primitives.
github.com/pmezard/go-difflib/difflib
Package difflib is a partial port of Python difflib module.
Package difflib is a partial port of Python difflib module.
github.com/robfig/cron
Package cron implements a cron spec parser and job runner.
Package cron implements a cron spec parser and job runner.
github.com/satori/go.uuid
Package uuid provides implementation of Universally Unique Identifier (UUID).
Package uuid provides implementation of Universally Unique Identifier (UUID).
golang.org/x/crypto/md4
Package md4 implements the MD4 hash algorithm as defined in RFC 1320.
Package md4 implements the MD4 hash algorithm as defined in RFC 1320.
golang.org/x/crypto/sha3
Package sha3 implements the SHA-3 fixed-output-length hash functions and the SHAKE variable-output-length hash functions defined by FIPS-202.
Package sha3 implements the SHA-3 fixed-output-length hash functions and the SHAKE variable-output-length hash functions defined by FIPS-202.
golang.org/x/crypto/ssh/terminal
Package terminal provides support functions for dealing with terminals, as commonly found on UNIX systems.
Package terminal provides support functions for dealing with terminals, as commonly found on UNIX systems.
golang.org/x/sys/execabs
Package execabs is a drop-in replacement for os/exec that requires PATH lookups to find absolute paths.
Package execabs is a drop-in replacement for os/exec that requires PATH lookups to find absolute paths.
golang.org/x/sys/unix
Package unix contains an interface to the low-level operating system primitives.
Package unix contains an interface to the low-level operating system primitives.
gopkg.in/gopkg.in/ini.v1
Package ini provides INI file read and write functionality in Go.
Package ini provides INI file read and write functionality in Go.
gopkg.in/gopkg.in/natefinch/lumberjack.v2
Package lumberjack provides a rolling logger.
Package lumberjack provides a rolling logger.
gopkg.in/gopkg.in/urfave/cli.v1
Package cli provides a minimal framework for creating and organizing command line Go applications.
Package cli provides a minimal framework for creating and organizing command line Go applications.
gopkg.in/gopkg.in/urfave/cli.v2
Package cli provides a minimal framework for creating and organizing command line Go applications.
Package cli provides a minimal framework for creating and organizing command line Go applications.
gopkg.in/ini.v1
Package ini provides INI file read and write functionality in Go.
Package ini provides INI file read and write functionality in Go.
gopkg.in/natefinch/lumberjack.v2
Package lumberjack provides a rolling logger.
Package lumberjack provides a rolling logger.
gopkg.in/urfave/cli.v1
Package cli provides a minimal framework for creating and organizing command line Go applications.
Package cli provides a minimal framework for creating and organizing command line Go applications.
gopkg.in/urfave/cli.v2
Package cli provides a minimal framework for creating and organizing command line Go applications.
Package cli provides a minimal framework for creating and organizing command line Go applications.
schedrestd/docs
Package docs GENERATED BY THE COMMAND ABOVE; DO NOT EDIT This file was generated by swaggo/swag
Package docs GENERATED BY THE COMMAND ABOVE; DO NOT EDIT This file was generated by swaggo/swag

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL