Documentation
¶
Overview ¶
Copyright 2019 txn2
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2019 txn2 ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2019 txn2 ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- Constants
- func AccountAccessCheckHandler(checkAdmin bool) gin.HandlerFunc
- func GetAccountMapping(prefix string) es.IndexTemplate
- func GetUserMapping(prefix string) es.IndexTemplate
- func UserHasAccessHandler(c *gin.Context)
- func UserHasAdminAccessHandler(c *gin.Context)
- func UserTokenHandler() gin.HandlerFunc
- type AccessCheck
- type AccessCheckResult
- type AccessKey
- type Account
- type AccountResult
- type AccountSearchResults
- type AccountSearchResultsAck
- type Api
- func (a *Api) AuthUser(auth Auth) (*UserResult, bool, error)
- func (a *Api) AuthUserHandler(c *gin.Context)
- func (a *Api) GetAccount(id string) (int, *AccountResult, error)
- func (a *Api) GetAccountHandler(c *gin.Context)
- func (a *Api) GetUser(id string) (int, *UserResult, error)
- func (a *Api) GetUserHandler(c *gin.Context)
- func (a *Api) PrefixHandler(c *gin.Context)
- func (a *Api) SearchAccounts(searchObj *es.Obj) (int, AccountSearchResults, error)
- func (a *Api) SearchAccountsHandler(c *gin.Context)
- func (a *Api) SearchUsers(searchObj *es.Obj) (int, UserSearchResults, error)
- func (a *Api) SearchUsersHandler(c *gin.Context)
- func (a *Api) SendEsMapping(mapping es.IndexTemplate) error
- func (a *Api) UpsertAccount(account *Account) (int, es.Result, error)
- func (a *Api) UpsertAccountHandler(c *gin.Context)
- func (a *Api) UpsertUser(user *User) (int, es.Result, error)
- func (a *Api) UpsertUserHandler(c *gin.Context)
- type Auth
- type Config
- type User
- type UserResult
- type UserSearchResults
- type UserSearchResultsAck
- type UserTokenResult
Constants ¶
const EncCost = 12
const IdxAccount = "account"
const IdxUser = "user"
const RedactMsg = "REDACTED"
Variables ¶
This section is empty.
Functions ¶
func AccountAccessCheckHandler ¶ added in v0.0.8
func AccountAccessCheckHandler(checkAdmin bool) gin.HandlerFunc
AccountAccessCheckHandler
func UserHasAccessHandler ¶ added in v0.0.6
UserHasAccessHandler
func UserHasAdminAccessHandler ¶ added in v0.0.6
UserHasAdminAccessHandler
Types ¶
type AccessCheck ¶
AccessCheck is used to configure an access check
type AccessCheckResult ¶ added in v0.0.5
type AccessCheckResult struct {
AccessChecked *AccessCheck `json:"access_checked"`
Status bool `json:"status"`
Message string `json:"message"`
}
AccessCheckResult
type AccessKey ¶
type AccessKey struct {
Name string `json:"name"`
Description string `json:"description"`
Key string `json:"key"`
Active bool `json:"active"`
}
AccessKey
type Account ¶
type Account struct {
Id string `json:"id"`
Description string `json:"description"`
DisplayName string `json:"display_name"`
Active bool `json:"active"`
Modules []string `json:"modules"`
OrgId int `json:"org_id"`
AccessKeys []AccessKey `json:"access_keys"`
}
User defines a DCP user object
type AccountResult ¶
AccountResult returned from Elastic
type AccountSearchResults ¶ added in v0.0.2
type AccountSearchResults struct {
es.SearchResults
Hits struct {
Total int `json:"total"`
MaxScore float64 `json:"max_score"`
Hits []AccountResult `json:"hits"`
} `json:"hits"`
}
AccountSearchResults
type AccountSearchResultsAck ¶ added in v0.0.2
type AccountSearchResultsAck struct {
ack.Ack
Payload AccountSearchResults `json:"payload"`
}
AccountSearchResultsAck
type Api ¶
type Api struct {
*Config
}
Api
func (*Api) AuthUser ¶
func (a *Api) AuthUser(auth Auth) (*UserResult, bool, error)
AuthUser authenticates a user with id and password
func (*Api) GetAccount ¶
func (a *Api) GetAccount(id string) (int, *AccountResult, error)
GetAccount
func (*Api) GetAccountHandler ¶
GetAccountHandler gets an account by ID
func (*Api) GetUserHandler ¶
GetUserHandler gets a user by ID
func (*Api) PrefixHandler ¶ added in v0.0.2
PrefixHandler
func (*Api) SearchAccounts ¶ added in v0.0.2
SearchAccounts
func (*Api) SearchAccountsHandler ¶ added in v0.0.2
SearchAccountsHandler
func (*Api) SearchUsers ¶ added in v0.0.2
SearchUsers
func (*Api) SearchUsersHandler ¶ added in v0.0.2
SearchUsersHandler
func (*Api) SendEsMapping ¶
func (a *Api) SendEsMapping(mapping es.IndexTemplate) error
SetupUserIndexTemplate
func (*Api) UpsertAccount ¶
UpsertAccount inserts or updates an account. Elasticsearch treats documents as immutable.
func (*Api) UpsertAccountHandler ¶
UpsertAccountHandler
func (*Api) UpsertUser ¶
UpsertUser inserts or updates a user record. Elasticsearch treats documents as immutable.
type Config ¶
type Config struct {
Logger *zap.Logger
HttpClient *micro.Client
// used for communication with Elasticsearch
// if nil, one will be created
Elastic *es.Client
ElasticServer string
// used to prefix the user and account indexes IdxPrefix_user, IdxPrefix_account
// defaults to system.
IdxPrefix string
// pre-configured from server (txn2/micro)
Token *token.Jwt
}
Config
type User ¶
type User struct {
Id string `json:"id" mapstructure:"id"`
Description string `json:"description" mapstructure:"description"`
DisplayName string `json:"display_name" mapstructure:"display_name"`
Active bool `json:"active" mapstructure:"active"`
Sysop bool `json:"sysop" mapstructure:"sysop"`
Password string `json:"password" mapstructure:"password"`
Sections []string `json:"sections" mapstructure:"sections"`
SectionsAll bool `json:"sections_all" mapstructure:"sections_all"`
Accounts []string `json:"accounts" mapstructure:"accounts"`
AdminAccounts []string `json:"admin_accounts" mapstructure:"admin_accounts"`
}
User defines a user object
func (*User) CheckEncryptPassword ¶
CheckEncryptPassword checks and encrypts the password in the user object.
func (*User) HasAccess ¶
func (u *User) HasAccess(ac *AccessCheck) bool
BasicAccess returns true is user is active and not locked
func (*User) HasBasicAccess ¶
BasicAccess returns true is user is active and not locked
type UserResult ¶
UserResult returned from Elastic
type UserSearchResults ¶ added in v0.0.2
type UserSearchResults struct {
es.SearchResults
Hits struct {
Total int `json:"total"`
MaxScore float64 `json:"max_score"`
Hits []UserResult `json:"hits"`
} `json:"hits"`
}
UserSearchResults
type UserSearchResultsAck ¶ added in v0.0.2
type UserSearchResultsAck struct {
ack.Ack
Payload UserSearchResults `json:"payload"`
}
UserSearchResultsAck
type UserTokenResult ¶ added in v0.0.2
UserTokenResult
