v1

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2021 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	V1APIPathPrefix = "/api/v1"
)

Variables

View Source
var (
	// MaxTokens defines the maximum number of API tokens a user can create.
	MaxTokens int64 = 100
)

Functions

func ModuleFromManifest

func ModuleFromManifest(manifest Manifest, sanitizer Sanitizer) models.Module

ModuleFromManifest converts a Manifest to a Module model.

Types

type AuthorsManifest

type AuthorsManifest struct {
	Name  string `json:"name" toml:"name" validate:"required"`
	Email string `json:"email" toml:"email" validate:"omitempty,email"`
}

AuthorsManifest defines author information in a module's manifest.

type BugTackerManifest

type BugTackerManifest struct {
	URL     string `json:"url" toml:"url" validate:"omitempty,url"`
	Contact string `json:"contact" toml:"contact" validate:"omitempty,email"`
}

BugTackerManifest defines the bug tracker information in a module's manifest.

type GitHubClient added in v0.0.2

type GitHubClient struct {
	*github.Client
}

GitHubClient implements a wrapper around a GitHub v3 API client.

func NewGitHubClient added in v0.0.2

func NewGitHubClient(token string) *GitHubClient

func (*GitHubClient) GetRepository added in v0.0.2

func (gc *GitHubClient) GetRepository(repoURL string) (Repository, error)

GetRepository returns a Repository object which contains information needed when publishing a Cosmos SDK module. It returns an error if the repository URL is invalid or if any resource fails to be fetched from the GitHub API.

type GitHubClientI added in v0.0.2

type GitHubClientI interface {
	GetRepository(repoURL string) (Repository, error)
}

GitHubClientI defines the interface used to retrieve GitHub repository information.

type Manifest

type Manifest struct {
	Module     ModuleManifest    `json:"module" toml:"module"`
	BugTracker BugTackerManifest `json:"bug_tracker" toml:"bug_tracker" validate:"omitempty,dive"`
	Authors    []AuthorsManifest `json:"authors" toml:"authors" validate:"required,gt=0,unique=Name,dive"`
	Version    VersionManifest   `json:"version" toml:"version" validate:"required,dive"`
}

Manifest defines a Cosmos SDK module manifest. It translates directly into a Module model.

type ModuleInvite

type ModuleInvite struct {
	ModuleID uint   `json:"module_id" validate:"required,gte=1"`
	User     string `json:"user" validate:"required"`
}

ModuleInvite defines the request type when inviting a user as an owner to a module.

type ModuleManifest

type ModuleManifest struct {
	Name        string   `json:"name" toml:"name" validate:"required"`
	Keywords    []string `json:"keywords" toml:"keywords" validate:"omitempty,gt=0,unique,dive,gt=0"`
	Description string   `json:"description" toml:"description"`
	Homepage    string   `json:"homepage" toml:"homepage" validate:"omitempty,url"`
}

ModuleManifest defines the primary module fields in a module's manifest.

type ModuleStars

type ModuleStars struct {
	Stars int64 `json:"stars"`
}

ModuleStars defines the HTTP response type for the total nubmer of favorites for a module.

type Repository added in v0.0.2

type Repository struct {
	Owner        string
	Repo         string
	Contributors map[string]*github.Contributor
}

Repository defines the relevant information Atlas needs for a GitHub repository in order to publish modules.

type Router

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

Router implements a versioned HTTP router responsible for handling all v1 API requests

func NewRouter

func NewRouter(
	logger zerolog.Logger,
	cfg config.Config,
	db *gorm.DB,
	cookieCfg gologin.CookieConfig,
	sStore *sessions.CookieStore,
	oauth2Cfg *oauth2.Config,
	ghClientCreator func(string) GitHubClientI,
) (*Router, error)

func (*Router) AcceptOwnerInvite

func (r *Router) AcceptOwnerInvite() http.HandlerFunc

AcceptOwnerInvite implements a request handler for accepting a module owner invitation.

@Summary Accept a module owner invitation @Tags users @Produce json @Param inviteToken path string true "invite token" @Success 200 {object} models.ModuleJSON @Failure 400 {object} httputil.ErrResponse @Failure 401 {object} httputil.ErrResponse @Failure 404 {object} httputil.ErrResponse @Failure 500 {object} httputil.ErrResponse @Security APIKeyAuth @Router /me/invite/accept/{inviteToken} [put]

func (*Router) AuthorizeSession

func (r *Router) AuthorizeSession() http.Handler

AuthorizeSession returns a callback request handler for Github OAuth user authentication. After a user grants access, this callback handler will be executed. A session cookie will be saved and sent to the client. A user record will also be upserted.

func (*Router) ConfirmEmail

func (r *Router) ConfirmEmail() http.HandlerFunc

ConfirmEmail implements a request handler for confirming a user email address.

@Summary Confirm a user email confirmation @Tags users @Produce json @Param emailToken path string true "email token" @Success 200 {object} models.UserJSON @Failure 400 {object} httputil.ErrResponse @Failure 401 {object} httputil.ErrResponse @Failure 404 {object} httputil.ErrResponse @Failure 500 {object} httputil.ErrResponse @Router /me/confirm/{emailToken} [put]

func (*Router) CreateUserToken

func (r *Router) CreateUserToken() http.HandlerFunc

CreateUserToken implements a request handler that creates a new API token for the authenticated user.

@Summary Create a user API token @Tags users @Produce json @Param token body Token true "token name" @Success 200 {object} models.UserTokenJSON @Failure 400 {object} httputil.ErrResponse @Failure 401 {object} httputil.ErrResponse @Failure 500 {object} httputil.ErrResponse @Security APIKeyAuth @Router /me/tokens [put]

func (*Router) GetAllKeywords

func (r *Router) GetAllKeywords() http.HandlerFunc

GetAllKeywords implements a request handler returning a paginated set of keywords.

@Summary Return a paginated set of all keywords @Tags keywords @Accept json @Produce json @Param page query int true "pagination page" default(1) @Param limit query int true "pagination limit" default(100) @Param reverse query string false "pagination reverse" default(false) @Param order query string false "pagination order by" default(id) @Success 200 {object} httputil.PaginationResponse @Failure 400 {object} httputil.ErrResponse @Failure 500 {object} httputil.ErrResponse @Router /keywords [get]

func (*Router) GetAllModules

func (r *Router) GetAllModules() http.HandlerFunc

GetAllModules implements a request handler returning a paginated set of modules.

@Summary Return a paginated set of all Cosmos SDK modules @Tags modules @Accept json @Produce json @Param page query int true "pagination page" default(1) @Param limit query int true "pagination limit" default(100) @Param reverse query string false "pagination reverse" default(false) @Param order query string false "pagination order by" default(id) @Success 200 {object} httputil.PaginationResponse @Failure 400 {object} httputil.ErrResponse @Failure 500 {object} httputil.ErrResponse @Router /modules [get]

func (*Router) GetAllUsers

func (r *Router) GetAllUsers() http.HandlerFunc

GetAllUsers implements a request handler returning a paginated set of users.

@Summary Return a paginated set of all users @Tags users @Accept json @Produce json @Param page query int true "pagination page" default(1) @Param limit query int true "pagination limit" default(100) @Param reverse query string false "pagination reverse" default(false) @Param order query string false "pagination order by" default(id) @Success 200 {object} httputil.PaginationResponse @Failure 400 {object} httputil.ErrResponse @Failure 500 {object} httputil.ErrResponse @Router /users [get]

func (*Router) GetModuleAuthors

func (r *Router) GetModuleAuthors() http.HandlerFunc

GetModuleAuthors implements a request handler to retrieve a module's set of authors by ID.

@Summary Get all authors for a Cosmos SDK module by ID @Tags modules @Accept json @Produce json @Param id path int true "module ID" @Success 200 {array} models.UserJSON @Failure 400 {object} httputil.ErrResponse @Failure 404 {object} httputil.ErrResponse @Failure 500 {object} httputil.ErrResponse @Router /modules/{id}/authors [get]

func (*Router) GetModuleByID

func (r *Router) GetModuleByID() http.HandlerFunc

GetModuleByID implements a request handler to retrieve a module by ID.

@Summary Get a Cosmos SDK module by ID @Tags modules @Accept json @Produce json @Param id path int true "module ID" @Success 200 {object} models.ModuleJSON @Failure 400 {object} httputil.ErrResponse @Failure 404 {object} httputil.ErrResponse @Failure 500 {object} httputil.ErrResponse @Router /modules/{id} [get]

func (*Router) GetModuleKeywords

func (r *Router) GetModuleKeywords() http.HandlerFunc

GetModuleKeywords implements a request handler to retrieve a module's set of keywords by ID.

@Summary Get all keywords for a Cosmos SDK module by ID @Tags modules @Accept json @Produce json @Param id path int true "module ID" @Success 200 {array} models.KeywordJSON @Failure 400 {object} httputil.ErrResponse @Failure 404 {object} httputil.ErrResponse @Failure 500 {object} httputil.ErrResponse @Router /modules/{id}/keywords [get]

func (*Router) GetModuleVersions

func (r *Router) GetModuleVersions() http.HandlerFunc

GetModuleVersions implements a request handler to retrieve a module's set of versions by ID.

@Summary Get all versions for a Cosmos SDK module by ID @Tags modules @Accept json @Produce json @Param id path int true "module ID" @Success 200 {array} models.ModuleVersionJSON @Failure 400 {object} httputil.ErrResponse @Failure 404 {object} httputil.ErrResponse @Failure 500 {object} httputil.ErrResponse @Router /modules/{id}/versions [get]

func (*Router) GetUser

func (r *Router) GetUser() http.HandlerFunc

GetUser returns the current authenticated user.

@Summary Get the current authenticated user @Tags users @Produce json @Success 200 {object} models.UserJSON @Failure 401 {object} httputil.ErrResponse @Security APIKeyAuth @Router /me [get]

func (*Router) GetUserByName

func (r *Router) GetUserByName() http.HandlerFunc

GetUserByID implements a request handler to retrieve a user by name.

@Summary Get a user by name @Tags users @Accept json @Produce json @Param name path string true "user name" @Success 200 {object} models.UserJSON @Failure 404 {object} httputil.ErrResponse @Failure 500 {object} httputil.ErrResponse @Router /users/{name} [get]

func (*Router) GetUserModules

func (r *Router) GetUserModules() http.HandlerFunc

GetUserModules implements a request handler to retrieve a set of modules authored by a given user by name.

@Summary Return a set of all Cosmos SDK modules published by a given user @Tags users @Accept json @Produce json @Param name path string true "user name" @Success 200 {array} models.ModuleJSON @Failure 404 {object} httputil.ErrResponse @Failure 500 {object} httputil.ErrResponse @Router /users/{name}/modules [get]

func (*Router) GetUserTokens

func (r *Router) GetUserTokens() http.HandlerFunc

GetUserTokens implements a request handler returning all of an authenticated user's tokens.

@Summary Get all API tokens by user ID @Tags users @Produce json @Success 200 {array} models.UserTokenJSON @Failure 401 {object} httputil.ErrResponse @Failure 500 {object} httputil.ErrResponse @Security APIKeyAuth @Router /me/tokens [get]

func (*Router) InviteOwner

func (r *Router) InviteOwner() http.HandlerFunc

InviteOwner implements a request handler to invite a user to be an owner of a module.

@Summary Invite a user to be an owner of a module @Tags users @Produce json @Accept json @Param invite body ModuleInvite true "invitation" @Success 200 {object} boolean @Failure 400 {object} httputil.ErrResponse @Failure 401 {object} httputil.ErrResponse @Failure 404 {object} httputil.ErrResponse @Failure 500 {object} httputil.ErrResponse @Security APIKeyAuth @Router /me/invite [put]

func (*Router) LogoutSession

func (r *Router) LogoutSession() http.HandlerFunc

LogoutSession implements a request handler to terminate and logout of an existing session.

func (*Router) Register

func (r *Router) Register(rtr *mux.Router, prefix string)

Register registers all v1 HTTP handlers with the provided mux router and prefix path. All registered HTTP handlers come bundled with the appropriate middleware.

func (*Router) RevokeUserToken

func (r *Router) RevokeUserToken() http.HandlerFunc

RevokeUserToken implements a request handler revoking a specific token from the authorized user.

@Summary Revoke a user API token by ID @Tags users @Produce json @Param id path int true "token ID" @Success 200 {object} models.UserTokenJSON @Failure 400 {object} httputil.ErrResponse @Failure 401 {object} httputil.ErrResponse @Failure 500 {object} httputil.ErrResponse @Security APIKeyAuth @Router /me/tokens/{id} [delete]

func (*Router) SearchModules

func (r *Router) SearchModules() http.HandlerFunc

SearchModules implements a request handler to retrieve a set of module objects by search criteria.

@Summary Search for Cosmos SDK modules by name, team, description and keywords @Tags modules @Accept json @Produce json @Param page query int true "pagination page" default(1) @Param limit query int true "pagination limit" default(100) @Param reverse query string false "pagination reverse" default(false) @Param order query string false "pagination order by" default(id) @Param q query string true "search criteria" @Success 200 {object} httputil.PaginationResponse @Failure 400 {object} httputil.ErrResponse @Failure 500 {object} httputil.ErrResponse @Router /modules/search [get]

func (*Router) SearchNodes added in v0.0.3

func (r *Router) SearchNodes() http.HandlerFunc

SearchNodes implements a request handler to retrieve a set of nodes by search criteria, which can be empty.

@Summary Search for Tendermint crawled nodes by network, moniker, version or location. @Tags nodes @Accept json @Produce json @Param page query int true "pagination page" default(1) @Param limit query int true "pagination limit" default(100) @Param reverse query string false "pagination reverse" default(false) @Param order query string false "pagination order by" default(id) @Param q query string false "search criteria" @Success 200 {object} httputil.PaginationResponse @Failure 400 {object} httputil.ErrResponse @Failure 500 {object} httputil.ErrResponse @Router /nodes/search [get]

func (*Router) StarModule

func (r *Router) StarModule() http.HandlerFunc

StarModule implements a request handler for adding a favorite by a user to a given module.

@Summary Add a favorite for a module @Tags modules @Produce json @Param id path int true "module ID" @Success 200 {object} ModuleStars @Failure 400 {object} httputil.ErrResponse @Failure 401 {object} httputil.ErrResponse @Failure 404 {object} httputil.ErrResponse @Failure 500 {object} httputil.ErrResponse @Security APIKeyAuth @Router /modules/{id}/star [put]

func (*Router) StartSession

func (r *Router) StartSession() http.Handler

StartSession returns a request handler to begin a user session via Github OAuth authentication. The user must either grant or reject access. Upon granting access, Github will perform a callback where we create a session and obtain a token.

func (*Router) UnStarModule

func (r *Router) UnStarModule() http.HandlerFunc

UnStarModule implements a request handler for removing a favorite by a user to a given module.

@Summary Remove a favorite for a module @Tags modules @Produce json @Param id path int true "module ID" @Success 200 {object} ModuleStars @Failure 400 {object} httputil.ErrResponse @Failure 401 {object} httputil.ErrResponse @Failure 404 {object} httputil.ErrResponse @Failure 500 {object} httputil.ErrResponse @Security APIKeyAuth @Router /modules/{id}/unstar [put]

func (*Router) UpdateUser

func (r *Router) UpdateUser() http.HandlerFunc

UpdateUser updates an existing user record.

@Summary Update the current authenticated user @Tags users @Produce json @Param user body User true "user" @Success 200 {object} boolean @Failure 400 {object} httputil.ErrResponse @Failure 401 {object} httputil.ErrResponse @Failure 500 {object} httputil.ErrResponse @Security APIKeyAuth @Router /me [put]

func (*Router) UpsertModule

func (r *Router) UpsertModule() http.HandlerFunc

UpsertModule implements a request handler to publish a Cosmos SDK module. The authorized user is considered to be the publisher. The publisher must be an owner of the module and a contributor to the GitHub repository. If the module does not exist, the publisher is considered to be the first and only owner and subsequent owners may be invited by the publisher. An error is returned if the request body is invalid, the user is not authorized or if any database transaction fails.

@Summary Publish a Cosmos SDK module @Tags modules @Accept json @Produce json @Param manifest body Manifest true "module manifest" @Success 200 {object} models.ModuleJSON @Failure 400 {object} httputil.ErrResponse @Failure 401 {object} httputil.ErrResponse @Failure 500 {object} httputil.ErrResponse @Security APIKeyAuth @Router /modules [put]

type Sanitizer

type Sanitizer interface {
	Sanitize(string) string
}

Sanitizer defines a sanitization interface for cleaning HTML input.

type Token

type Token struct {
	Name string `json:"name" validate:"required"`
}

Token defines the request type when creating a new user API token.

type User

type User struct {
	Email string `json:"email" validate:"required,email"`
}

User defines the request type when updating a user record.

type VersionManifest

type VersionManifest struct {
	Repo          string `json:"repo" toml:"repo" validate:"required,url"`
	Documentation string `json:"documentation" toml:"documentation" validate:"omitempty,url"`
	Version       string `json:"version" toml:"version" validate:"required"`
	SDKCompat     string `json:"sdk_compat" toml:"sdk_compat"`
}

VersionManifest defines the version information in a module's manifest.

Jump to

Keyboard shortcuts

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