Using_Parameter_file - moh-hassan/odata2poco GitHub Wiki
Using Parameter file (configuration File)
A. How the configuration File Work
You can automate the execution of o2pgen by specifying a configuration file when you start O2pgen. The configuration file is a text file with extension ".txt" or any extension you want. O2pgen uses the values contained in the configuration file to provide the options of the arguments of the commandLine.
B- Running o2pgen Using a configuration File
Now, you are ready to run at the command line, specifying the configuration file you created. For help information about the full set of these options, run the command with the help option, for example:
> o2pgen --help
To run o2pgen using a configuration file named myconfig.txt, prefix the file name with @:
REM Don't include extra parametrs when you call the configuration file.
O2pgen @path/to/myconfig.txt
the File may be relative or absolute one.
If you specify a relative path to the configuration file, it will be relative to the current working directory.
The following rules are applied to the configuration file:
- Every line may contain one or more option. The Comment lines are started with # and it will be ignored. The empty lines will be ignored.
- Option values can be Environment variables based on the standard of the operating system. On windows, it is contained between % %, e.g
%TOKEN%
and case insensetive. In Linux/Mack Os it prefixed by $, e.g$TOKEN
. It read based on OS. - If the option value is ? for password, o2pgen read value from keyboard. e.g
-p ?
- If the option value is preceded by
@@
. The value will be read from file on disk. For example a token is stored in file namedpath/to/token.txt
. This help in reading tokens stored in files. Also you can include external file by@@fileName
which may be shared betwwen different configuration files. - The sequence options (multi values), can be written in multi lines, like:
# attributes -a can be one line: key,req,json or be written in multilines
-a key
req
json
- Configuration file can include other configuration file using the command
#include myconfig2.txt
You can create different configuration files per service and use the required one as needed.
c- The default configuration file
If you run o2pgen without any parameter and the current directory include file named o2pgen.txt
, it will be used as a configuration file.
Example1:
The next configuration file config1.txt, contains environment variables in windows with comments and empty lines.
#-------Odata Service
#for development test
#-r https://localhost/odata
# for production
-r https://services.odata.org/V4/OData/OData.svc
--auth oauth2
# environment var: client_id
-u %client_id%
-p %client_secret%
--token-endpoint https://MtTokenServer.us.com/oauth/token
--token-params "audience=https://www.todo.com"
-v
To use:
o2pgen @config1.txt
Example 2:
The file config2.txt, read password from keyboard.
-r https://services.odata.org/V4/OData/OData.svc
--auth basic
-u user1
# read password from keyboard
-p ?
To use:
o2pgen @config2.txt
Example 3:
The file config3.txt, read token from file.
-r https://services.odata.org/V4/OData/OData.svc
--auth token
# read password from keyboard
-p @@path/to/mytoken.txt
Example 4:
The file config3.txt, read token from file.
-r https://services.odata.org/V4/OData/OData.svc
--auth none
# new feature, to pass header to httpClient
# authentication read token from environment var
--http-header "Authorization=Bearer %token%"
key1=123
key2=abc
Accept=application/json
Exampl 5:
This example show how to include file that has common options in the configuration file.
The file header.txt
has a shared options used with other configuration files
a) Create a text file named header.txt
with the contents:
# file: header.txt
-H "Authorization=Bearer %token%"
-H key1=123
-H key2=abc
-H Accept=application/json
b) Create the main configuration file named config5.txt
that refer to the previous file header.txt
#File: config5.txt
#--url http://localhost/odata
-r https://services.odata.org/TripPinRESTierService
# attribute list in multi lines
-a key
req
json
#include the shared file header.txt (relative or absolute path)
#include header.txt
To use
o2pgen @config5.txt
Now config5.txt contain all the parameters of both files.
Reading value of any option in the commandLine from file
If you use tte --auth token
to connect with oData service, you can pass the file containing the token using a prefix @@
like @@path/to/token.txt
.
Example
-r http://myservice.com -auth token -p @@tripToken.txt
The above exampl use the file tripToken.txt which contain the token.
Reading password from keyboard and Encrypted
To enter the password for o2pgen, use a single dash - or question mark ? as a placeholder. When prompted for the password, o2pgen will read characters from the console and mask them with asterisks for security.
example
?
as placeHolder
use -u user1 -p ?
OR use single dash -
as PlaceHolder
-u user1 -p -
After displaying the message Enter password:
on the screen, o2pgen waits for the user to enter the password using the keyboard, one character at a time. For security, the password is displayed on the screen as *****.
Once the password is entered, o2pgen stores the encrypted password in a secured container. When the password is needed, o2pgen decrypts it and then overwrites the contents of the password with zeros to ensure that it cannot be accessed from memory.