Go API Documentation

github.com/semaphoreui/semaphore/api

No package summary is available.

Package

Files: 13. Third party imports: 10. Imports from organisation: 0. Tests: 0. Benchmarks: 0.

Vars

Types

LoginAuthMethods

This type doesn't have documentation.

Field name Field type Comment
Totp

*LoginTotpAuthMethod

No comment on field.

LoginTotpAuthMethod

This type doesn't have documentation.

Field name Field type Comment
AllowRecovery

bool

No comment on field.

claimResult

This type doesn't have documentation.

Field name Field type Comment
username

string

No comment on field.
name

string

No comment on field.
email

string

No comment on field.

loginMetadata

This type doesn't have documentation.

Field name Field type Comment
OidcProviders

[]loginMetadataOidcProvider

No comment on field.
LoginWithPassword

bool

No comment on field.
AuthMethods

LoginAuthMethods

No comment on field.

loginMetadataOidcProvider

This type doesn't have documentation.

Field name Field type Comment
ID

string

No comment on field.
Name

string

No comment on field.
Color

string

No comment on field.
Icon

string

No comment on field.

minimalUser

This type doesn't have documentation.

Field name Field type Comment
ID

int

No comment on field.
Username

string

No comment on field.
Name

string

No comment on field.

runnerWithToken

This type doesn't have documentation.

Field name Field type Comment

db.Runner

No comment on field.
Token

string

No comment on field.
PrivateKey

string

No comment on field.

totpRecoveryRequestBody

This type doesn't have documentation.

Field name Field type Comment
RecoveryCode

string

No comment on field.

totpRequestBody

This type doesn't have documentation.

Field name Field type Comment
Passcode

string

No comment on field.

Functions

func DelayMiddleware

DelayMiddleware adds artificial delay to simulate slow network conditions

Uses: http.Handler, http.HandlerFunc, http.Request, http.ResponseWriter, time.Sleep.

func Extract

Uses: db.IntegrationBodyDataJSON, db.IntegrationBodyDataString, db.IntegrationExtractBodyValue, db.IntegrationExtractHeaderValue, fmt.Sprintf.

func ExtractAsAnyForTaskParams

Uses: db.IntegrationBodyDataJSON, db.IntegrationBodyDataString, db.IntegrationExtractBodyValue, db.IntegrationExtractHeaderValue, db.MapStringAnyField.

func JSONMiddleware

JSONMiddleware ensures that all the routes respond with Json, this is added by default to all routes

Uses: http.HandlerFunc, http.Request, http.ResponseWriter.

func Match

Uses: db.IntegrationBodyDataJSON, db.IntegrationBodyDataString, db.IntegrationMatchBody, db.IntegrationMatchHeader.

func MatchCompare

Uses: conv.ConvertFloatToIntIfPossible, db.IntegrationMatchMethodContains, db.IntegrationMatchMethodEquals, db.IntegrationMatchMethodUnEquals, fmt.Sprintf, strings.Contains.

func ReceiveIntegration

Uses: db.FillIntegration, db.IntegrationAliasSingle, db.IntegrationAuthBasic, db.IntegrationAuthBitbucket, db.IntegrationAuthGitHub, db.IntegrationAuthHmac, db.IntegrationAuthNone, db.IntegrationAuthToken, db.IntegrationMatcher, db.Project, db.RetrieveQueryParams, fmt.Sprintf, helpers.GetStrParam, helpers.Store, http.StatusNoContent, io.ReadAll, log.Error, log.Fields, log.Info, log.WithFields.

func Route

Route declares all routes

Uses: db.CanManageProjectResources, db.CanManageProjectUsers, db.CanRunProjectTasks, db.CanUpdateProject, debug.Dump, debug.GC, http.HandlerFunc, log.Fields, log.WithError, mux.CORSMethodMiddleware, mux.NewRouter, os.Getenv, projects.AddEnvironment, projects.AddIntegration, projects.AddIntegrationAlias, projects.AddIntegrationExtractValue, projects.AddIntegrationMatcher, projects.AddInventory, projects.AddKey, projects.AddProject, projects.AddRepository, projects.AddRunner, projects.AddSchedule, projects.AddTask, projects.AddTemplate, projects.AddTerraformInventoryAlias, projects.AddUser, projects.AddView, projects.AttachInventory, projects.ClearCache, projects.ClearRunnerCache, projects.ConfirmTask, projects.DeleteIntegration, projects.DeleteIntegrationExtractValue, projects.DeleteIntegrationMatcher, projects.DeleteProject, projects.DeleteRunner, projects.DeleteTerraformInventoryAlias, projects.DeleteTerraformInventoryState, projects.DetachInventory, projects.EnvironmentMiddleware, projects.GetAllTasks, projects.GetAnsibleTaskErrors, projects.GetAnsibleTaskHosts, projects.GetBackup, projects.GetEnvironment, projects.GetEnvironmentRefs, projects.GetIntegration, projects.GetIntegrationAlias, projects.GetIntegrationExtractValue, projects.GetIntegrationExtractValueRefs, projects.GetIntegrationExtractValues, projects.GetIntegrationMatcher, projects.GetIntegrationMatcherRefs, projects.GetIntegrationMatchers, projects.GetIntegrationRefs, projects.GetIntegrations, projects.GetInventory, projects.GetInventoryRefs, projects.GetKeyRefs, projects.GetKeys, projects.GetLastTasks, projects.GetMustCanMiddleware, projects.GetProject, projects.GetProjectSchedules, projects.GetProjects, projects.GetRepositories, projects.GetRepositoryBranches, projects.GetRepositoryRefs, projects.GetRunner, projects.GetRunnerTags, projects.GetRunners, projects.GetSchedule, projects.GetTask, projects.GetTaskMiddleware, projects.GetTaskOutput, projects.GetTaskRawOutput, projects.GetTaskStages, projects.GetTaskStats, projects.GetTemplate, projects.GetTemplateRefs, projects.GetTemplateSchedules, projects.GetTemplates, projects.GetTerraformInventoryAlias, projects.GetTerraformInventoryAliases, projects.GetTerraformInventoryLatestState, projects.GetTerraformInventoryState, projects.GetTerraformInventoryStates, projects.GetUserRole, projects.GetUsers, projects.GetViewTemplates, projects.GetViews, projects.IntegrationMiddleware, projects.InventoryMiddleware, projects.KeyMiddleware, projects.LeftProject, projects.ProjectMiddleware, projects.RejectTask, projects.RemoveEnvironment, projects.RemoveIntegrationAlias, projects.RemoveInventory, projects.RemoveKey, projects.RemoveRepository, projects.RemoveSchedule, projects.RemoveTask, projects.RemoveTemplate, projects.RemoveUser, projects.RemoveView, projects.RepositoryMiddleware, projects.Restore, projects.RunnerMiddleware, projects.SchedulesMiddleware, projects.SetRunnerActive, projects.SetScheduleActive, projects.SetTemplateInventory, projects.SetTerraformInventoryAliasAccessKey, projects.SetViewPositions, projects.StopTask, projects.TemplatesMiddleware, projects.UpdateEnvironment, projects.UpdateIntegration, projects.UpdateIntegrationExtractValue, projects.UpdateIntegrationMatcher, projects.UpdateInventory, projects.UpdateKey, projects.UpdateProject, projects.UpdateRepository, projects.UpdateRunner, projects.UpdateSchedule, projects.UpdateTemplate, projects.UpdateTemplateDescription, projects.UpdateUser, projects.UpdateView, projects.UserMiddleware, projects.ValidateScheduleCronFormat, projects.ViewMiddleware, runners.GetRunner, runners.RegisterRunner, runners.RunnerMiddleware, runners.UnregisterRunner, runners.UpdateRunner, sockets.Handler, strings.HasSuffix, tasks.DeleteTask, tasks.GetTasks, tasks.TaskMiddleware, time.ParseDuration, util.Config, util.WebHostURL.

func RunIntegration

Uses: db.IntegrationExtractValue, db.IntegrationVariableEnvironment, db.IntegrationVariableTaskParam, db.RetrieveQueryParams, db.Task, fmt.Sprintf, helpers.Store, helpers.TaskPool, json.Marshal, log.Error, log.Info.

func StoreMiddleware

StoreMiddleware WTF?

Uses: db.StoreSession, helpers.Store, http.HandlerFunc, http.Request, http.ResponseWriter, util.RandString.

func TerraformInventoryAliasMiddleware

Uses: http.HandlerFunc, http.Request, http.ResponseWriter.

Private functions

func addGlobalRunner

References: bufio.NewWriter, bytes.Buffer, db.Runner, helpers.Bind, helpers.Store, helpers.WriteError, helpers.WriteJSON, http.StatusBadRequest, http.StatusCreated, log.Warn, util.GeneratePrivateKey.

func addTerraformState

References: http.StatusNotFound.

func addUser

References: context.Get, db.User, db.UserWithPwd, helpers.Bind, helpers.Store, helpers.WriteJSON, http.StatusBadRequest, http.StatusCreated, http.StatusUnauthorized, log.Warn.

func adminMiddleware

References: context.Get, db.User, http.HandlerFunc, http.Request, http.ResponseWriter, http.StatusForbidden.

func appMiddleware

References: context.Set, helpers.GetStrParam, helpers.WriteErrorStatus, http.HandlerFunc, http.Request, http.ResponseWriter, http.StatusBadRequest.

func authentication

nolint: gocyclo

References: http.HandlerFunc, http.Request, http.ResponseWriter.

func authenticationHandler

References: context.Set, db.ErrNotFound, errors.Is, helpers.Store, helpers.WriteErrorStatus, http.StatusUnauthorized, log.Error, strings.Contains, strings.Replace, strings.ToLower.

func authenticationWithStore

nolint: gocyclo

References: db.StoreSession, helpers.Store, http.HandlerFunc, http.Request, http.ResponseWriter.

func claimOidcToken

func claimOidcUserInfo

func clearCache

References: context.Get, db.User, helpers.WriteJSON, http.StatusForbidden, http.StatusInternalServerError, http.StatusNoContent, log.Error, util.Config.

func clearGlobalRunnerCache

References: context.Get, db.Runner, helpers.Store, helpers.WriteError, http.StatusNoContent.

func convertEntryToMap

func createAPIToken

References: base64.URLEncoding, context.Get, db.APIToken, db.User, helpers.Store, helpers.WriteJSON, http.StatusCreated, io.ReadFull, rand.Reader, strings.ToLower.

func createSession

createSession creates session for passed user and stores session details in cookies.

References: db.Session, db.SessionVerificationMethod, db.SessionVerificationNone, db.SessionVerificationTotp, helpers.Store, helpers.WriteErrorStatus, http.Cookie, http.SetCookie, http.StatusInternalServerError, log.Error, tz.Now, util.Config, util.Cookie.

func debugPrintRoutes

References: fmt.Println, mux.Route, mux.Router, strings.Join.

func deleteAPIToken

References: context.Get, db.User, helpers.Store, helpers.WriteError, http.StatusNoContent, mux.Vars.

func deleteApp

References: context.Get, db.ErrNotFound, errors.Is, helpers.Store, helpers.WriteErrorStatus, http.StatusInternalServerError, http.StatusNoContent, util.Config.

func deleteGlobalRunner

References: context.Get, db.Runner, helpers.Store, helpers.WriteErrorStatus, http.StatusBadRequest, http.StatusNoContent.

func deleteUser

References: context.Get, db.User, helpers.Store, http.StatusInternalServerError, http.StatusNoContent, http.StatusUnauthorized, log.Warn.

func disableTotp

References: context.Get, db.User, helpers.GetIntParam, helpers.Store, helpers.WriteError, helpers.WriteErrorStatus, http.StatusBadRequest, http.StatusNoContent.

func enableTotp

References: context.Get, db.User, helpers.Store, helpers.WriteError, helpers.WriteErrorStatus, helpers.WriteJSON, http.Error, http.StatusBadRequest, http.StatusInternalServerError, http.StatusOK, totp.Generate, totp.GenerateOpts, util.Config, util.GenerateRecoveryCode.

func generateStateOauthCookie

References: base64.URLEncoding, http.Cookie, http.SetCookie, rand.Read, time.Hour, tz.Now.

func getAPITokens

References: context.Get, db.User, helpers.Store, helpers.WriteJSON, http.StatusInternalServerError, http.StatusOK.

func getAllEvents

func getAllRunners

References: db.Runner, helpers.Store, helpers.WriteJSON, http.StatusOK.

func getApp

References: context.Get, helpers.WriteErrorStatus, helpers.WriteJSON, http.StatusNotFound, http.StatusOK, util.Config.

func getApps

References: helpers.WriteJSON, http.StatusOK, sort.Slice, util.App, util.Config.

func getEvents

nolint: gocyclo

References: context.Get, context.GetOk, db.Event, db.Project, db.RetrieveQueryParams, db.User, helpers.Store, helpers.WriteError, helpers.WriteJSON, http.StatusOK.

func getGlobalRunner

References: context.Get, db.Runner, helpers.WriteJSON, http.StatusOK.

func getLastEvents

func getOidcProvider

References: fmt.Errorf, oauth2.Config, oidc.NewProvider, oidc.ProviderConfig, strings.HasPrefix, strings.TrimRight, url.JoinPath, url.Parse, util.Config.

func getOptions

References: context.Get, db.RetrieveQueryParams, db.User, helpers.Store, helpers.WriteJSON, http.StatusForbidden, http.StatusInternalServerError, http.StatusOK.

func getRandomProfileName

func getRandomUsername

References: random.String.

func getSecretFromFile

References: os.ReadFile.

func getSession

References: helpers.Store, log.Error, time.Since, util.Cookie.

func getSystemInfo

References: helpers.WriteJSON, http.StatusOK, util.AnsibleVersion, util.Config, util.GetPublicHost, util.Version.

func getTerraformState

References: http.StatusNotFound.

func getUser

References: context.Get, context.GetOk, db.User, helpers.WriteJSON, http.StatusOK, util.Config.

func getUserMiddleware

References: context.Get, context.Set, db.User, helpers.GetIntParam, helpers.Store, helpers.WriteError, http.HandlerFunc, http.Request, http.ResponseWriter, http.StatusUnauthorized, log.Warn.

func getUsers

References: context.Get, db.RetrieveQueryParams, db.User, helpers.Store, helpers.WriteJSON, http.StatusOK.

func globalRunnerMiddleware

References: context.Set, helpers.GetIntParam, helpers.Store, helpers.WriteJSON, http.HandlerFunc, http.Request, http.ResponseWriter, http.StatusBadRequest, http.StatusNotFound.

func hmacHashPayload

hmacHashPayload computes the hash of payload's body according to the webhook's secret token see https://developer.github.com/webhooks/securing/#validating-payloads-from-github returning the hash as a hexadecimal string

References: fmt.Sprintf, hmac.New, sha256.New.

func isValidHmacPayload

isValidHmacPayload checks if the GitHub payload's hash fits with the hash computed by GitHub sent as a header

References: hmac.Equal, strings.HasPrefix.

func lockTerraformState

References: http.StatusNotFound.

func login

nolint: gocyclo

References: db.ErrNotFound, db.User, db.ValidationError, errors.As, errors.Is, helpers.Bind, helpers.Store, helpers.WriteJSON, http.StatusInternalServerError, http.StatusNoContent, http.StatusOK, http.StatusUnauthorized, log.Error, log.Warn, sort.Slice, strings.ToLower, util.Config.

func loginByLDAP

References: db.ErrNotFound, errors.Is.

func loginByPassword

References: bcrypt.CompareHashAndPassword, db.ErrNotFound.

func logout

logout handles the user logout process by expiring the current session and clearing the session cookie.

Behavior:

  • If a valid session exists, it is expired in the database.
  • The session cookie is cleared by setting its value to an empty string and its expiration date to a past time.

Responses:

  • 204 No Content: Logout successful.
  • 500 Internal Server Error: An error occurred while expiring the session.

References: helpers.Store, http.Cookie, http.SetCookie, http.StatusInternalServerError, http.StatusNoContent, log.Error, time.Hour, tz.Now.

func oidcLogin

References: context.Background, http.Redirect, http.StatusTemporaryRedirect, log.Error, mux.Vars, url.JoinPath, util.Config.

func oidcRedirect

References: context.Background, db.User, fmt.Errorf, helpers.Store, http.Redirect, http.StatusTemporaryRedirect, log.Error, mux.Vars, oauth2.StaticTokenSource, oidc.Config, oidc.IDToken, oidc.UserInfo, url.JoinPath, util.Config.

func parseClaim

References: bytes.NewBufferString, strings.Contains, strings.Split, strings.TrimSpace, template.New.

func parseClaims

References: fmt.Errorf.

func plainTextMiddleware

plainTextMiddleware resets headers to Plain Text if needed

References: http.HandlerFunc, http.Request, http.ResponseWriter.

func pongHandler

func prepareClaims

func readonlyUserMiddleware

References: context.Get, context.Set, db.User, helpers.GetIntParam, helpers.Store, helpers.WriteError, http.HandlerFunc, http.Request, http.ResponseWriter.

func recoverySession

recoverySession handles the recovery of a user session using a recovery code. It validates the recovery code provided by the user and, if valid, verifies the session. If the recovery code is invalid or recovery is not allowed, it returns an appropriate HTTP status code.

HTTP Request:

  • Method: POST
  • Body: JSON object containing the recovery code (e.g., {"recovery_code": "code"}).

Responses:

  • 204 No Content: Recovery successful, session verified.
  • 400 Bad Request: Invalid request body or user does not have TOTP enabled.
  • 401 Unauthorized: Invalid recovery code or session not found.
  • 403 Forbidden: TOTP recovery is disabled.
  • 500 Internal Server Error: An unexpected error occurred.

Preconditions:

  • The session must exist and be valid.
  • TOTP recovery must be enabled in the configuration.

Parameters:

  • w: The HTTP response writer.
  • r: The HTTP request.

References: db.SessionVerificationNone, db.SessionVerificationTotp, helpers.Bind, helpers.Store, helpers.WriteErrorStatus, http.StatusBadRequest, http.StatusForbidden, http.StatusInternalServerError, http.StatusNoContent, http.StatusUnauthorized, util.Config, util.VerifyRecoveryCode.

func serveFile

References: bytes.NewReader, fmt.Sprintf, http.Error, http.ServeContent, http.StatusNotFound, http.StatusText, strings.HasSuffix, strings.Replace, time.Hour, util.WebHostURL.

func servePublic

References: http.Error, http.StatusNotFound, http.StatusText, path.Join, strings.Contains, strings.HasPrefix, strings.HasSuffix, strings.Replace, util.WebHostURL.

func setApp

References: context.Get, helpers.Bind, helpers.Store, helpers.WriteErrorStatus, http.StatusInternalServerError, http.StatusNoContent, json.Marshal, reflect.Array, reflect.Slice, reflect.String, reflect.TypeOf, util.App.

func setAppActive

References: context.Get, helpers.Bind, helpers.Store, helpers.WriteErrorStatus, http.StatusBadRequest, http.StatusInternalServerError, http.StatusNoContent.

func setAppOption

References: db.ConvertFlatToNested, fmt.Sprintf, util.AssignMapToStruct, util.Config.

func setGlobalRunnerActive

References: context.Get, db.Runner, helpers.Bind, helpers.Store, helpers.WriteErrorStatus, http.StatusBadRequest, http.StatusNoContent.

func setOption

References: context.Get, db.Option, db.User, helpers.Bind, helpers.Store, helpers.WriteJSON, http.StatusForbidden, http.StatusInternalServerError, http.StatusOK.

func startEmailVerification

References: http.StatusBadRequest.

func structToFlatMap

References: reflect.Array, reflect.Map, reflect.Ptr, reflect.Slice, reflect.Struct, reflect.TypeOf, reflect.ValueOf, strings.Split.

func totpQr

References: bytes.Buffer, context.Get, db.User, helpers.WriteError, helpers.WriteErrorStatus, http.StatusNotFound, otp.NewKeyFromURL, png.Encode.

func tryFindLDAPUser

References: db.User, db.ValidateUser, fmt.Errorf, fmt.Sprintf, json.Marshal, log.Error, log.Info, strings.ToLower, tls.Config, tz.Now, util.Config.

func unlockTerraformState

References: http.StatusNotFound.

func updateGlobalRunner

References: context.Get, db.Runner, helpers.Bind, helpers.Store, helpers.WriteErrorStatus, http.StatusBadRequest, http.StatusNoContent.

func updateUser

References: context.Get, db.User, db.UserWithPwd, helpers.Bind, helpers.Store, http.StatusBadRequest, http.StatusNoContent, http.StatusUnauthorized, log.Error, log.Warn.

func updateUserPassword

References: context.Get, db.User, helpers.Bind, helpers.Store, http.StatusBadRequest, http.StatusInternalServerError, http.StatusNoContent, http.StatusUnauthorized, log.Warn, util.LogWarning.

func validateAppID

func verifySession

References: db.SessionVerificationEmail, db.SessionVerificationNone, db.SessionVerificationTotp, helpers.Bind, helpers.Store, helpers.WriteError, helpers.WriteErrorStatus, http.StatusBadRequest, http.StatusForbidden, http.StatusInternalServerError, http.StatusNoContent, http.StatusUnauthorized, otp.NewKeyFromURL, totp.Validate, util.Config.

func verifySessionByEmail

References: http.StatusBadRequest.


Tests

Files: 4. Third party imports: 0. Imports from organisation: 0. Tests: 8. Benchmarks: 0.

Test functions

TestApiPing

References: http.NewRequest, httptest.NewRecorder, util.Config, util.ConfigType, util.DebuggingConfig.

TestIntegrationMatch

References: db.IntegrationBodyDataJSON, db.IntegrationMatchBody, db.IntegrationMatchMethodEquals, db.IntegrationMatcher, http.Header.

TestParseClaim

TestParseClaim2

TestParseClaim3

TestParseClaim4

TestParseClaim5

TestStructToMap

References: fmt.Println.