libs

package
v1.0.12 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfigRoute

func ConfigRoute(c echo.Context) error

The function returns a JSON response containing default roles and group mappings from a configuration file.

func Decrypt

func Decrypt(ctx context.Context, encryptedString string, keyString string) (decryptedString string)

Decrypt decrypts a previously encrypted string using the same key used to encrypt it. It takes in an encrypted string and a key string as parameters and returns the decrypted string. The key must be in hexadecimal format.

func Encrypt

func Encrypt(ctx context.Context, stringToEncrypt string, keyString string) (encryptedString string)

Encrypt encrypts a string using AES-GCM algorithm with a given key. The key should be provided as a hexadecimal string. It returns the encrypted string in hexadecimal format.

func GenerateKey

func GenerateKey(ctx context.Context) (string, error)

The function generates a random 32 byte key for AES-256 encryption and returns it as a hexadecimal encoded string.

func GenerateTemporaryUserPassword

func GenerateTemporaryUserPassword(ctx context.Context) (string, error)

The function generates a temporary user password that is 32 characters long with a mix of digits, symbols, and upper/lower case letters, disallowing repeat characters.

func GetUserRoles

func GetUserRoles(ctx context.Context, userGroups []string) []string

The function retrieves user roles based on their group mappings or default roles if no mappings are found.

func HandleSecretKey added in v1.0.6

func HandleSecretKey(ctx context.Context) error

The function generates and sets a secret key if one is not provided or generates and prints a secret key if the "generateKey" flag is set to true.

func HealthRoute

func HealthRoute(c echo.Context) error

The function returns a JSON response with a "OK" status for a health route in a Go application.

func InitConfiguration added in v1.0.6

func InitConfiguration() error

This function initializes the configuration for an application using flags, environment variables, and a YAML configuration file.

func MainRoute

func MainRoute(c echo.Context) error

This function handles the main route of a web application, authenticating users and caching their encrypted passwords.

func UpsertUser

func UpsertUser(ctx context.Context, username string, elasticsearchUser ElasticsearchUser) error

The function UpsertUser sends a POST request to Elasticsearch to create or update a user with the given username and user details.

func WebserverInit added in v1.0.6

func WebserverInit(ctx context.Context)

WebserverInit initializes the webserver and sets up all the routes. It configures the server based on settings from the viper configuration library. It also adds support for metrics if enabled with the `enable_metrics` flag. Lastly, it starts the server on the `listen` address specified in the configuration.

Types

type ElasticsearchConnectionDetails

type ElasticsearchConnectionDetails struct {
	URL      string
	Username string
	Password string
}

The type `ElasticsearchConnectionDetails` contains URL, username, and password information for connecting to Elasticsearch. @property {string} URL - The URL property is a string that represents the endpoint of the Elasticsearch cluster that the application will connect to. It typically includes the protocol (http or https), the hostname or IP address of the Elasticsearch server, and the port number. @property {string} Username - The `Username` property is a string that represents the username used to authenticate the connection to an Elasticsearch instance. @property {string} Password - The `Password` property is a string that stores the password required to authenticate and establish a connection to an Elasticsearch instance. This property is typically used in conjunction with the `Username` property to provide secure access to the Elasticsearch cluster.

type ElasticsearchUser

type ElasticsearchUser struct {
	Enabled  bool                      `json:"enabled"`
	Email    string                    `json:"email"`
	Password string                    `json:"password"`
	Metadata ElasticsearchUserMetadata `json:"metadata"`
	FullName string                    `json:"full_name"`
	Roles    []string                  `json:"roles"`
}

The ElasticsearchUser type represents a user in Elasticsearch with properties such as email, password, metadata, full name, and roles. @property {bool} Enabled - A boolean value indicating whether the Elasticsearch user is enabled or disabled. @property {string} Email - The email address of the Elasticsearch user. @property {string} Password - The "Password" property is a string that represents the password of an Elasticsearch user. It is used to authenticate the user when they try to access Elasticsearch resources. It is important to keep this property secure and encrypted to prevent unauthorized access to Elasticsearch data. @property {ElasticsearchUserMetadata} Metadata - Metadata is a property of the ElasticsearchUser struct that contains additional information about the user. It is of type ElasticsearchUserMetadata, which is likely another struct that contains specific metadata properties such as creation date, last login time, etc. The purpose of this property is to provide additional context and information about the @property {string} FullName - The FullName property is a string that represents the full name of an Elasticsearch user. It is one of the properties of the ElasticsearchUser struct. @property {[]string} Roles - Roles is a property of the ElasticsearchUser struct that represents the list of roles assigned to the user. Roles are used to define the level of access and permissions a user has within the Elasticsearch system. For example, a user with the "admin" role may have full access to all Elasticsearch features, while

type ElasticsearchUserMetadata

type ElasticsearchUserMetadata struct {
	Groups []string `json:"groups"`
}

The type `ElasticsearchUserMetadata` contains a field `Groups` which is a slice of strings representing user groups. @property {[]string} Groups - The `Groups` property is a slice of strings that represents the groups that a user belongs to in Elasticsearch. This metadata can be used to control access to specific resources or features within Elasticsearch based on a user's group membership.

type ErrorResponse

type ErrorResponse struct {
	Message string `json:"message"`
	Code    int    `json:"code"`
}

The type `ErrorResponse` is a struct that contains a message and code for error responses in Go. @property {string} Message - Message is a string property that represents the error message that will be returned in the response when an error occurs. @property {int} Code - The `Code` property is an integer that represents an error code. It is used to identify the type of error that occurred. For example, a code of 404 might indicate that a requested resource was not found, while a code of 500 might indicate a server error.

type HealthResponse

type HealthResponse struct {
	Status string `json:"status"`
}

The HealthResponse type is a struct in Go that contains a single field called Status, which is a string that will be represented as "status" in JSON. @property {string} Status - The `Status` property is a string field that represents the status of a health response. It is tagged with `json:"status"` which indicates that when this struct is serialized to JSON, the field name will be "status".

Jump to

Keyboard shortcuts

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