• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang models.Repository类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/containerops/wharf/models.Repository的典型用法代码示例。如果您正苦于以下问题:Golang Repository类的具体用法?Golang Repository怎么用?Golang Repository使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Repository类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: GetRepositoryTags

func (this *RepoAPIV1Controller) GetRepositoryTags() {
	namespace := this.Ctx.Input.Param(":namespace")
	repository := this.Ctx.Input.Param(":repo_name")

	repo := new(models.Repository)

	if has, _, err := repo.Has(namespace, repository); err != nil {
		this.JSONOut(http.StatusBadRequest, "Read repository json error", nil)
		return
	} else if has == false {
		this.JSONOut(http.StatusBadRequest, "Read repository no found", nil)
		return
	}

	tag := map[string]string{}

	for _, value := range repo.Tags {
		t := new(models.Tag)
		if err := t.GetById(value); err != nil {
			this.JSONOut(http.StatusBadRequest, "", map[string]string{"message": fmt.Sprintf("%s/%s Tags is not exist", namespace, repository)})
			return
		}

		tag[t.Name] = t.ImageId
	}

	this.JSONOut(http.StatusOK, "", tag)
	return
}
开发者ID:rechen,项目名称:wharf,代码行数:29,代码来源:repoapiv1.go


示例2: PutRepository

func (this *RepoAPIV1Controller) PutRepository() {
	username, _, _ := utils.DecodeBasicAuth(this.Ctx.Input.Header("Authorization"))

	namespace := string(this.Ctx.Input.Param(":namespace"))
	repository := string(this.Ctx.Input.Param(":repo_name"))

	repo := new(models.Repository)

	if err := repo.Put(namespace, repository, string(this.Ctx.Input.CopyBody()), this.Ctx.Input.Header("User-Agent"), models.APIVERSION_V1); err != nil {
		this.JSONOut(http.StatusForbidden, err.Error(), nil)
		return
	}

	if this.Ctx.Input.Header("X-Docker-Token") == "true" {
		token := string(utils.GeneralKey(username))
		this.SetSession("token", token)
		this.Ctx.Output.Context.ResponseWriter.Header().Set("X-Docker-Token", token)
		this.Ctx.Output.Context.ResponseWriter.Header().Set("WWW-Authenticate", token)
	}

	user := new(models.User)
	if _, _, err := user.Has(username); err != nil {
		this.JSONOut(http.StatusForbidden, err.Error(), nil)
		return
	}

	memo, _ := json.Marshal(this.Ctx.Input.Header)
	user.Log(models.ACTION_UPDATE_REPO, models.LEVELINFORMATIONAL, models.TYPE_APIV1, repo.Id, memo)
	repo.Log(models.ACTION_UPDATE_REPO, models.LEVELINFORMATIONAL, models.TYPE_APIV1, repo.Id, memo)

	this.Ctx.Output.Context.ResponseWriter.Header().Set("X-Docker-Endpoints", beego.AppConfig.String("docker::Endpoints"))
	this.Ctx.Output.Context.Output.SetStatus(http.StatusOK)
	this.Ctx.Output.Context.Output.Body([]byte(""))
	return
}
开发者ID:rechen,项目名称:wharf,代码行数:35,代码来源:repoapiv1.go


示例3: GetTags

func (this *ManifestsAPIV2Controller) GetTags() {
	namespace := this.Ctx.Input.Param(":namespace")
	repository := this.Ctx.Input.Param(":repo_name")

	repo := new(models.Repository)

	if has, _, err := repo.Has(namespace, repository); err != nil || has == false {
		this.JSONOut(http.StatusBadRequest, "", map[string][]modules.ErrorDescriptor{"errors": []modules.ErrorDescriptor{modules.ErrorDescriptors[modules.APIErrorCodeNameInvalid]}})
		return
	}

	data := map[string]interface{}{}
	tags := []string{}

	data["name"] = fmt.Sprintf("%s/%s", namespace, repository)

	for _, value := range repo.Tags {
		t := new(models.Tag)
		if err := t.GetById(value); err != nil {
			this.JSONOut(http.StatusBadRequest, "", map[string][]modules.ErrorDescriptor{"errors": []modules.ErrorDescriptor{modules.ErrorDescriptors[modules.APIErrorCodeTagInvalid]}})
			return
		}

		tags = append(tags, t.Name)
	}

	data["tags"] = tags

	this.JSONOut(http.StatusOK, "", data)
	return
}
开发者ID:rechen,项目名称:wharf,代码行数:31,代码来源:manifestsv2.go


示例4: GetPrivateRepos

func (this *OrganizationWebV1Controller) GetPrivateRepos() {
	org := new(models.Organization)
	repos := make([]models.Repository, 0)

	if exist, _, err := org.Has(this.Ctx.Input.Param(":org")); err != nil {
		this.JSONOut(http.StatusBadRequest, err.Error(), nil)
		return
	} else if exist == false {
		this.JSONOut(http.StatusBadRequest, "Organization not exist", nil)
		return
	}

	for _, v := range org.Repositories {
		repo := new(models.Repository)

		if err := repo.Get(v); err != nil {
			this.JSONOut(http.StatusBadRequest, "Repository invalid", nil)
			return
		}

		if repo.Privated == true {
			repos = append(repos, *repo)
		}
	}

	this.JSONOut(http.StatusOK, "", repos)
	return
}
开发者ID:rechen,项目名称:wharf,代码行数:28,代码来源:orgwebv1.go


示例5: GetRepository

func (this *WebController) GetRepository() {
	namespace := this.Ctx.Input.Param(":namespace")
	repository := this.Ctx.Input.Param(":repository")

	repo := new(models.Repository)
	if exist, _, _ := repo.Has(namespace, repository); exist {
		user, exist := this.Ctx.Input.CruSession.Get("user").(models.User)
		if repo.Privated {
			if !exist == true {
				this.Abort("404")
				return
			} else {
				if user.Username != namespace {
					this.Abort("404")
					return
				}
				this.Data["username"] = user.Username
				this.Data["privated"] = repo.Privated
				this.Data["namespace"] = repo.Namespace
				this.Data["repository"] = repo.Repository
				this.Data["created"] = repo.Created
				this.Data["short"] = repo.Short
				this.Data["description"] = string(github_flavored_markdown.Markdown([]byte(repo.Description)))
				this.Data["download"] = repo.Download
				this.Data["comments"] = len(repo.Comments)
				this.Data["starts"] = len(repo.Starts)

				this.TplNames = "repository.html"
				this.Render()
				return
			}
		} else {
			this.Data["username"] = user.Username
			this.Data["privated"] = repo.Privated
			this.Data["namespace"] = repo.Namespace
			this.Data["repository"] = repo.Repository
			this.Data["created"] = repo.Created
			this.Data["short"] = repo.Short
			this.Data["description"] = string(github_flavored_markdown.Markdown([]byte(repo.Description)))
			this.Data["download"] = repo.Download
			this.Data["comments"] = len(repo.Comments)
			this.Data["starts"] = len(repo.Starts)

			this.TplNames = "repository.html"
			this.Render()
			return
		}
	} else {
		this.Abort("404")
		return
	}
	return
}
开发者ID:rechen,项目名称:wharf,代码行数:53,代码来源:web.go


示例6: GetRepositoryImages

func (this *RepoAPIV1Controller) GetRepositoryImages() {
	namespace := string(this.Ctx.Input.Param(":namespace"))
	repository := string(this.Ctx.Input.Param(":repo_name"))

	repo := new(models.Repository)

	if has, _, err := repo.Has(namespace, repository); err != nil {
		this.JSONOut(http.StatusBadRequest, "Read repository json error", nil)
		return
	} else if has == false {
		this.JSONOut(http.StatusBadRequest, "Read repository no found", nil)
		return
	}

	repo.Download += 1

	if err := repo.Save(); err != nil {
		this.JSONOut(http.StatusBadRequest, err.Error(), nil)
	}

	memo, _ := json.Marshal(this.Ctx.Input.Header)
	repo.Log(models.ACTION_GET_REPO, models.LEVELINFORMATIONAL, models.TYPE_APIV1, repo.Id, memo)

	this.Ctx.Output.Context.Output.SetStatus(http.StatusOK)
	this.Ctx.Output.Context.Output.Body([]byte(repo.JSON))
	return
}
开发者ID:rechen,项目名称:wharf,代码行数:27,代码来源:repoapiv1.go


示例7: PutRepositoryImages

func (this *RepoAPIV1Controller) PutRepositoryImages() {
	namespace := this.Ctx.Input.Param(":namespace")
	repository := this.Ctx.Input.Param(":repo_name")

	repo := new(models.Repository)

	if err := repo.PutImages(namespace, repository); err != nil {
		this.JSONOut(http.StatusBadRequest, "Update Uploaded flag error", nil)
		return
	}

	memo, _ := json.Marshal(this.Ctx.Input.Header)
	repo.Log(models.ACTION_PUT_REPO_IMAGES, models.LEVELINFORMATIONAL, models.TYPE_APIV1, repo.Id, memo)

	org := new(models.Organization)
	isOrg, _, err := org.Has(namespace)
	if err != nil {
		this.JSONOut(http.StatusBadRequest, "Search Organization Error", nil)
		return
	}

	user := new(models.User)
	authUsername, _, _ := utils.DecodeBasicAuth(this.Ctx.Input.Header("Authorization"))
	isUser, _, err := user.Has(authUsername)
	if err != nil {
		this.JSONOut(http.StatusBadRequest, err.Error(), nil)
		return
	}

	if !isUser && !isOrg {
		this.JSONOut(http.StatusBadRequest, "Search Namespace Error", nil)
		return
	}

	if isUser {
		user.Repositories = append(user.Repositories, repo.Id)
		user.Save()
	}
	if isOrg {
		org.Repositories = append(org.Repositories, repo.Id)
		org.Save()
	}

	this.Ctx.Output.Context.Output.SetStatus(http.StatusNoContent)
	this.Ctx.Output.Context.Output.Body([]byte(""))

	this.ServeJson()
	return
}
开发者ID:rechen,项目名称:wharf,代码行数:49,代码来源:repoapiv1.go


示例8: checkRepositoriesPrivate

func checkRepositoriesPrivate(namespace, repository string) bool {
	repo := new(models.Repository)

	if has, _, err := repo.Has(namespace, repository); err != nil || has == false {
		return false
	} else if has == true {
		if repo.Privated == true {
			return false
		} else {
			return true
		}
	}

	return false
}
开发者ID:rechen,项目名称:wharf,代码行数:15,代码来源:auth.go


示例9: checkOrgRepositoryPermission

func checkOrgRepositoryPermission(user *models.User, namespace, repository string, permission int) bool {
	owner := false

	//Check Org exists
	org := new(models.Organization)
	if has, _, _ := org.Has(namespace); has == false {
		return false
	}

	//Check Owner, don't care Join team
	for _, k := range user.Organizations {
		if org.Id == k {
			owner = true
		}
	}

	//Check Repository
	repo := new(models.Repository)
	if has, _, _ := repo.Has(namespace, repository); has == false {
		if owner == true {
			return true
		} else {
			return false
		}
	}

	if repo.Privated == false && permission == PERMISSION_READ {
		return true
	}

	//Loop Team
	for _, k := range user.JoinTeams {
		team := new(models.Team)

		if err := team.GetById(k); err != nil {
			return false
		}

		//TODO Check Team Perimssion

	}

	return false
}
开发者ID:rechen,项目名称:wharf,代码行数:44,代码来源:auth.go


示例10: PutManifests

func (this *ManifestsAPIV2Controller) PutManifests() {
	manifest, _ := ioutil.ReadAll(this.Ctx.Request.Body)

	namespace := this.Ctx.Input.Param(":namespace")
	repository := this.Ctx.Input.Param(":repo_name")

	repo := new(models.Repository)

	if err := repo.Put(namespace, repository, "", this.Ctx.Input.Header("User-Agent"), models.APIVERSION_V2); err != nil {
		this.JSONOut(http.StatusBadRequest, "", map[string][]modules.ErrorDescriptor{"errors": []modules.ErrorDescriptor{modules.ErrorDescriptors[modules.APIErrorCodeManifestInvalid]}})
		return
	}

	manifestsConvertV1(manifest)

	this.Ctx.Output.Context.Output.SetStatus(http.StatusOK)
	this.Ctx.Output.Context.Output.Body([]byte(""))
	return
}
开发者ID:rechen,项目名称:wharf,代码行数:19,代码来源:manifestsv2.go


示例11: PutTag

func (this *RepoAPIV1Controller) PutTag() {
	namespace := this.Ctx.Input.Param(":namespace")
	repository := this.Ctx.Input.Param(":repo_name")

	tag := this.Ctx.Input.Param(":tag")

	r, _ := regexp.Compile(`"([[:alnum:]]+)"`)
	imageIds := r.FindStringSubmatch(string(this.Ctx.Input.CopyBody()))

	repo := new(models.Repository)
	if err := repo.PutTag(imageIds[1], namespace, repository, tag); err != nil {
		this.JSONOut(http.StatusBadRequest, err.Error(), nil)
		return
	}

	memo, _ := json.Marshal(this.Ctx.Input.Header)
	repo.Log(models.ACTION_PUT_TAG, models.LEVELINFORMATIONAL, models.TYPE_APIV1, repo.Id, memo)

	this.Ctx.Output.Context.Output.SetStatus(http.StatusOK)
	this.Ctx.Output.Context.Output.Body([]byte(""))
	return
}
开发者ID:rechen,项目名称:wharf,代码行数:22,代码来源:repoapiv1.go


示例12: manifestsConvertV1

func manifestsConvertV1(data []byte) error {
	var manifest map[string]interface{}
	if err := json.Unmarshal(data, &manifest); err != nil {
		return err
	}

	tag := manifest["tag"]
	namespace, repository := strings.Split(manifest["name"].(string), "/")[0], strings.Split(manifest["name"].(string), "/")[1]

	for k := len(manifest["history"].([]interface{})) - 1; k >= 0; k-- {
		v := manifest["history"].([]interface{})[k]
		compatibility := v.(map[string]interface{})["v1Compatibility"].(string)

		var image map[string]interface{}
		if err := json.Unmarshal([]byte(compatibility), &image); err != nil {
			return err
		}

		i := map[string]string{}
		r := new(models.Repository)

		if k == 0 {
			i["Tag"] = tag.(string)
		}
		i["id"] = image["id"].(string)

		//Put V1 JSON
		if err := r.PutJSONFromManifests(i, namespace, repository); err != nil {
			return err
		}

		if k == 0 {
			//Put V1 Tag
			if err := r.PutTagFromManifests(image["id"].(string), namespace, repository, tag.(string), string(data)); err != nil {
				return err
			}
		}

		img := new(models.Image)

		tarsum := manifest["fsLayers"].([]interface{})[k].(map[string]interface{})["blobSum"].(string)
		sha256 := strings.Split(tarsum, ":")[1]

		//Put Image Json
		if err := img.PutJSON(image["id"].(string), v.(map[string]interface{})["v1Compatibility"].(string), models.APIVERSION_V2); err != nil {
			return err
		}

		//Put Image Layer
		basePath := beego.AppConfig.String("docker::BasePath")
		layerfile := fmt.Sprintf("%v/uuid/%v/layer", basePath, sha256)

		if err := img.PutLayer(image["id"].(string), layerfile, true, int64(image["Size"].(float64))); err != nil {
			return err
		}

		//Put Checksum
		if err := img.PutChecksum(image["id"].(string), sha256, true, ""); err != nil {
			return err
		}

		//Put Ancestry
		if err := img.PutAncestry(image["id"].(string)); err != nil {
			return err
		}
	}

	return nil
}
开发者ID:rechen,项目名称:wharf,代码行数:69,代码来源:common.go



注:本文中的github.com/containerops/wharf/models.Repository类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang models.Team类代码示例发布时间:2022-05-23
下一篇:
Golang models.Organization类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap