i2Rest Advanced Setup

From i2Rest
Revision as of 12:50, 15 June 2020 by Alexei.baranov (talk | contribs) (i2Rest Gates)
Jump to: navigation, search

This section describes the advanced configuration options of i2Rest Server. To configure, the file in the JSON format is used, the settings reference is here

i2Rest Gates

i2Rest Gate is the endpoint where the server listens for incoming requests. The server uses up to three endpoints to process requests from clients, administrators/managers and sessions. Configuration file can contain up to three gate objects to setup these endpoints. If the configuration does not contain a setting for some gate, then the default setting is used - file: protocol at temporary location.
Detailed description of all available configuration options for gates is here

i2Rest Gates protocols

http

This is a common protocol, without encryption. You can use this protocol in a fully secure network environment. Example:

"gates":
   {
      ...
      "main": {"url":"http://192.168.1.123:5678", ...},
      ...
   },

https

To protect the connections, use the https protocol. i2Rest Server uses standard IBM i GSK API to protect connections. All required parameters are configured using DCM, see detailed guide. Example:

"gates":
   {
      ...
      "main": {"url":"https://192.168.1.123:5678", "dcm_server_id":"MYSERVER", ...},
      ...
   },

file

When your i2Rest Server instance and its clients both located on the same IBM i server, it is reasonable to use file: protocol. For example, you can use this protocol for management gate, to perform management functions using local i2Rest Client. i2Rest Server is able to listen incoming requests at some unix socket defined as a file at IFS. In this case, the server will not be accessible externally. i2Rest Server uses temporary file: endpoints when it can't find configuration for some gate. Temporary file: endpoints are created at /tmp folder, for example /tmp/AS5WRD7DCJ. Example:

"gates":
   {
      ...
      "session": {"url":"file:///tmp/session_gate", ...},
      ...
   },

i2Rest Sessions

Ссылка или дублирование "что такое session system".
Ссылка на reference настройки
Упомянуть о сессиях на другой IBM i и на другой платформе
Привести примеры настройки сессий

  • Обычные сессии (*LOCAL)
  • Анонимные сессии (*ANONYMOUS)
  • Варианты обычных сессий (system_XXX) - для задания особых параметров запуска, например логирования, запуск в выделенной подсистеме и прочее
  • Запуск сессии на удаленной машине (SBMRMTJOB)

Настройка API

  • Используем PCML, дать ссылку на что такое PCML, какие особенности PCML в i2Rest
  • Примеры PCML
  • Примеры расширенных PCML, включая тег openapi30

Настройка параметров доступа OAuth2

Модели настройки доступа

Стандартная и custom модель, стандартная - бесплатная. Custom - позволяет настраивать собственные правила или справочники для пользователей, клиентов и токенов.

Стандартная модель

users

clients

scopes

tokens

Custom access model

User exits для реализации custom модели

Standard UI pages


Take a look on how the minimal i2Rest configuration might look like.

{
   "gates":
   {
      "main"       : {"url":"http://i2rest.com:22088"},
      "management" : {"url":"http://192.168.0.233:8080"},
      "session"    : {"url":"http://192.168.0.233:8888"}
   },
   "session_systems":
   [
         {"name": "*LOCAL",     "submit":"SBMJOB JOB(I2RESTS) USER(${user}) CMD(CALL JPCML/I2REST PARM('-session' '-url' '${surl}' '-uid' '${uid}' 
          '-user' '${user}' '-init' 'ADDLIBLE JPCML' '-dcm_client_id' 'MYCLIENT')) INLLIBL(KAPBASELIB QGPL)"},
         {"name": "*ANONYMOUS", "submit":"SBMJOB JOB(I2RESTA) USER(${user}) CMD(CALL JPCML/I2REST PARM('-session' '-url' '${surl}' '-uid' '${uid}' 
          '-user' '${user}' '-init' 'ADDLIBLE JPCML' '-dcm_client_id' 'MYCLIENT')) INLLIBL(KAPBASELIB QGPL)"},
   ],
}

According to I2Rest Configuration Object description just two i2Rest Configuration Object fields are mandotary: gates object and main, manager and session gates object. With only this two configured fields we already can run a server instance, but still can't get much use of it. Most valuable i2Rest Server applications - the run_program API and the run_command API requires some more stuff:

run_command API requires Oauth2 object;
run_program API generally requires PCML object to be set up, but Oauth2 object also is mandotary for programs which has "valid_in_anonymous":false flag in PCML.

So the setting that allows to call IBM i program as a web service might look like as follows:

"pcmls":
   [
      {"pcml_mount":"echo",     "pcml_file":"pcml/echo.pcml", "valid_in_anonymous":true},
   ],

Not too dificult, isn't it? Much more complex Oauth2 object example below:


   "OAuth2":
   {
      "scopes": {"run_program"          : {"description":"Run *PGM and *SRVPGM"}, 
                 "run_command"          : {"description":"Run CL command"},
                 "system_BTC7"          : {"description":"Execute API on BTC7"},
                 "management_functions" : {"description":"Invoke i2Rest manager APIs"}},
      "clients":
      {
         "OAUTH21":{"redirect_uri":"http://api.i2rest.com:22088/oauth2/redirect", 
                    "description":"Test client", 
                    "valid_scopes":["run_program", "run_command", "management_functions", "system_BTC7"],
                    "valid_grant_types":["authorization_code", "urn:ietf:params:oauth:grant-type:device_code", "refresh_token", "client_credentials"]}
      },
      "users":
      {
         "BTAB":{"description":"Alexei Baranov", "valid_clients":{"OAUTH21":{"scopes":["run_program", "run_command", "management_functions", "system_BTC7"]}}},
         "BTPL":{"description":"Pavel Lobko",    "valid_clients":{"OAUTH21":{"scopes":["run_program", "run_command", "management_functions", "system_BTC7"]}}}
      },
      "tokens": {"type":"token"},"refresh_tokens":{"type":"refresh_token"},"codes":{"type":"code"},"device_codes":{"type":"user_code"},

      "login_page"            : "/pages/Login/index.html",
      "decision_page"         : "/pages/user_decide.html",
      "bad_auth_page"         : "/pages/bad_auth.html",
      "enter_code_page"       : "/pages/enter_code.html",
      "device_connected_page" : "/pages/device_connected.html"
   }