Skip to content

The titan User Service

The titan User Service can be reached via a REST API that serves under the port number HOST:9000.

UseCaseDiagram

Building/ running

To run the service simply use go run ./cmd/user

or to create an exe go build ./cmd/user

It features the following command line arguments:

Name Options (default) Purpose
port (8085) Port on which the User Service serves
log-level info/debug/warning/error Log level
(info)
log-to-kafka (false) Flag: use kafka hook for logging
kafka (10.14.0.23:9092) host:port of kafka broker
service-topic (titan.servicelogs) kafka topic for logs
config-file (internal/app/user/config.yaml) Configuration file
smtp-user Auth for SMTP server
smtp-password Auth for SMTP server
smtp-address SMTP address for establish connection
smtp-port SMTP port
email-from (no-reply@industrial-devops.org) default from-email when sending an email
smtp-enable (false) For development env we do not want to send email. In production need to set this to true
api-base-path (https://titan.industrial-devops.org/apis/) Path where EndpointProvider serves configurable APIs

The default configuration file contains the following items:

Name Type Doc (default value) Constraints
database string URL of the Database (127.0.0.1:27017)
allowed-origins list List of allowed origins for CORS request [not null]
user-manager string URL of the User Service (http://127.0.0.1:9000)
service-ids list of strings no default set, add id of EndpointProvider, Flowmanager
service-id string no default set, set id
flowmanager string host:port of FlowManager (localhost:9002)

Generally, all settings listed above can be done also via environment variables, whereby the variables are composed of a prefix (TITAN_UM) and the argument using snake case:

TITAN_UM_ARGUMENT, e.g. TITAN_UM_LOG_LEVEL

Usage

Generally, all queries to the User Service are formulated by sending a json object with the fields :

{
  "username": "UserName",
  "email": "Email",
  "password": "Password"
}

UserWithPassword

structure of a user object with password

Items:

Name Type Doc Constraints
Username string user name [not null]
Email string email [not null]
Password string password [not null]
IsAdmin boolean flag: admin rights
IsAllowedToUpload boolean flag: package upload rights

User

structure of a user object

Items:

Name Type Doc Constraints
Username string username [not null]
Email string email [not null]
IsAdmin boolean flag: admin rights
IsAllowedToUpload boolean flag: package upload rights

ChangePassword

structure of a change password request body

Items:

Name Type Doc Constraints
User UserWithPassword UserWithPassword [not null]
OldPassword string old_password [not null]

APIS

Signup

To sign up, need the JSON object UserWithPassword, IsAdmin, IsAllowedToSignup will be ignored

API functions

/userservice/signup Type: POST or PUT

Response

If successful, the response header will contain a token and User object.

To sign up, need the JSON object UserWithPassword

API functions

/userservice/signup?id=<token> Type: POST or PUT

Response

If successful, the response header will contain a token and User object.

Login

To Login, need the JSON object UserWithPassword

API functions

/userservice/login Type: POST or PUT

Response

If successful, the response header will contain a token.

Logout

To Logout a user

API functions

/userservice/logout Type: GET

Response

If successful, the response header will contain a expired cookie that has empty token.

Authentication

To authentication a user need to send the cookie that contain a token

API functions

/userservice/authentication Type: GET

Response

If successful, the response StatusOk in HTTP and list of Users

IsAdmin

To authorize a user need to send the cookie that contain a token

API functions

/userservice/isadmin Type: GET

Response

If successful, the response StatusOk in HTTP and 'true' in body

Get Users

To get all users as Type User. You need admin role for this end point

API functions

/userservice/users Type: GET

Response

If successful, the response StatusOk in HTTP and list of Users

Delete user

Users can only delete themselfs, despite admins, who are also allowed to delete users.

API functions

/userservice/users/<id string> Type: DELETE

Request data

UserWithPassword objects password as JSON need to send in body.

Response

If successful, the response StatusOk in HTTP

Update user

Users can only update themselves

API functions

/userservice/users/<id string> Type: PUT

Request data

UserWithPassword objects in body as JSON type.

Response

If successful, the response StatusOk in HTTP

Change Passwords

Admin can use this API to change the other user passwords. User can change password for his own account.

ChangePassword as JSON need to send in body.

API functions

/userservice/changepassword Type: PUT

Response

If successful, the response StatusOk.

Get platform configuration

API functions

/userservice/platformConfig Type: GET

Response

If successful, the response StatusOk in HTTP and the Platform configuration as a json object .

Update platform configuration

API functions

/userservice/platformConfig Type: PUT

Send an updated platform configuration as a json object.

Response

If successful, the response StatusOk in HTTP and the platform configuration as a json object .

API functions

/userservice/invite?email=<email> Type: POST

Response

If successful, the response StatusOk in HTTP and the invitation as a json object .

Set administrator rights for a user

This endpoint provides the facility to set or unset a user adminstrator rights.

This endpoint is only accessibly by a user that is already an Admin in the system.

API functions

/userservice/users/{id:string}/rights/admin Type: PUT (make admin) /userservice/users/{id:string}/rights/admin Type: DELETE (remove admin rights)

Request data

No data needs to be sent

Response

If successful, the response StatusOk in HTTP

Allow user to upload brick packages

Using this endpoint, admins can allow a user to upload brick packages.

API functions

/userservice/users/{id:string}/rights/upload Type: PUT (allow to upload) /userservice/users/{id:string}/rights/upload Type: DELETE (remove upload rights)

Request data

No data needs to be sent.

Response

If successful, the response StatusOk in HTTP

Get User

To get a specific user as a subset of Type User.

API functions

/userservice/users/<id string> Type: GET

Response

If successful, the response StatusOk in HTTP a user object containing the ID and username of the user

Example:

{
  id: "443bafdf-f98c-11ea-a835-98fa9b446af4"
  username: "this_is_a_username"
}

Get user information from an email address

To get a specific user as a subset of Type User.

API functions

/userservice/user/email/<email> Type: GET

Response

If successful, the response StatusOk in HTTP a user object containing the ID, email, and username of the user. Only titan services can access this endpoint.

Example:

{
  id: "443bafdf-f98c-11ea-a835-98fa9b446af4"
  username: "this_is_a_username"
  email: "some Email adress"
}

Send email to a user

Send an email to a registered user.

API functions

/userservice/user/<id: string>/email Type: POST

Request

Send email with subject, sections. Example:

{
  subject: "notification from titan platform"
  sections: ["Be notified about smth",
   "Click on a button "]
}

Response

If successful, the response StatusOk is sent.

Send message to all users

Send a particular message to all registered users.

API functions

/userservice/user/<id: string>/sendtoall Type: PUT

Request

Send email with subject, message. Example:

{
  subject: "notification from titan platform"
  message: "#Any Markdown Text"
}

Response

If successful, the response StatusOk is sent.

Signup Request

Before signing up we need to verify the email address. This request sends the appropriate email to the user.

API functions

/userservice/signupRequest?email=<email string> Type: POST

Response

If successful the response will contain a Status: Ok in the HTTP header and a success message in the body. If unsuccessful the response will contain a Status: InternalServerError in the HTTP header.

Example for a successful response in the body:

verification_email_sent

Verify the signup link and get the email address for continue the signup process

API functions

/userservice/signupRequest?token=<token string> Type: GET

Response

If successful, the response is Status: Ok in HTTP header and the email address that user want to signup with in the body. If unsuccessful the response will contain a Status: InternalServerError in the HTTP header.

Example for a successful response in the body:

user@domain.com

Request Reset Password

For resetting user account password, generate a link with token and send it to user email address

API functions

/userservice/resetpassword?email=<email string> Type: GET

Response

If successful, the response Status: Ok in HTTP

Reset Password

After validating a reset password link, read the new password from the request body and save it to the user service DB.

JSON need to send in body.

{
  "password": "new password"
}

API functions

/userservice/resetpassword?id=<id string> Type: POST

Response

If successful, the response Status: Ok in HTTP

Get User with service key

To get a specific user as a subset of Type User.

API functions

/userservice/user/<id string> Type: GET

Response

If successful, the response StatusOk in HTTP and User object

API functions

/userservice/users/changeEmail/<token> Type: POST

Response

If successful, the response is Status: Ok in HTTP header. If unsuccessful the response will contain a Status: InternalServerError in the HTTP header.