services

package
v0.0.0-...-85a151d Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2021 License: MIT Imports: 19 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"], Value: item["name"]})
		}
		for i, j := 0, len(versions)-1; i < j; i, j = i+1, j-1 {
			versions[i], versions[j] = versions[j], versions[i]
		}
	}
	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), Value: item.(string)})
		}
		for i, j := 0, len(versions)-1; i < j; i, j = i+1, j-1 {
			versions[i], versions[j] = versions[j], versions[i]
		}
	}
	if app.Repository.Type == "nexus-v3" {
		continuationToken := ""
		hasMore := true
		versionsMap := make(map[string]dto.Version)
		regex := regexp.MustCompile(`-(\d{8})\.(\d{6})-(\d{1,4})`)

		for hasMore {
			url := fmt.Sprintf(
				"%s/service/rest/v1/search?repository=%s&group=%s&name=%s%s",
				app.Repository.Url,
				app.Repository.NexusName,
				app.RepositoryGroup,
				app.RepositoryArtifact,
				continuationToken)
			var response map[string]interface{}
			err := GetJson(url, &response)
			if err != nil {
				log.Printf("GetJson error: %s", err)
				return nil, err
			}
			hasMore = response["continuationToken"] != nil
			if hasMore {
				continuationToken = fmt.Sprintf("&continuationToken=%s", response["continuationToken"].(string))
			}

			for _, item := range response["items"].([]interface{}) {
				version := regex.ReplaceAllString(item.(map[string]interface{})["version"].(string), "-SNAPSHOT")
				snapshotData := regex.FindStringSubmatch(item.(map[string]interface{})["version"].(string))
				name := version
				if len(snapshotData) == 4 {
					date, err := time.Parse("20060102", snapshotData[1])
					time, err2 := time.Parse("150405", snapshotData[2])
					if err == nil && err2 == nil {
						name += " | " + date.Format("2006-01-02") + " " + time.Format("15:04:05") + " | Build number: #" + snapshotData[3]
					}
				}

				versionsMap[version] = dto.Version{Name: name, Value: version, SortKey: getSortKey(version)}
			}
		}
		for _, item := range versionsMap {
			versions = append(versions, item)
		}
		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 GetJWTClaims

func GetJWTClaims(r *http.Request) dto.JWTClaims

func GetJson

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

func HashPassword

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

func ParseToken

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

func RefreshToken

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

func TokenGetter

func TokenGetter(r *http.Request) string

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