api

package
v0.0.0-...-953ae9e Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2020 License: Apache-2.0 Imports: 54 Imported by: 0

Documentation

Overview

Package User Microservice API.

This serves as the user's microservice api definition for the CUBE Platform

Terms Of Service:

there are no TOS at this moment, use at your own risk we take no responsibility

Schemes: http, https
Host: localhost
BasePath: /v1
Version: 1.0.0
License: MIT http://opensource.org/licenses/MIT
Contact: Yoan Yomba<yoanyombapro@gmail.com.com> http://CUBE.com

Consumes:
- application/json

Produces:
- application/json

Security:
- api_key:

Extensions:
x-meta-value: value
x-meta-array:
  - value1
  - value2
x-meta-array-obj:
  - name: obj
    value: field

swagger:meta

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AttachAuthTokenToHeader

func AttachAuthTokenToHeader(token *authentication.TokenId, req *http.Request)

AttachAuthTokenToHeader attaches an authorization token to a request header

func AttachIdToUrl

func AttachIdToUrl(id uint32, req *http.Request) (map[string]string, *http.Request)

func CheckResponseCode

func CheckResponseCode(t *testing.T, expected, actual int)

CheckResponseCode asserts that the expected response code matches the actual response code

func ConstructCreateTeamRequestHelper

func ConstructCreateTeamRequestHelper(t *testing.T, jsonStr []byte, srv *Server, adminUserId uint32) (*http.Request, bool)

func ConstructCreateUserRequestHelper

func ConstructCreateUserRequestHelper(t *testing.T, jsonStr []byte, srv *Server) (*http.Request, bool)

func CreateTeamAndConvertToJson

func CreateTeamAndConvertToJson() (error, []byte)

creates a team and marshalls to json byte string

func CreateTeamAndOptionalTeamProfile

func CreateTeamAndOptionalTeamProfile(t *testing.T, srv *Server, createProfileResponse CreateTeamProfileResponse, createTeamProfileFlag bool) (uint32, string, error)

func CreateTeamProfileAndConvertToJson

func CreateTeamProfileAndConvertToJson() ([]byte, error)

func CreateTeamSubscriptionAndConvertToJson

func CreateTeamSubscriptionAndConvertToJson() (error, []byte)

create a random subscription and marshalls to json byte string

func CreateToken

func CreateToken(userId int32) (string, error)

CreateToken creates an access token (jwt) and attaches it to a jwt claims map

func CreateUserAndConvertToJson

func CreateUserAndConvertToJson() (error, []byte)

Creates a random user and marshall to json returning any error occuring as well as the marshalled json string

func CreateUserAndOptionalUserProfile

func CreateUserAndOptionalUserProfile(t *testing.T, srv *Server, createProfileResponse CreateUserProfileResponse, createUserProfileFlag bool) (uint32, uint32, string, error)

func CreateUserProfileAndConvertToJson

func CreateUserProfileAndConvertToJson() (error, []byte)

Creates a random user profile and marshall to json returning any error occuring as well as the marshalled json string

func CreateUserSubscriptionAndConvertToJson

func CreateUserSubscriptionAndConvertToJson() (error, []byte)

create a random subscription and marshalls to json byte string

func DeleteCreatedEntities

func DeleteCreatedEntities(db *gorm.DB) func()

DeleteCreatedEntities sets up GORM `onCreate` hook and return a function that can be deferred to remove all the entities created after the hook was set up You can use it as

func TestSomething(t *testing.T){
    db, _ := gorm.Open(...)

    cleaner := DeleteCreatedEntities(db)
    defer cleaner()

}

func DeleteTeam

func DeleteTeam(userAccountId uint32, token string, srv *Server) *httptest.ResponseRecorder

func DeleteTeamProfile

func DeleteTeamProfile(userAccountId uint32, token string, srv *Server) *httptest.ResponseRecorder

func DeleteUser

func DeleteUser(userAccountId uint32, token string, srv *Server) *httptest.ResponseRecorder

func DeleteUserProfile

func DeleteUserProfile(userAccountId uint32, profileId uint32, token string, srv *Server) *httptest.ResponseRecorder

func ExecuteRequest

func ExecuteRequest(req *http.Request, handle func(http.ResponseWriter, *http.Request)) *httptest.ResponseRecorder

ExecuteRequest executes an api request and returns a recorded response

func ExtractIdFromToken

func ExtractIdFromToken(token string) (error, int)

Extracts an account id from a jwt token

func GenerateTestTeamProfile

func GenerateTestTeamProfile() model.TeamProfile

func GetAllUsers

func GetAllUsers(token string, srv *Server, limit int) *httptest.ResponseRecorder

func GetRandomString

func GetRandomString() (string, error, bool)

func GetTeam

func GetTeam(userAccountId uint32, token string, srv *Server) *httptest.ResponseRecorder

func GetTeamProfile

func GetTeamProfile(userAccountId uint32, token string, srv *Server) *httptest.ResponseRecorder

func GetUser

func GetUser(userAccountId uint32, token string, srv *Server) *httptest.ResponseRecorder

func GetUserProfile

func GetUserProfile(userAccountId uint32, token string, srv *Server) *httptest.ResponseRecorder

func Initialize

func Initialize(connSettings string) *database.Database

func NewUUID

func NewUUID() (string, error)

newUUID generates a random UUID according to RFC 4122

func SignupAndStoreTokenInHeader

func SignupAndStoreTokenInHeader(t *testing.T, srv *Server, name, password string, req *http.Request) bool

func UpdateRequestHeaders

func UpdateRequestHeaders(req *http.Request, token string)

Updates the request headers and adds a jwt token as well as content type

func UpdateTeam

func UpdateTeam(teamAccountId uint32, token string, payload []byte, srv *Server) *httptest.ResponseRecorder

func UpdateTeamProfile

func UpdateTeamProfile(teamAccountId uint32, token string, payload []byte, srv *Server) *httptest.ResponseRecorder

Types

type ArrayResponse

type ArrayResponse []string

type Config

type Config struct {
	HttpClientTimeout                   time.Duration `mapstructure:"http-client-timeout"`
	HttpServerTimeout                   time.Duration `mapstructure:"http-server-timeout"`
	HttpServerShutdownTimeout           time.Duration `mapstructure:"http-server-shutdown-timeout"`
	BackendURL                          []string      `mapstructure:"backend-url"`
	UIMessage                           string        `mapstructure:"ui-message"`
	UIColor                             string        `mapstructure:"ui-color"`
	UIPath                              string        `mapstructure:"ui-path"`
	DataPath                            string        `mapstructure:"data-path"`
	ConfigPath                          string        `mapstructure:"config-path"`
	Port                                string        `mapstructure:"port"`
	PortMetrics                         int           `mapstructure:"port-metrics"`
	Hostname                            string        `mapstructure:"hostname"`
	H2C                                 bool          `mapstructure:"h2c"`
	RandomDelay                         bool          `mapstructure:"random-delay"`
	RandomError                         bool          `mapstructure:"random-error"`
	Unhealthy                           bool          `mapstructure:"unhealthy"`
	Unready                             bool          `mapstructure:"unready"`
	JWTSecret                           string        `mapstructure:"jwt-secret"`
	Production                          bool          `mapstructure:"production"`
	RedirectToHttps                     bool          `mapstructure:"redirectohttps"`
	ServiceName                         string        `mapstructure:"service-name"`
	ZipkinServerUrl                     string        `mapstructure:"zipkin-server-url"`
	AmqpServerUrl                       string        `mapstructure:"amqp-server-url"`
	EnableAuthServicePrivateIntegration bool          `mapstructure:"ENABLE_AUTH_SERVICE_PRIVATE_INTEGRATION"`
	ServiceEmail                        string        `mapstructure:"SERVICE_EMAIL"`
}

type CreateTeamProfileRequest

type CreateTeamProfileRequest struct {
	Profile model.TeamProfile `json:"payload"`
}

type CreateTeamProfileResponse

type CreateTeamProfileResponse struct {
	Id    uint32 `json:"id"`
	Error error  `json:"error"`
}

type CreateTeamRequest

type CreateTeamRequest struct {
	Team    model.Team `json:"team"`
	AdminId uint32     `json:"adminId"`
}

type CreateTeamResponse

type CreateTeamResponse struct {
	Id    uint32 `json:"id"`
	Error error  `json:"error"`
}

func CreateTestTeamBackendCall

func CreateTestTeamBackendCall(t *testing.T, srv *Server) (CreateTeamResponse, string, bool)

type CreateTeamSubscriptionRequest

type CreateTeamSubscriptionRequest struct {
	Subscription model.Subscriptions `json:"payload"`
}

type CreateTeamSubscriptionResponse

type CreateTeamSubscriptionResponse struct {
	Error error      `json:"error"`
	Team  model.Team `json:"payload"`
}

type CreateUserProfileRequest

type CreateUserProfileRequest struct {
	UserProfile model.Profile `json:"result"`
}

type CreateUserProfileResponse

type CreateUserProfileResponse struct {
	UserProfile model.Profile `json:"result"`
	Error       error         `json:"error"`
}

type CreateUserRequest

type CreateUserRequest struct {
	User model.User `json:"user"`
}

type CreateUserResponse

type CreateUserResponse struct {
	Error error  `json:"error"`
	Id    uint32 `json:"id"`
}

func CreateTestUserBackendCall

func CreateTestUserBackendCall(t *testing.T, srv *Server) (CreateUserResponse, string, bool)

type CreateUserSubscriptionRequest

type CreateUserSubscriptionRequest struct {
	Subscription model.Subscriptions `json:"result"`
}

type CreateUserSubscriptionResponse

type CreateUserSubscriptionResponse struct {
	Error        error                  `json:"error"`
	Subscription []*model.Subscriptions `json:"result"`
}

type DeleteSubscriptionRequestSwagger

type DeleteSubscriptionRequestSwagger struct {
	// user account id
	// in: query
	// required: true
	UserAccountId uint32
	// contains filtered or unexported fields
}

swagger:parameters deleteSubscription

type DeleteTeamProfileResponse

type DeleteTeamProfileResponse struct {
	Error error `json:"error"`
}

type DeleteTeamResponse

type DeleteTeamResponse struct {
	Error error `json:"error"`
}

type DeleteUserByIdRequestSwagger

type DeleteUserByIdRequestSwagger struct {
	// id of the user account to delete
	// in: query
	// required: true
	Id uint32 `json:"result"`
}

Delete user by id request swagger:parameters deleteUser

type DeleteUserProfileRequestSwagger

type DeleteUserProfileRequestSwagger struct {
	// user account id
	// in: query
	// required: true
	UserAccountId uint32
	// profile id
	// in: query
	// required: true
	ProfileId uint32
}

swagger:parameters deleteProfile

type FluxConfig

type FluxConfig struct {
	GitUrl    string `mapstructure:"git-url"`
	GitBranch string `mapstructure:"git-branch"`
}

type GetAllUserProfileResponse

type GetAllUserProfileResponse struct {
	Error       error           `json:"error"`
	UserProfile []model.Profile `json:"result"`
}

type GetAllUserProfilesSwagger

type GetAllUserProfilesSwagger struct {
	// in: query
	// required: true
	Limit uint32
}

swagger: response getAllUserProfiles

type GetAllUserSubscriptionsRequestSwagger

type GetAllUserSubscriptionsRequestSwagger struct {
	// in: query
	AccountId uint32
}

swagger:parameters getAllSubscriptions

type GetAllUserSubscriptionsResponse

type GetAllUserSubscriptionsResponse struct {
	Error         error                 `json:"error"`
	Subscriptions []model.Subscriptions `json:"result"`
}

type GetAllUserSubscriptionsResponseSwagger

type GetAllUserSubscriptionsResponseSwagger struct {
	// in: body
	Body struct {
		// errors occuring throughout the request lifecycle
		// required: true
		Error error `json:"error"`
		// set of subscriptions of interest
		// required: true
		Subscriptions []model.Subscriptions `json:"result"`
	}
}

swagger:response getSubscriptionsResponse

type GetAllUsersByAccountTypeRequestSwagger

type GetAllUsersByAccountTypeRequestSwagger struct {
	// contains filtered or unexported fields
}

swagger:parameters getAllUsersByAccountTypeRequest

type GetAllUsersByIntentRequestSwagger

type GetAllUsersByIntentRequestSwagger struct {
	// contains filtered or unexported fields
}

swagger:parameters getAllUsersByIntentRequest

type GetAllUsersRequestSwagger

type GetAllUsersRequestSwagger struct {
	// contains filtered or unexported fields
}

swagger:parameters getAllUsersRequest

type GetAllUsersResponse

type GetAllUsersResponse struct {
	Error error        `json:"error"`
	Users []model.User `json:"result"`
}

type GetAllUsersResponseSwagger

type GetAllUsersResponseSwagger struct {
	// in: body
	Body struct {
		// error
		// required: true
		Error error `json:"error"`
		// set of users
		// required: true
		Users []model.User `json:"result"`
	}
}

swagger:response getAllUsersResponse

type GetTeamProfileResponse

type GetTeamProfileResponse struct {
	Error       error             `json:"error"`
	TeamProfile model.TeamProfile `json:"payload"`
}

type GetTeamResponse

type GetTeamResponse struct {
	Team  model.Team `json:"payload"`
	Error error      `json:"error"`
}

type GetUserByIdRequestSwagger

type GetUserByIdRequestSwagger struct {
	// id of the user account to get
	// in: query
	// required: true
	Id uint32 `json:"result"`
}

Get user by id request swagger:parameters getUser

type GetUserProfileRequestSwagger

type GetUserProfileRequestSwagger struct {
	// in: query
	// required: true
	AccountId uint32 `json:"error"`
}

swagger:parameters getUserProfile

type GetUserProfileResponse

type GetUserProfileResponse struct {
	Error       error         `json:"error"`
	UserProfile model.Profile `json:"result"`
}

type GetUserProfileResponseSwagger

type GetUserProfileResponseSwagger struct {
	// in: body
	Body struct {
		// error
		// required: true
		Error error `json:"error"`
		// profile of interest
		// required: true
		UserProfile model.Profile `json:"result"`
	}
}

swagger:response getUserProfileResponse

type GetUserProfilesByNationalityRequestSwagger

type GetUserProfilesByNationalityRequestSwagger struct {
	// in: query
	// required: true
	Nationality string
	// required: true
	Limit uint32
}

swagger: parameters getAllUserProfilesByNationality

type GetUserProfilesByProfileTypeRequestSwagger

type GetUserProfilesByProfileTypeRequestSwagger struct {
	// in: query
	// required: true
	ProfileType string
	// required: true
	Limit uint32
}

swagger: parameters getAllUserProfilesByProfileType

type LoginResponse

type LoginResponse struct {
	JwtToken string `json:"token"`
	Error    error  `json:"error"`
}

type LoginTeamRequest

type LoginTeamRequest struct {
	TeamName string `json:"teamname"`
	Password string `json:"password"`
}

type LoginUserRequest

type LoginUserRequest struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

type MapResponse

type MapResponse map[string]string

type OperationResponse

type OperationResponse struct {
	Error error `json:"error"`
}

type OperationResponseSwagger

type OperationResponseSwagger struct {
	// in: body
	Body struct {
		// error
		// required: true
		// example: Error occured
		Error error `json:"error"`
	}
}

swagger:response operationResponse

type RuntimeResponse

type RuntimeResponse struct {
	Hostname     string `json:"hostname"`
	Version      string `json:"version"`
	Revision     string `json:"revision"`
	Color        string `json:"color"`
	Message      string `json:"message"`
	GOOS         string `json:"goos"`
	GOARCH       string `json:"goarch"`
	Runtime      string `json:"runtime"`
	NumGoroutine string `json:"num_goroutine"`
	NumCPU       string `json:"num_cpu"`
}

type Server

type Server struct {
	Db              *database.Database
	Auth            *authentication.Authentication
	JwtConfig       *authentication.JwtConfiguration
	Keys            *authentication.JsonKeys
	InfraCounters   *infrastructure.InfrastructureCounters
	MessagingClient *rabbitmq.RabbitMQClient
	// contains filtered or unexported fields
}

func InitializeMockServer

func InitializeMockServer() *Server

func InitializeMockServerAndDb

func InitializeMockServerAndDb() (*Server, func())

func NewMockServer

func NewMockServer() *Server

func NewServer

func NewServer(
	config *Config,
	logger *zap.Logger,
	database *database.Database,
	messagingClient *rabbitmq.RabbitMQClient,
	infrastructureCounter *infrastructure.InfrastructureCounters,
	authServiceWrapper *authentication.Authentication) (*Server, error)

func (*Server) ErrorResponse

func (s *Server) ErrorResponse(w http.ResponseWriter, r *http.Request, error string, code int)

func (*Server) ExtractJwtFromHeader

func (s *Server) ExtractJwtFromHeader(r *http.Request) (error, uint32)

func (*Server) JSONResponse

func (s *Server) JSONResponse(w http.ResponseWriter, r *http.Request, result interface{})

func (*Server) JSONResponseCode

func (s *Server) JSONResponseCode(w http.ResponseWriter, r *http.Request, result interface{}, responseCode int)

func (*Server) ListenAndServe

func (s *Server) ListenAndServe(stopCh <-chan struct{})

func (*Server) TeamExistsToAuthService

func (s *Server) TeamExistsToAuthService(w http.ResponseWriter, team *model.Team) bool

func (*Server) UserExistsToAuthService

func (s *Server) UserExistsToAuthService(w http.ResponseWriter, user *model.User) bool

type TokenResponse

type TokenResponse struct {
	Token     string    `json:"token"`
	ExpiresAt time.Time `json:"expires_at"`
}

type TokenValidationResponse

type TokenValidationResponse struct {
	TokenName string    `json:"token_name"`
	ExpiresAt time.Time `json:"expires_at"`
}

type UpdateTeamProfileRequest

type UpdateTeamProfileRequest struct {
	Profile model.TeamProfile `json:"payload"`
}

type UpdateTeamProfileRequestSwagger

type UpdateTeamProfileRequestSwagger struct {
	// in: body
	Body struct {
		// team profile to update
		// required: true
		TeamProfile model.TeamProfile `json:"payload"`
	}
	// in: query
	// required: true
	// example; 1243
	TeamId uint32 `json:"teamId"`
}

Update team profile request swagger:parameters updateTeamProfileRequest

type UpdateTeamProfileResponse

type UpdateTeamProfileResponse struct {
	Error   error      `json:"error"`
	Profile model.Team `json:"payload"`
}

type UpdateTeamProfileResponseSwagger

type UpdateTeamProfileResponseSwagger struct {
	// in: body
	Body struct {
		// updated team profile
		// required: true
		TeamProfile model.TeamProfile `json:"result"`
		// error
		// required: true
		Error error `json:"error"`
	}
}

Updated team profile response swagger:response updateTeamProfileResponse

type UpdateTeamRequest

type UpdateTeamRequest struct {
	Team model.Team `json:"payload"`
}

type UpdateTeamRequestSwagger

type UpdateTeamRequestSwagger struct {
	// in: body
	Body struct {
		// team to update
		// required: true
		Team model.Team `json:"payload"`
	}
	// in: query
	// required: true
	// exmaple; 1243
	TeamId uint32 `json:"teamId"`
}

Update team request swagger:parameters updateTeamRequest

type UpdateTeamResponse

type UpdateTeamResponse struct {
	Error error      `json:"error"`
	Team  model.Team `json:"payload"`
}

type UpdateTeamResponseSwagger

type UpdateTeamResponseSwagger struct {
	// in: body
	Body struct {
		// updated team
		// required: true
		Team model.Team `json:"result"`
		// error
		// required: true
		Error error `json:"error"`
	}
}

Updated team response swagger:response updateTeamResponse

type UpdateUserProfileRequest

type UpdateUserProfileRequest struct {
	Profile model.Profile `json:"result"`
}

type UpdateUserProfileRequestSwagger

type UpdateUserProfileRequestSwagger struct {
	// in: body
	Body struct {
		// errors
		// required: true
		Error error `json:"error"`
		// profile to update
		// required: true
		Profile model.Profile `json:"result"`
	}
	// user account id
	// in: query
	// required: true
	UserAccountId uint32
	// profile id
	// in: query
	// required: true
	ProfileId uint32
}

swagger:parameters updateProfile

type UpdateUserProfileResponse

type UpdateUserProfileResponse struct {
	Error   error         `json:"error"`
	Profile model.Profile `json:"result"`
}

type UpdateUserProfileResponseSwagger

type UpdateUserProfileResponseSwagger struct {
	// in: body
	Body struct {
		// error
		// required: true
		Error error `json:"error"`
		// profile to update
		// required: true
		Profile model.Profile `json:"result"`
	}
}

swagger:response updateProfileResponse

type UpdateUserRequestSwagger

type UpdateUserRequestSwagger struct {
	// user account to create
	// in: body
	Body struct {
		// required: true
		User model.User `json:"result"`
	}
}

Update user request swagger:parameters updateUser

type UpdateUserSubscriptionRequest

type UpdateUserSubscriptionRequest struct {
	Subscription model.Subscriptions `json:"result"`
}

type UpdateUserSubscriptionResponse

type UpdateUserSubscriptionResponse struct {
	Error        error               `json:"error"`
	Subscription model.Subscriptions `json:"result"`
}

type UserOperationResponse

type UserOperationResponse struct {
	Error error      `json:"error"`
	User  model.User `json:"result"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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