utils

package
v0.0.0-...-556965f Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2025 License: GPL-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultPage Set default page to 1
	DefaultPage int64 = 1
	// DefaultLimit Set default max limit to 20
	DefaultLimit int64 = 20
)

Functions

func Converter

func Converter(input models.LicenseJson) models.LicenseDB

The Converter function takes an input of type models.LicenseJson and converts it into a corresponding models.LicenseDB object. It performs several field assignments and transformations to create the LicenseDB object, including generating the SpdxId based on the SpdxCompatible field. The resulting LicenseDB object is returned as the output of this function.

func GenerateDiffForReplacingLicenses

func GenerateDiffForReplacingLicenses(obligation *models.Obligation, newLicenseAssociations []string, removeLicenses, insertLicenses *[]string)

GenerateDiffForReplacingLicenses creates list of license associations to be created and deleted such that the list of currently associated licenses to a obligation is overwritten by the list provided in the param newLicenseAssociations

func GetAuditEntity

func GetAuditEntity(c *gin.Context, audit *models.Audit) error

GetAuditEntity is an utility function to fetch obligation or license associated with an audit

func GetKid

func GetKid(token string) (string, error)

https://github.com/lestrrat-go/jwx/discussions/547 Get kid field value from JWS Header

func HashPassword

func HashPassword(user *models.User) error

HashPassword hashes the password of the user using bcrypt. It also trims the username and escapes the HTML characters.

func ParseIdToInt

func ParseIdToInt(c *gin.Context, id string, idType string) (int64, error)

ParseIdToInt convert the string ID from gin.Context to an integer and throw error if conversion fails. Also, update the gin.Context with REST API error.

func PerformObligationMapActions

func PerformObligationMapActions(username string, obligation *models.Obligation,
	removeLicenses, insertLicenses []string) ([]string, []error)

PerformObligationMapActions created associations for licenses in insertLicenses and deletes associations for licenses in removeLicenses. It also calculates changelog for the changes. It returns the final list of associated licenses.

func Populatedb

func Populatedb(datafile string)

Populatedb populates the database with license data from a JSON file.

func PreparePaginateResponse

func PreparePaginateResponse(c *gin.Context, query *gorm.DB,
	responseModel interface{}) models.PaginationInput

PreparePaginateResponse prepares the pagination response for the API. It gets the count of total rows and sets the pagination parameters, also updates the query limit and offset and update the "paginationMeta" and "responseModel" in gin.Context for middleware to process.

func VerifyPassword

func VerifyPassword(inputPassword, dbPassword string) error

VerifyPassword compares the input password with the password stored in the database. Returns nil on success, or an error on failure.

Types

type LicenseImportStatusCode

type LicenseImportStatusCode int

LicenseImportStatusCode is internally used for checking status of a license import

const (
	IMPORT_FAILED LicenseImportStatusCode = iota + 1
	IMPORT_LICENSE_CREATED
	IMPORT_LICENSE_UPDATED
	IMPORT_LICENSE_UPDATED_EXCEPT_TEXT
)

Status codes covering various scenarios that can occur on a license import

Jump to

Keyboard shortcuts

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