Skip to content

Commit 90e3079

Browse files
author
Jim Minter
committed
plumbing
1 parent 013c229 commit 90e3079

File tree

26 files changed

+134
-269
lines changed

26 files changed

+134
-269
lines changed

pkg/bootstrap/docker/dockerhelper/filetransfer.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
"github.com/docker/engine-api/types"
1313
s2itar "github.com/openshift/source-to-image/pkg/tar"
14-
s2iutil "github.com/openshift/source-to-image/pkg/util"
14+
s2ifs "github.com/openshift/source-to-image/pkg/util/fs"
1515
)
1616

1717
// removeLeadingDirectoryAdapter wraps a tar.Reader and strips the first leading
@@ -106,15 +106,15 @@ func DownloadDirFromContainer(client Interface, container, src, dst string) erro
106106
defer response.Close()
107107
tarReader := &removeLeadingDirectoryAdapter{Reader: tar.NewReader(response)}
108108

109-
t := s2itar.New(s2iutil.NewFileSystem())
109+
t := s2itar.New(s2ifs.NewFileSystem())
110110
return t.ExtractTarStreamFromTarReader(dst, tarReader, nil)
111111
}
112112

113113
// UploadFileToContainer uploads a file to a remote container.
114114
func UploadFileToContainer(client Interface, container, src, dest string) error {
115115
uploader, errch := newContainerUploader(client, container, path.Dir(dest))
116116

117-
t := s2itar.New(s2iutil.NewFileSystem())
117+
t := s2itar.New(s2ifs.NewFileSystem())
118118
tarWriter := s2itar.RenameAdapter{Writer: tar.NewWriter(uploader), Old: filepath.Base(src), New: path.Base(dest)}
119119

120120
err := t.CreateTarStreamToTarWriter(src, true, tarWriter, nil)

pkg/build/builder/cmd/builder.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
kapi "k8s.io/kubernetes/pkg/api"
1919

2020
s2iapi "github.com/openshift/source-to-image/pkg/api"
21+
s2igit "github.com/openshift/source-to-image/pkg/scm/git"
2122

2223
buildapi "github.com/openshift/origin/pkg/build/apis/build"
2324
"github.com/openshift/origin/pkg/build/apis/build/validation"
@@ -123,7 +124,7 @@ func (c *builderConfig) setupGitEnvironment() (string, []string, error) {
123124
if sourceSecret != nil {
124125
// TODO: this should be refactored to let each source type manage which secrets
125126
// it accepts
126-
sourceURL, err := git.ParseRepository(gitSource.URI)
127+
sourceURL, err := s2igit.Parse(gitSource.URI)
127128
if err != nil {
128129
return "", nil, fmt.Errorf("cannot parse build URL: %s", gitSource.URI)
129130
}

pkg/build/builder/cmd/scmauth/cacert.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ package scmauth
33
import (
44
"fmt"
55
"io/ioutil"
6-
"net/url"
76
"path/filepath"
8-
"strings"
7+
8+
s2igit "github.com/openshift/source-to-image/pkg/scm/git"
99
)
1010

1111
const (
@@ -18,12 +18,12 @@ const (
1818

1919
// CACert implements SCMAuth interface for using a custom certificate authority
2020
type CACert struct {
21-
SourceURL url.URL
21+
SourceURL s2igit.URL
2222
}
2323

2424
// Setup creates a .gitconfig fragment that points to the given ca.crt
2525
func (s CACert) Setup(baseDir string, context SCMAuthContext) error {
26-
if strings.ToLower(s.SourceURL.Scheme) != "https" {
26+
if !(s.SourceURL.Type == s2igit.URLTypeURL && s.SourceURL.URL.Scheme == "https" && s.SourceURL.URL.Opaque == "") {
2727
return nil
2828
}
2929
gitconfig, err := ioutil.TempFile("", "ca.crt.")

pkg/build/builder/cmd/scmauth/cacert_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package scmauth
22

33
import (
4-
"net/url"
54
"os"
65
"testing"
6+
7+
"github.com/openshift/source-to-image/pkg/scm/git"
78
)
89

910
func TestCACertHandles(t *testing.T) {
@@ -19,7 +20,7 @@ func TestCACertHandles(t *testing.T) {
1920
func TestCACertSetup(t *testing.T) {
2021
context := NewDefaultSCMContext()
2122
caCert := &CACert{
22-
SourceURL: url.URL{Scheme: "https", Host: "my.host", Path: "git/repo"},
23+
SourceURL: *git.MustParse("https://my.host/git/repo"),
2324
}
2425
secretDir := secretDir(t, "ca.crt")
2526
defer os.RemoveAll(secretDir)
@@ -36,7 +37,7 @@ func TestCACertSetup(t *testing.T) {
3637
func TestCACertSetupNoSSL(t *testing.T) {
3738
context := NewDefaultSCMContext()
3839
caCert := &CACert{
39-
SourceURL: url.URL{Scheme: "http", Host: "my.host", Path: "git/repo"},
40+
SourceURL: *git.MustParse("http://my.host/git/repo"),
4041
}
4142
secretDir := secretDir(t, "ca.crt")
4243
defer os.RemoveAll(secretDir)

pkg/build/builder/cmd/scmauth/password.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import (
66
"net/url"
77
"os"
88
"path/filepath"
9-
"strings"
109

1110
"github.com/openshift/origin/pkg/util/file"
11+
12+
s2igit "github.com/openshift/source-to-image/pkg/scm/git"
1213
)
1314

1415
const (
@@ -25,14 +26,16 @@ const (
2526

2627
// UsernamePassword implements SCMAuth interface for using Username and Password credentials
2728
type UsernamePassword struct {
28-
SourceURL url.URL
29+
SourceURL s2igit.URL
2930
}
3031

3132
// Setup creates a gitconfig fragment that includes a substitution URL with the username/password
3233
// included in the URL. Returns source URL stripped of username/password credentials.
3334
func (u UsernamePassword) Setup(baseDir string, context SCMAuthContext) error {
3435
// Only apply to https and http URLs
35-
if scheme := strings.ToLower(u.SourceURL.Scheme); scheme != "http" && scheme != "https" {
36+
if !(u.SourceURL.Type == s2igit.URLTypeURL &&
37+
(u.SourceURL.URL.Scheme == "http" || u.SourceURL.URL.Scheme == "https") &&
38+
u.SourceURL.URL.Opaque == "") {
3639
return nil
3740
}
3841

@@ -51,7 +54,7 @@ func (u UsernamePassword) Setup(baseDir string, context SCMAuthContext) error {
5154
}
5255

5356
// Determine overrides
54-
overrideSourceURL, gitconfigURL, err := doSetup(u.SourceURL, usernameSecret, passwordSecret, tokenSecret)
57+
overrideSourceURL, gitconfigURL, err := doSetup(u.SourceURL.URL, usernameSecret, passwordSecret, tokenSecret)
5558
if err != nil {
5659
return err
5760
}

pkg/build/builder/cmd/scmauth/scmauths.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ import (
77
"os"
88

99
"github.com/golang/glog"
10+
11+
s2igit "github.com/openshift/source-to-image/pkg/scm/git"
1012
)
1113

1214
type SCMAuths []SCMAuth
1315

14-
func GitAuths(sourceURL *url.URL) SCMAuths {
16+
func GitAuths(sourceURL *s2igit.URL) SCMAuths {
1517
auths := SCMAuths{
1618
&SSHPrivateKey{},
1719
&UsernamePassword{SourceURL: *sourceURL},

pkg/build/builder/docker.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
s2iapi "github.com/openshift/source-to-image/pkg/api"
2020
"github.com/openshift/source-to-image/pkg/tar"
2121
"github.com/openshift/source-to-image/pkg/util"
22-
s2iutil "github.com/openshift/source-to-image/pkg/util"
22+
s2ifs "github.com/openshift/source-to-image/pkg/util/fs"
2323

2424
buildapi "github.com/openshift/origin/pkg/build/apis/build"
2525
"github.com/openshift/origin/pkg/build/builder/cmd/dockercfg"
@@ -50,7 +50,7 @@ func NewDockerBuilder(dockerClient DockerClient, buildsClient client.BuildInterf
5050
dockerClient: dockerClient,
5151
build: build,
5252
gitClient: gitClient,
53-
tar: tar.New(s2iutil.NewFileSystem()),
53+
tar: tar.New(s2ifs.NewFileSystem()),
5454
client: buildsClient,
5555
cgLimits: cgLimits,
5656
}

pkg/build/builder/docker_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
kapi "k8s.io/kubernetes/pkg/api"
1515

1616
"github.com/openshift/source-to-image/pkg/tar"
17-
s2iutil "github.com/openshift/source-to-image/pkg/util"
17+
s2ifs "github.com/openshift/source-to-image/pkg/util/fs"
1818

1919
buildapi "github.com/openshift/origin/pkg/build/apis/build"
2020
"github.com/openshift/origin/pkg/build/util/dockerfile"
@@ -261,7 +261,7 @@ func TestDockerfilePath(t *testing.T) {
261261
dockerClient: dockerClient,
262262
build: build,
263263
gitClient: git.NewRepository(),
264-
tar: tar.New(s2iutil.NewFileSystem()),
264+
tar: tar.New(s2ifs.NewFileSystem()),
265265
}
266266

267267
// this will validate that the Dockerfile is readable
@@ -385,7 +385,7 @@ USER 1001`
385385
build: build,
386386
dockerClient: dockerClient,
387387
gitClient: git.NewRepository(),
388-
tar: tar.New(s2iutil.NewFileSystem()),
388+
tar: tar.New(s2ifs.NewFileSystem()),
389389
}
390390

391391
if err := dockerBuilder.Build(); err != nil {

pkg/build/builder/source.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
docker "github.com/fsouza/go-dockerclient"
1515

1616
s2igit "github.com/openshift/source-to-image/pkg/scm/git"
17-
s2iutil "github.com/openshift/source-to-image/pkg/util"
17+
s2ifs "github.com/openshift/source-to-image/pkg/util/fs"
1818

1919
buildapi "github.com/openshift/origin/pkg/build/apis/build"
2020
"github.com/openshift/origin/pkg/build/builder/cmd/dockercfg"
@@ -167,13 +167,10 @@ func checkRemoteGit(gitClient GitClient, url string, initialTimeout time.Duratio
167167
// checkSourceURI performs a check on the URI associated with the build
168168
// to make sure that it is valid.
169169
func checkSourceURI(gitClient GitClient, rawurl string, timeout time.Duration) error {
170-
ok, err := s2igit.New(s2iutil.NewFileSystem()).ValidCloneSpec(rawurl)
170+
_, err := s2igit.Parse(rawurl)
171171
if err != nil {
172172
return fmt.Errorf("Invalid git source url %q: %v", rawurl, err)
173173
}
174-
if !ok {
175-
return fmt.Errorf("Invalid git source url: %s", rawurl)
176-
}
177174
return checkRemoteGit(gitClient, rawurl, timeout)
178175
}
179176

@@ -391,7 +388,7 @@ func extractSourceFromImage(ctx context.Context, dockerClient DockerClient, imag
391388
}
392389
defer dockerClient.RemoveContainer(docker.RemoveContainerOptions{ID: container.ID})
393390

394-
tarHelper := tar.New(s2iutil.NewFileSystem())
391+
tarHelper := tar.New(s2ifs.NewFileSystem())
395392
tarHelper.SetExclusionPattern(nil)
396393

397394
for _, path := range paths {

pkg/build/builder/sti.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
s2ibuild "github.com/openshift/source-to-image/pkg/build"
1919
s2i "github.com/openshift/source-to-image/pkg/build/strategies"
2020
"github.com/openshift/source-to-image/pkg/docker"
21+
s2igit "github.com/openshift/source-to-image/pkg/scm/git"
2122

2223
buildapi "github.com/openshift/origin/pkg/build/apis/build"
2324
"github.com/openshift/origin/pkg/build/builder/cmd/dockercfg"
@@ -169,7 +170,7 @@ func (s *S2IBuilder) Build() error {
169170
}
170171
}
171172

172-
var s2iSourceInfo *s2iapi.SourceInfo
173+
var s2iSourceInfo *s2igit.SourceInfo
173174
if sourceInfo != nil {
174175
s2iSourceInfo = &sourceInfo.SourceInfo
175176
revision := updateBuildRevision(s.build, sourceInfo)
@@ -220,7 +221,7 @@ func (s *S2IBuilder) Build() error {
220221
Labels: buildLabels(s.build),
221222
DockerNetworkMode: getDockerNetworkMode(),
222223

223-
Source: srcDir,
224+
Source: &s2igit.URL{URL: url.URL{Path: srcDir}, Type: s2igit.URLTypeLocal},
224225
ContextDir: contextDir,
225226
SourceInfo: s2iSourceInfo,
226227
ForceCopy: true,
@@ -382,13 +383,13 @@ func (s *S2IBuilder) Build() error {
382383
}
383384

384385
type downloader struct {
385-
sourceInfo *s2iapi.SourceInfo
386+
sourceInfo *s2igit.SourceInfo
386387
}
387388

388389
// Download no-ops (because we already downloaded the source to the right location)
389390
// and returns the previously computed sourceInfo for the source.
390-
func (d *downloader) Download(config *s2iapi.Config) (*s2iapi.SourceInfo, error) {
391-
config.WorkingSourceDir = config.Source
391+
func (d *downloader) Download(config *s2iapi.Config) (*s2igit.SourceInfo, error) {
392+
config.WorkingSourceDir = config.Source.LocalPath()
392393

393394
return d.sourceInfo, nil
394395
}

pkg/cmd/cli/cmd/rsync/copytar.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"github.com/spf13/cobra"
1717
kerrors "k8s.io/apimachinery/pkg/util/errors"
1818

19-
s2iutil "github.com/openshift/source-to-image/pkg/util"
19+
s2ifs "github.com/openshift/source-to-image/pkg/util/fs"
2020

2121
"github.com/openshift/origin/pkg/cmd/util/clientcmd"
2222
)
@@ -37,7 +37,7 @@ type tarStrategy struct {
3737

3838
func newTarStrategy(f *clientcmd.Factory, c *cobra.Command, o *RsyncOptions) (copyStrategy, error) {
3939

40-
tarHelper := tar.New(s2iutil.NewFileSystem())
40+
tarHelper := tar.New(s2ifs.NewFileSystem())
4141
tarHelper.SetExclusionPattern(nil)
4242

4343
ignoredFlags := rsyncSpecificFlags(o)

pkg/cmd/cli/cmd/startbuild.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
"github.com/spf13/cobra"
2020

2121
"github.com/openshift/source-to-image/pkg/tar"
22-
s2iutil "github.com/openshift/source-to-image/pkg/util"
22+
s2ifs "github.com/openshift/source-to-image/pkg/util/fs"
2323

2424
kerrors "k8s.io/apimachinery/pkg/api/errors"
2525
"k8s.io/apimachinery/pkg/api/meta"
@@ -599,7 +599,7 @@ func streamPathToBuild(repo git.Repository, in io.Reader, out io.Writer, client
599599
pr, pw := io.Pipe()
600600
go func() {
601601
w := gzip.NewWriter(pw)
602-
if err := tar.New(s2iutil.NewFileSystem()).CreateTarStream(path, false, w); err != nil {
602+
if err := tar.New(s2ifs.NewFileSystem()).CreateTarStream(path, false, w); err != nil {
603603
pw.CloseWithError(err)
604604
} else {
605605
w.Close()

pkg/diagnostics/network/results.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"strconv"
1212

1313
"github.com/openshift/source-to-image/pkg/tar"
14-
s2iutil "github.com/openshift/source-to-image/pkg/util"
14+
s2ifs "github.com/openshift/source-to-image/pkg/util/fs"
1515

1616
kerrs "k8s.io/apimachinery/pkg/util/errors"
1717
kapi "k8s.io/kubernetes/pkg/api"
@@ -93,7 +93,7 @@ func (d *NetworkDiagnostic) copyNetworkPodInfo(pod *kapi.Pod) error {
9393
}
9494
defer tmp.Close()
9595

96-
tarHelper := tar.New(s2iutil.NewFileSystem())
96+
tarHelper := tar.New(s2ifs.NewFileSystem())
9797
tarHelper.SetExclusionPattern(nil)
9898
logdir := filepath.Join(d.LogDir, util.NetworkDiagNodeLogDirPrefix, pod.Spec.NodeName)
9999
err = tarHelper.ExtractTarStream(logdir, tmp)

0 commit comments

Comments
 (0)