Skip to content

Commit

Permalink
fix bbc auth vars used in testing; remove a bunch of debug prints
Browse files Browse the repository at this point in the history
Signed-off-by: Tony Worm <tony@hofstadter.io>
  • Loading branch information
verdverm committed Sep 13, 2021
1 parent 132b89d commit 75dff8e
Show file tree
Hide file tree
Showing 11 changed files with 12 additions and 28 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/test_mod.cue
Expand Up @@ -16,7 +16,8 @@ common.#Workflow & {
HOFMOD_SSHKEY: "${{secrets.HOFMOD_SSHKEY}}"
GITHUB_TOKEN: "${{secrets.HOFMOD_TOKEN}}"
GITLAB_TOKEN: "${{secrets.GITLAB_TOKEN}}"
BITBUCKET_TOKEN: "${{secrets.BITBUCKET_TOKEN}}"
BITBUCKET_USERNAME: "hofstadter"
BITBUCKET_PASSWORD: "${{secrets.BITBUCKET_TOKEN}}"
}
}]
}
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/test_mod.yml
Expand Up @@ -37,4 +37,5 @@ jobs:
HOFMOD_SSHKEY: ${{secrets.HOFMOD_SSHKEY}}
GITHUB_TOKEN: ${{secrets.HOFMOD_TOKEN}}
GITLAB_TOKEN: ${{secrets.GITLAB_TOKEN}}
BITBUCKET_TOKEN: ${{secrets.BITBUCKET_TOKEN}}
BITBUCKET_USERNAME: hofstadter
BITBUCKET_PASSWORD: ${{secrets.BITBUCKET_TOKEN}}
1 change: 0 additions & 1 deletion lib/mod/cache/fetch.go
Expand Up @@ -42,7 +42,6 @@ func fetch(lang, mod, ver string, private bool) error {
remote, owner, repo := parseModURL(mod)
tag := ver

fmt.Println("mod/cache.fetch:", lang, remote, owner, repo, ver, private)
// TODO, how to deal with self-hosted / enterprise repos?

switch remote {
Expand Down
5 changes: 4 additions & 1 deletion lib/mod/testdata/authd/sshkey/vendor__priv_all.txt
@@ -1,9 +1,12 @@
# hof mod vendor - with deps

env CUEPRIVATE="github.com,gitlab.com,bitbucket.org"

## blankout token vars for this test
env GITHUB_TOKEN=""
env GITLAB_TOKEN=""
env BITBUCKET_TOKEN=""
env BITBUCKET_USERNAME=""
env BITBUCKET_PASSWORD=""

## setup default sshkey auth
mkdir $HOME/.ssh
Expand Down
2 changes: 0 additions & 2 deletions lib/yagu/git.go
@@ -1,7 +1,6 @@
package yagu

import (
"fmt"
"io/ioutil"
"os"
"strings"
Expand Down Expand Up @@ -71,7 +70,6 @@ func SetupGitOptions(srcUrl, srcVer string) (*git.CloneOptions, error) {
}

func SetupGitAuth(srcUrl, srcVer string, co *git.CloneOptions) error {
fmt.Println("SetupGitAuth")

// GitHub variations
if strings.Contains(srcUrl, "github.com") {
Expand Down
4 changes: 0 additions & 4 deletions lib/yagu/repos/bbc/fetch.go
Expand Up @@ -16,12 +16,10 @@ import (
)

func Fetch(FS billy.Filesystem, owner, repo, tag string, private bool) (error) {
fmt.Println("bbc.Fetch", owner, repo, tag, private)

// If private, and no token auth, try git protocol
// need to catch auth errors and suggest how to setup
if private && os.Getenv(TokenEnv) == "" {
fmt.Println("bitbucket git fallback")
return git.Fetch(FS, "bitbucket.org", owner, repo, tag, private)
}

Expand Down Expand Up @@ -64,7 +62,6 @@ func Fetch(FS billy.Filesystem, owner, repo, tag string, private bool) (error) {

zReader, err = FetchTagZip(owner, repo, T.Name)
if err != nil {
fmt.Printf("Error: %v\n", err)
return fmt.Errorf("While fetching tag zipfile\n%w\n", err)
}
}
Expand All @@ -81,7 +78,6 @@ func Fetch(FS billy.Filesystem, owner, repo, tag string, private bool) (error) {
}

func FetchTagZip(owner, repo, ver string) (*zip.Reader, error) {
fmt.Println("bbc.FetchTagZip")

// url := *tag.ZipballURL
url := fmt.Sprintf("https://bitbucket.org/%s/%s/get/%s.zip", owner, repo, ver)
Expand Down
5 changes: 4 additions & 1 deletion lib/yagu/repos/bbc/info.go
Expand Up @@ -35,7 +35,6 @@ func GetRepo(client *bitbucket.Client, owner, repo string) (*bitbucket.Repositor
RepoSlug: repo,
}
r, err := client.Repositories.Repository.Get(ro)
fmt.Printf("bbc.GetRepo\n%# v\n%v\n", *r, err)
return r, err
}

Expand All @@ -58,6 +57,10 @@ func GetBranches(client *bitbucket.Client, owner, repo, branch string) ([]bitbuc
}

func GetTags(client *bitbucket.Client, owner, repo string) ([]bitbucket.RepositoryTag, error) {
_, err := GetRepo(client, owner, repo)
if err != nil {
return nil, err
}
ro := &bitbucket.RepositoryTagOptions{
Owner: owner,
RepoSlug: repo,
Expand Down
5 changes: 0 additions & 5 deletions lib/yagu/repos/git/fetch.go
Expand Up @@ -113,20 +113,15 @@ func Fetch(FS billy.Filesystem, remote, owner, repo, tag string, private bool) e
}

if private {
fmt.Println("git.Fetch")
if netrc, err := yagu.NetrcCredentials(remote); err == nil {
fmt.Println("NetRC")
gco.Auth = &http.BasicAuth{
Username: netrc.Login,
Password: netrc.Password,
}
} else if ssh, err := yagu.SSHCredentials(remote); err == nil {
fmt.Println("SSHCreds")
gco.Auth = ssh.Keys
gco.URL = fmt.Sprintf("%s@%s:%s", ssh.User, remote, srcRepo)
fmt.Println("URL:", gco.URL)
} else {
fmt.Println("NoAuth")
gco.URL = fmt.Sprintf("%s@%s:%s", "git", remote, srcRepo)
}
}
Expand Down
1 change: 0 additions & 1 deletion lib/yagu/repos/git/index.go
Expand Up @@ -11,7 +11,6 @@ import (
// given a git url, and a req (required) version
// returns the minReference, allRefferences, and error
func IndexGitRemote(url, req string) (*plumbing.Reference, []*plumbing.Reference, error) {
fmt.Println("indexing:", url, req)

if !semver.IsValid(req) {
return nil, nil, fmt.Errorf("Invalid SemVer v2 %q", req)
Expand Down
4 changes: 0 additions & 4 deletions lib/yagu/repos/github/fetch.go
Expand Up @@ -16,12 +16,10 @@ import (
)

func Fetch(FS billy.Filesystem, owner, repo, tag string, private bool) (error) {
fmt.Println("github.Fetch", owner, repo, tag, private)

// If private, and no token auth, try git protocol
// need to catch auth errors and suggest how to setup
if private && os.Getenv(TokenEnv) == "" {
fmt.Println("github git fallback")
return git.Fetch(FS, "github.com", owner, repo, tag, private)
}

Expand Down Expand Up @@ -54,7 +52,6 @@ func Fetch(FS billy.Filesystem, owner, repo, tag string, private bool) (error) {
for _, t := range tags {
if tag != "" && tag == *t.Name {
T = t
// fmt.Printf("FOUND %v\n", *t.Name)
}
}

Expand All @@ -64,7 +61,6 @@ func Fetch(FS billy.Filesystem, owner, repo, tag string, private bool) (error) {

zReader, err = FetchTagZip(T)
if err != nil {
fmt.Printf("Error: %v\n", err)
return fmt.Errorf("While fetching tag zipfile\n%w\n", err)
}
}
Expand Down
7 changes: 0 additions & 7 deletions lib/yagu/ssh.go
@@ -1,7 +1,6 @@
package yagu

import (
"fmt"
"os"
"path/filepath"
"strings"
Expand All @@ -16,7 +15,6 @@ type SSHMachine struct {
}

func SSHCredentials(machine string) (SSHMachine, error) {
fmt.Println("ssh.CredsLookup")
pub := ""
usr := "git"

Expand All @@ -27,7 +25,6 @@ func SSHCredentials(machine string) (SSHMachine, error) {

// look for env var key location
if key := os.Getenv("HOF_SSHKEY"); key != "" {
fmt.Println("ssh.SSHEnvVar")
pks, err := ssh.NewPublicKeysFromFile(usr, key, "")
if err != nil {
return SSHMachine{}, err
Expand All @@ -46,15 +43,12 @@ func SSHCredentials(machine string) (SSHMachine, error) {
_, uerr := os.Lstat(filepath.Join(hdir, ".ssh", "config"))
_, serr := os.Lstat(filepath.Join("etc", "ssh", "ssh_config"))
if uerr == nil || serr == nil {
fmt.Println("ssh.SSHConfig")
return getSSHConfigVals(machine)
}

// fallback on default pubkey
fmt.Println("ssh.DefaultPubkey")
pub = filepath.Join(hdir, ".ssh", "id_rsa")
pks, err := ssh.NewPublicKeysFromFile(usr, pub, "")
fmt.Println("err:", err)
if err != nil {
return SSHMachine{}, err
}
Expand All @@ -66,7 +60,6 @@ func getSSHConfigVals(machine string) (SSHMachine, error) {
// try to lookup the machine in config
pub, err := ssh_config.GetStrict(machine, "IdentityFile")
if err != nil {
fmt.Println(pub, err)
return SSHMachine{}, err
}

Expand Down

0 comments on commit 75dff8e

Please sign in to comment.