Documentation ¶
Index ¶
- Constants
- Variables
- func CheckRoles(roles ...string) func(http.Handler) http.Handler
- func ContextWithToken(ctx context.Context, token string) context.Context
- func ContextWithUser(ctx context.Context, user *User) context.Context
- func GetTokenFromContext(ctx context.Context) string
- type Cache
- type CacheClient
- func (c *CacheClient) Authenticate(username string, password string) (string, error)
- func (c *CacheClient) FindAll(token string) ([]*User, error)
- func (c *CacheClient) FindById(token, userId string) (*User, error)
- func (c *CacheClient) Logout(token string) error
- func (c *CacheClient) Me(token string) (*User, error)
- func (c *CacheClient) RevokedTokens(token string) ([]RevokedToken, error)
- type CacheMock
- type Client
- type ClientWithToken
- type ClientWithTokenHolder
- type HttpClient
- func (c *HttpClient) Authenticate(username string, password string) (string, error)
- func (c *HttpClient) FindAll(token string) ([]*User, error)
- func (c *HttpClient) FindById(token, userId string) (*User, error)
- func (c *HttpClient) Logout(token string) error
- func (c *HttpClient) Me(token string) (*User, error)
- func (c *HttpClient) RevokedTokens(token string) ([]RevokedToken, error)
- type HttpRequestBuilder
- type HttpRequestBuilderImpl
- func (rb *HttpRequestBuilderImpl) BuildGetAllRequest(token string) (*http.Request, error)
- func (rb *HttpRequestBuilderImpl) BuildGetRequest(token, userID string) (*http.Request, error)
- func (rb *HttpRequestBuilderImpl) BuildLoginRequest(username string, password string) (*http.Request, error)
- func (rb *HttpRequestBuilderImpl) BuildLogoutRequest(token string) (*http.Request, error)
- func (rb *HttpRequestBuilderImpl) BuildMeRequest(token string) (*http.Request, error)
- func (rb *HttpRequestBuilderImpl) BuildPlatformsRequest(token, userID string) (*http.Request, error)
- func (rb *HttpRequestBuilderImpl) BuildRevokedTokensRequest(token string) (*http.Request, error)
- type HttpRequestBuilderMock
- func (rb *HttpRequestBuilderMock) BuildGetAllRequest(token string) (*http.Request, error)
- func (rb *HttpRequestBuilderMock) BuildGetRequest(token, userID string) (*http.Request, error)
- func (rb *HttpRequestBuilderMock) BuildLoginRequest(username string, password string) (*http.Request, error)
- func (rb *HttpRequestBuilderMock) BuildLogoutRequest(token string) (*http.Request, error)
- func (rb *HttpRequestBuilderMock) BuildMeRequest(token string) (*http.Request, error)
- func (rb *HttpRequestBuilderMock) BuildPlatformsRequest(token, userID string) (*http.Request, error)
- func (rb *HttpRequestBuilderMock) BuildRevokedTokensRequest(token string) (*http.Request, error)
- type InMemoryTokenHolder
- type Message
- type Middleware
- type Platform
- type PubSub
- type RetryConfig
- type RevokedToken
- type StaticTokenHolder
- type TokenHolder
- type User
- type UserClientMock
- func (c *UserClientMock) Authenticate(username string, password string) (string, error)
- func (c *UserClientMock) FindAll(token string) ([]*User, error)
- func (c *UserClientMock) FindById(token, userId string) (*User, error)
- func (c *UserClientMock) Logout(token string) error
- func (c *UserClientMock) Me(token string) (*User, error)
- func (c *UserClientMock) RevokedTokens(token string) ([]RevokedToken, error)
Constants ¶
View Source
const ( RoleAdmin = "Admin" RoleShippingProvider = "ShippingProvider" RolePlatformTransportation = "PlatformTransportation" RolePlatformWarehouse = "PlatformWarehouse" RolePlatformOverview = "PlatformOverview" RoleLocationTree = "LocationTree" RoleAccessAdmin = "AccessAdmin" RoleReturn = "Return" RmsAdmin = "RmsAdmin" RmsReturnOperator = "RmsReturnOperator" RmsCbOperator = "RmsCbOperator" RmsApi = "RmsApi" RoleRmsApplicationAdmin = "RmsApplicationAdmin" RmsCs = "RmsCs" RmsAdminID = "ID_RMS_ADMIN" RmsAdminVN = "VN_RMS_ADMIN" RmsAdminTH = "TH_RMS_ADMIN" RmsAdminSG = "SG_RMS_ADMIN" RmsAdminPH = "PH_RMS_ADMIN" RmsAdminPK = "PK_RMS_ADMIN" RmsAdminBD = "BD_RMS_ADMIN" RmsAdminLK = "LK_RMS_ADMIN" RmsAdminNP = "NP_RMS_ADMIN" RmsAdminMM = "MM_RMS_ADMIN" RmsAdminMY = "MY_RMS_ADMIN" RmsReturnOperatorID = "ID_RMS_RETURN-OPERATOR" RmsReturnOperatorVN = "VN_RMS_RETURN-OPERATOR" RmsReturnOperatorTH = "TH_RMS_RETURN-OPERATOR" RmsReturnOperatorSG = "SG_RMS_RETURN-OPERATOR" RmsReturnOperatorPH = "PH_RMS_RETURN-OPERATOR" RmsReturnOperatorMY = "MY_RMS_RETURN-OPERATOR" RmsReturnOperatorPK = "PK_RMS_RETURN-OPERATOR" RmsReturnOperatorBD = "BD_RMS_RETURN-OPERATOR" RmsReturnOperatorLK = "LK_RMS_RETURN-OPERATOR" RmsReturnOperatorNP = "NP_RMS_RETURN-OPERATOR" RmsReturnOperatorMM = "MM_RMS_RETURN-OPERATOR" RmsCsID = "ID_RMS_CS" RmsCsVN = "VN_RMS_CS" RmsCsTH = "TH_RMS_CS" RmsCsSG = "SG_RMS_CS" RmsCsPH = "PH_RMS_CS" RmsCsMY = "MY_RMS_CS" RmsCsPK = "PK_RMS_CS" RmsCsBD = "BD_RMS_CS" RmsCsLK = "LK_RMS_CS" RmsCsNP = "NP_RMS_CS" RmsCsMM = "MM_RMS_CS" RmsCrossborderOperatorID = "ID_RMS_CROSSBORDER-OPERATOR" RmsCrossborderOperatorVN = "VN_RMS_CROSSBORDER-OPERATOR" RmsCrossborderOperatorTH = "TH_RMS_CROSSBORDER-OPERATOR" RmsCrossborderOperatorSG = "SG_RMS_CROSSBORDER-OPERATOR" RmsCrossborderOperatorPH = "PH_RMS_CROSSBORDER-OPERATOR" RmsCrossborderOperatorMY = "MY_RMS_CROSSBORDER-OPERATOR" RmsCrossborderOperatorPK = "PK_RMS_CROSSBORDER-OPERATOR" RmsCrossborderOperatorBD = "BD_RMS_CROSSBORDER-OPERATOR" RmsCrossborderOperatorLK = "LK_RMS_CROSSBORDER-OPERATOR" RmsCrossborderOperatorNP = "NP_RMS_CROSSBORDER-OPERATOR" RmsCrossborderOperatorMM = "MM_RMS_CROSSBORDER-OPERATOR" )
User roles which should be identical with user-service
View Source
const DEFAULT_TIME_OUT = 10
Variables ¶
View Source
var ( ErrNotFound = errors.New("not found user") ErrMissingToken = errors.New("missing token in response") )
View Source
var DefaultRetryConfig = RetryConfig{
MaxAttempt: defaultMaxAttempt,
WaitTime: defaultWaitTime,
}
Functions ¶
func ContextWithToken ¶
ContextWithToken add user token to context
func ContextWithUser ¶
ContextWithUser add user to context
func GetTokenFromContext ¶
GetTokenFromContext return token from context, empty string if token not exists
Types ¶
type CacheClient ¶
type CacheClient struct {
// contains filtered or unexported fields
}
func NewCacheClient ¶
func NewCacheClient(client Client, cache Cache) *CacheClient
func (*CacheClient) Authenticate ¶
func (c *CacheClient) Authenticate(username string, password string) (string, error)
func (*CacheClient) Logout ¶
func (c *CacheClient) Logout(token string) error
func (*CacheClient) RevokedTokens ¶
func (c *CacheClient) RevokedTokens(token string) ([]RevokedToken, error)
type CacheMock ¶
type ClientWithToken ¶
type ClientWithTokenHolder ¶
type ClientWithTokenHolder struct {
// contains filtered or unexported fields
}
func NewClientWithTokenHolder ¶
func NewClientWithTokenHolder(c Client, h TokenHolder) *ClientWithTokenHolder
func (*ClientWithTokenHolder) FindAll ¶
func (c *ClientWithTokenHolder) FindAll() ([]*User, error)
func (*ClientWithTokenHolder) FindById ¶
func (c *ClientWithTokenHolder) FindById(userId string) (*User, error)
func (*ClientWithTokenHolder) Me ¶
func (c *ClientWithTokenHolder) Me() (*User, error)
func (*ClientWithTokenHolder) RevokedTokens ¶
func (c *ClientWithTokenHolder) RevokedTokens() ([]RevokedToken, error)
type HttpClient ¶
type HttpClient struct {
// contains filtered or unexported fields
}
func New ¶
func New(rb HttpRequestBuilder, hc *http.Client) *HttpClient
func NewDefault ¶
func NewDefault(baseURL string) *HttpClient
func (*HttpClient) Authenticate ¶
func (c *HttpClient) Authenticate(username string, password string) (string, error)
func (*HttpClient) Logout ¶
func (c *HttpClient) Logout(token string) error
func (*HttpClient) RevokedTokens ¶
func (c *HttpClient) RevokedTokens(token string) ([]RevokedToken, error)
type HttpRequestBuilder ¶
type HttpRequestBuilder interface { BuildLoginRequest(username string, password string) (*http.Request, error) BuildMeRequest(token string) (*http.Request, error) BuildPlatformsRequest(token, userID string) (*http.Request, error) BuildLogoutRequest(token string) (*http.Request, error) BuildGetRequest(token, userID string) (*http.Request, error) BuildGetAllRequest(token string) (*http.Request, error) BuildRevokedTokensRequest(token string) (*http.Request, error) }
type HttpRequestBuilderImpl ¶
type HttpRequestBuilderImpl struct {
BaseURL string
}
func (*HttpRequestBuilderImpl) BuildGetAllRequest ¶
func (rb *HttpRequestBuilderImpl) BuildGetAllRequest(token string) (*http.Request, error)
func (*HttpRequestBuilderImpl) BuildGetRequest ¶
func (rb *HttpRequestBuilderImpl) BuildGetRequest(token, userID string) (*http.Request, error)
func (*HttpRequestBuilderImpl) BuildLoginRequest ¶
func (*HttpRequestBuilderImpl) BuildLogoutRequest ¶
func (rb *HttpRequestBuilderImpl) BuildLogoutRequest(token string) (*http.Request, error)
func (*HttpRequestBuilderImpl) BuildMeRequest ¶
func (rb *HttpRequestBuilderImpl) BuildMeRequest(token string) (*http.Request, error)
func (*HttpRequestBuilderImpl) BuildPlatformsRequest ¶
func (rb *HttpRequestBuilderImpl) BuildPlatformsRequest(token, userID string) (*http.Request, error)
func (*HttpRequestBuilderImpl) BuildRevokedTokensRequest ¶
func (rb *HttpRequestBuilderImpl) BuildRevokedTokensRequest(token string) (*http.Request, error)
type HttpRequestBuilderMock ¶
type HttpRequestBuilderMock struct { RequestURL string BuildLoginRequestMock func(username string, password string) (*http.Request, error) BuildMeRequestMock func(token string) (*http.Request, error) BuildPlatformsRequestMock func(token, userID string) (*http.Request, error) BuildLogoutRequestMock func(token string) (*http.Request, error) BuildGetRequestMock func(token, userID string) (*http.Request, error) BuildGetAllRequestMock func(token string) (*http.Request, error) BuildRevokedTokensRequestMock func(token string) (*http.Request, error) }
func (*HttpRequestBuilderMock) BuildGetAllRequest ¶
func (rb *HttpRequestBuilderMock) BuildGetAllRequest(token string) (*http.Request, error)
func (*HttpRequestBuilderMock) BuildGetRequest ¶
func (rb *HttpRequestBuilderMock) BuildGetRequest(token, userID string) (*http.Request, error)
func (*HttpRequestBuilderMock) BuildLoginRequest ¶
func (*HttpRequestBuilderMock) BuildLogoutRequest ¶
func (rb *HttpRequestBuilderMock) BuildLogoutRequest(token string) (*http.Request, error)
func (*HttpRequestBuilderMock) BuildMeRequest ¶
func (rb *HttpRequestBuilderMock) BuildMeRequest(token string) (*http.Request, error)
func (*HttpRequestBuilderMock) BuildPlatformsRequest ¶
func (rb *HttpRequestBuilderMock) BuildPlatformsRequest(token, userID string) (*http.Request, error)
func (*HttpRequestBuilderMock) BuildRevokedTokensRequest ¶
func (rb *HttpRequestBuilderMock) BuildRevokedTokensRequest(token string) (*http.Request, error)
type InMemoryTokenHolder ¶
type InMemoryTokenHolder struct { sync.Mutex Username string Password string // contains filtered or unexported fields }
Use this one for your consumers and other backend tasks this holder will automatically request a new token if the old one expired
func NewInMemoryTokenHolder ¶
func NewInMemoryTokenHolder(username, password string) *InMemoryTokenHolder
func (*InMemoryTokenHolder) GetToken ¶
func (h *InMemoryTokenHolder) GetToken(client Client) (string, error)
func (*InMemoryTokenHolder) Invalidate ¶
func (h *InMemoryTokenHolder) Invalidate()
type Middleware ¶
type Middleware struct {
// contains filtered or unexported fields
}
func NewMiddleware ¶
func NewMiddleware(userServiceClient Client, config RetryConfig) *Middleware
func (*Middleware) SetLogger ¶
func (m *Middleware) SetLogger(l logger)
type PubSub ¶
PubSub allows to subscribe to user service messages It's NOT safe for concurrent use by multiple goroutines.
type RetryConfig ¶
type RevokedToken ¶
func (*RevokedToken) TTL ¶
func (t *RevokedToken) TTL() time.Duration
type StaticTokenHolder ¶
type StaticTokenHolder struct {
// contains filtered or unexported fields
}
Use this one with token from auth middleware this holder doesn't retry to obtain new token
func NewStaticTokenHolder ¶
func NewStaticTokenHolder(token string) *StaticTokenHolder
func (*StaticTokenHolder) Invalidate ¶
func (h *StaticTokenHolder) Invalidate()
type TokenHolder ¶
type User ¶
type User struct { Id string `json:"id"` Username string `json:"username"` Email string `json:"email"` Active bool `json:"active"` Password string `json:"password"` Roles []string `json:"roles"` UpdatedAt time.Time `json:"updatedAt"` CreatedAt time.Time `json:"createdAt"` PlatformNames []string `json:"platforms"` }
func GetCurrentUserFromContext ¶
GetCurrentUserFromContext return user from context or nil
func (*User) HasAccessToPlatform ¶
func (*User) HasPlatformRole ¶
type UserClientMock ¶
type UserClientMock struct { AuthenticateMock func(username string, password string) (string, error) MeMock func(token string) (*User, error) LogoutMock func(token string) error FindByIdMock func(token, userId string) (*User, error) FindAllMock func(token string) ([]*User, error) RevokedTokensMock func(token string) ([]RevokedToken, error) }
func (*UserClientMock) Authenticate ¶
func (c *UserClientMock) Authenticate(username string, password string) (string, error)
func (*UserClientMock) FindById ¶
func (c *UserClientMock) FindById(token, userId string) (*User, error)
func (*UserClientMock) Logout ¶
func (c *UserClientMock) Logout(token string) error
func (*UserClientMock) RevokedTokens ¶
func (c *UserClientMock) RevokedTokens(token string) ([]RevokedToken, error)
Click to show internal directories.
Click to hide internal directories.