feat: kubesphere 4.0 (#6115)
* feat: kubesphere 4.0 Signed-off-by: ci-bot <ci-bot@kubesphere.io> * feat: kubesphere 4.0 Signed-off-by: ci-bot <ci-bot@kubesphere.io> --------- Signed-off-by: ci-bot <ci-bot@kubesphere.io> Co-authored-by: ks-ci-bot <ks-ci-bot@example.com> Co-authored-by: joyceliu <joyceliu@yunify.com>
This commit is contained in:
committed by
GitHub
parent
b5015ec7b9
commit
447a51f08b
@@ -1,30 +1,21 @@
|
||||
/*
|
||||
Copyright 2020 The KubeSphere Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
* Please refer to the LICENSE file in the root directory of the project.
|
||||
* https://github.com/kubesphere/kubesphere/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
package git
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"gopkg.in/src-d/go-git.v4"
|
||||
"gopkg.in/src-d/go-git.v4/config"
|
||||
"gopkg.in/src-d/go-git.v4/plumbing/transport/http"
|
||||
"gopkg.in/src-d/go-git.v4/storage/memory"
|
||||
"github.com/go-git/go-git/v5"
|
||||
"github.com/go-git/go-git/v5/config"
|
||||
"github.com/go-git/go-git/v5/plumbing/transport/http"
|
||||
"github.com/go-git/go-git/v5/storage/memory"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
"k8s.io/client-go/informers"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
runtimeclient "sigs.k8s.io/controller-runtime/pkg/client"
|
||||
)
|
||||
|
||||
type AuthInfo struct {
|
||||
@@ -37,19 +28,20 @@ type GitVerifier interface {
|
||||
}
|
||||
|
||||
type gitVerifier struct {
|
||||
informers informers.SharedInformerFactory
|
||||
cache runtimeclient.Reader
|
||||
}
|
||||
|
||||
func NewGitVerifier(informers informers.SharedInformerFactory) GitVerifier {
|
||||
return &gitVerifier{informers: informers}
|
||||
func NewGitVerifier(cacheReader runtimeclient.Reader) GitVerifier {
|
||||
return &gitVerifier{cache: cacheReader}
|
||||
}
|
||||
|
||||
func (c *gitVerifier) VerifyGitCredential(remoteUrl, namespace, secretName string) error {
|
||||
var username, password string
|
||||
|
||||
if len(secretName) > 0 {
|
||||
secret, err := c.informers.Core().V1().Secrets().Lister().Secrets(namespace).Get(secretName)
|
||||
if err != nil {
|
||||
secret := &corev1.Secret{}
|
||||
if err := c.cache.Get(context.Background(),
|
||||
types.NamespacedName{Namespace: namespace, Name: secretName}, secret); err != nil {
|
||||
return err
|
||||
}
|
||||
usernameBytes, ok := secret.Data[corev1.BasicAuthUsernameKey]
|
||||
@@ -69,7 +61,6 @@ func (c *gitVerifier) VerifyGitCredential(remoteUrl, namespace, secretName strin
|
||||
|
||||
func (c *gitVerifier) gitReadVerifyWithBasicAuth(username string, password string, remote string) error {
|
||||
r, _ := git.Init(memory.NewStorage(), nil)
|
||||
|
||||
// Add a new remote, with the default fetch refspec
|
||||
origin, err := r.CreateRemote(&config.RemoteConfig{
|
||||
Name: git.DefaultRemoteName,
|
||||
@@ -78,6 +69,6 @@ func (c *gitVerifier) gitReadVerifyWithBasicAuth(username string, password strin
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = origin.List(&git.ListOptions{Auth: &http.BasicAuth{Username: string(username), Password: string(password)}})
|
||||
_, err = origin.List(&git.ListOptions{Auth: &http.BasicAuth{Username: username, Password: password}})
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user