License as a service provides a convenient and effective way for organizations to manage their use of open-source licenses. With the growing popularity of open-source software, organizations are finding it more difficult to keep track of the various licenses and terms under which they are permitted to use open-source components. Open-source licenses can be complicated, making it difficult to understand how they apply to a specific piece of software or interact with other licenses. It can be used for various purposes by organizations and tools like FOSSology and SW360 like license identification, filtering, and managing licenses. There are benefits of this service such as increasing flexibility, a faster time-to-access, and managing the database.
Licensedb database has licenses, obligations, obligation map, users, their audits and changes.
- license_dbs table has list of licenses and all the data related to the licenses.
- obligations table has the list of obligations that are related to the licenses.
- obligation_maps table that maps obligations to their respective licenses.
- users table has the user that are associated with the licenses.
- audits table has the data of audits that are done in obligations or licenses
- change_logs table has all the change history of a particular audit.
There are multiple API endpoints for licenses, obligations, user and audit endpoints.
Check the OpenAPI documentation for the API endpoints at cmd/laas/docs/swagger.yaml.
The same can be viewed by Swagger UI plugin after installing and running the tool at http://localhost:8080/swagger/index.html.
To get the access token, send a POST request to /api/v1/login
with the
username and password.
curl -X POST "http://localhost:8080/api/v1/login" \
-H "accept: application/json" -H "Content-Type: application/json" \
-d "{ \"username\": \"<username>\", \"password\": \"<password>\"}"
As the response of the request, a JWT will be returned. Use this JWT with the
Authorization
header (as -H "Authorization: <JWT>"
) to access endpoints
requiring authentication.
Please install and set-up Golang on your system in advance.
- Clone this Project and Navigate to the folder.
git clone https://github.com/fossology/LicenseDb.git
cd LicenseDb
- Create the
external_ref_fields.yaml
file in the root directory of the project and change the values of the extra license json keys as per your requirement.
cp external_ref_fields.example.yaml external_ref_fields.yaml
vim external_ref_fields.yaml
- Generate Go struct for the extra fields listed in the external_ref_fields.yaml.
go generate ./...
- Build the project using following command.
go build ./cmd/laas
- Create the
.env
file in the root directory of the project and change the values of the environment variables as per your requirement.
cp .env.example .env
vim .env
- Run the executable.
./laas
- You can directly run it by the following command.
go run ./cmd/laas
Connect to the database using psql
with the following command.
psql -h localhost -p 5432 -U fossy -d fossology
Run the following query to create the first user.
INSERT INTO users (username, userpassword, userlevel) VALUES ('<username>', '<password>', 'admin');
- Install swag using the following command.
go install github.com/swaggo/swag/cmd/swag@latest
- Run the following command to generate swagger documentation.
swag init --parseDependency --generalInfo api.go --dir ./pkg/api,./pkg/auth,./pkg/db,./pkg/models,./pkg/utils --output ./cmd/laas/docs
- Swagger documentation will be generated in
./cmd/laas/docs
folder. - Run the project and navigate to
http://localhost:8080/swagger/index.html
to view the documentation. - Optionally, after changing any documentation comments, format them with following command.
swag fmt --generalInfo ./pkg/api/api.go --dir ./pkg/api,./pkg/auth,./pkg/db,./pkg/models,./pkg/utils