services

package
v0.0.0-...-51f14e4 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2019 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GetProjectFiles = func(projectId uint) ([]models.ProjectFile, error) {
	project := models.GetProject(projectId)
	if project == nil {
		return nil, errors.New("not found")
	}
	var projectFiles []models.ProjectFile
	root := fmt.Sprintf("%s/%d", os.Getenv("STORAGE_DIR"), project.ID)
	err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
		if info.IsDir() && info.Name() == ".git" {
			return filepath.SkipDir
		}
		if !info.IsDir() {
			projectFiles = append(projectFiles, models.ProjectFile(path[len(root)+1:]))
		}
		return nil
	})
	if err != nil {
		return nil, err
	}
	return projectFiles, nil
}
View Source
var GetVersions = func(appId uint) ([]dto.Version, error) {
	app := models.GetApplication(appId)
	if app == nil {
		return nil, errors.New("not found")
	}
	var versions []dto.Version
	if app.Repository.Type == "docker-v1" {
		url := fmt.Sprintf("%s/v1/repositories/%s/tags", app.Repository.Url, app.RepositoryArtifact)
		var response []map[string]string
		err := GetJson(url, &response)
		if err != nil {
			return nil, err
		}
		for _, item := range response {
			versions = append(versions, dto.Version{Name: item["name"]})
		}
	}
	if app.Repository.Type == "docker-v2" {
		url := fmt.Sprintf("%s/v2/%s/tags/list", app.Repository.Url, app.RepositoryArtifact)
		var response map[string]interface{}
		err := GetJson(url, &response)
		if err != nil {
			log.Printf("GetJson error: %s", err)
			return nil, err
		}

		for _, item := range response["tags"].([]interface{}) {
			versions = append(versions, dto.Version{Name: item.(string)})
		}
	}
	sort.Sort(dto.ByName(versions))
	return versions, nil
}

Functions

func AuthenticateDatabase

func AuthenticateDatabase(user *models.User, password string) (bool, error)

func AuthenticateLDAP

func AuthenticateLDAP(user *models.User, password string) (bool, error)

func CheckPasswordHash

func CheckPasswordHash(password, hash string) bool

func GenerateToken

func GenerateToken(user *models.User) (*dto.JWT, error)

func GetJson

func GetJson(url string, target interface{}) error

func HashPassword

func HashPassword(password models.Password) (models.Password, error)

func JwtMiddleware

func JwtMiddleware(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc)

func ParseToken

func ParseToken(tokenString string) (*jwt.Token, error)

func RefreshToken

func RefreshToken(r *http.Request) (*dto.JWT, error)

func VerifyClaims

func VerifyClaims(token *jwt.Token, verifyIAT bool, verifyNBF bool, verifyEXP bool) error

func VerifyRefreshTTL

func VerifyRefreshTTL(claim interface{}, cmp int64, req bool) bool

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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