本文整理汇总了Golang中github.com/openshift/geard/git.RepoIdentifier.RepositoryPathFor方法的典型用法代码示例。如果您正苦于以下问题:Golang RepoIdentifier.RepositoryPathFor方法的具体用法?Golang RepoIdentifier.RepositoryPathFor怎么用?Golang RepoIdentifier.RepositoryPathFor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/openshift/geard/git.RepoIdentifier
的用法示例。
在下文中一共展示了RepoIdentifier.RepositoryPathFor方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: switchnsGit
func switchnsGit() {
var u *user.User
var err error
var repoId git.RepoIdentifier
uid := os.Getuid()
originalCommand := os.Getenv("SSH_ORIGINAL_COMMAND")
if u, err = user.LookupId(strconv.Itoa(uid)); err != nil {
fmt.Printf("Couldn't find user with uid %n\n", uid)
os.Exit(2)
}
if uid != 0 {
if !isValidGitCommand(originalCommand, !gitRw) {
fmt.Printf("Invalid git command: %s\n", originalCommand)
os.Exit(2)
}
if repoId, err = git.NewIdentifierFromUser(u); err != nil {
fmt.Printf("Couldn't create identifier for user %v\n", u)
os.Exit(2)
}
env := []string{fmt.Sprintf("HOME=%s", repoId.RepositoryPathFor())}
client, err := docker.GetConnection("unix:///var/run/docker.sock")
if err != nil {
fmt.Printf("Unable to connect to server\n")
os.Exit(3)
}
runCommandInContainer(client, "geard-githost", []string{"/usr/bin/git-shell", "-c", originalCommand}, env)
} else {
fmt.Println("Cannot switch into any git repo as root user")
os.Exit(2)
}
}
示例2: switchnsGit
func switchnsGit(cmd *cobra.Command, args []string) {
var u *user.User
var err error
var repoId git.RepoIdentifier
uid := os.Getuid()
originalCommand := os.Getenv("SSH_ORIGINAL_COMMAND")
if u, err = user.LookupId(strconv.Itoa(uid)); err != nil {
os.Exit(2)
}
if uid != 0 {
if !isValidGitCommand(originalCommand, !git_rw) {
os.Exit(2)
}
if repoId, err = git.NewIdentifierFromUser(u); err != nil {
os.Exit(2)
}
env := []string{fmt.Sprintf("HOME=%s", repoId.RepositoryPathFor())}
runCommand("geard-githost", []string{"/usr/bin/git-shell", "-c", originalCommand}, env)
} else {
fmt.Println("Cannot switch into any git repo as root user")
os.Exit(2)
}
}
示例3: InitializeRepository
func InitializeRepository(repositoryId git.RepoIdentifier, repositoryURL string) error {
var err error
if _, err = user.Lookup(repositoryId.LoginFor()); err != nil {
if _, ok := err.(user.UnknownUserError); !ok {
return err
}
if err = createUser(repositoryId); err != nil {
return err
}
}
if err := os.MkdirAll(repositoryId.HomePath(), 0700); err != nil {
return err
}
if err := os.MkdirAll(repositoryId.RepositoryPathFor(), 0700); err != nil {
return err
}
var u *user.User
if u, err = user.Lookup(repositoryId.LoginFor()); err != nil {
return err
}
uid, _ := strconv.Atoi(u.Uid)
gid, _ := strconv.Atoi(u.Gid)
if err = os.Chown(repositoryId.HomePath(), uid, gid); err != nil {
return err
}
if err = os.Chown(repositoryId.RepositoryPathFor(), uid, gid); err != nil {
return err
}
switchns := filepath.Join("/", "usr", "bin", "switchns")
cmd := exec.Command(switchns, "--container=geard-githost", "--", "/git/init-repo", repositoryId.RepositoryPathFor(), u.Uid, u.Gid, repositoryURL)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err = cmd.Run()
if err != nil {
return err
}
if err := selinux.RestoreCon(repositoryId.RepositoryPathFor(), true); err != nil {
return err
}
return nil
}