Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove more unused local proxy code #368

Merged
merged 2 commits into from
Sep 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 6 additions & 63 deletions internal/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/docker/go-units"
"github.com/goware/urlx"
"github.com/infrahq/infra/internal/api"
"github.com/infrahq/infra/internal/certs"
"github.com/infrahq/infra/internal/engine"
"github.com/infrahq/infra/internal/generate"
"github.com/infrahq/infra/internal/logging"
Expand Down Expand Up @@ -501,50 +500,6 @@ func login(config *Config) error {

fmt.Fprintln(os.Stderr, blue("✓")+" Logged in as "+termenv.String(loginRes.Name).Bold().String())

// Generate client certs
home, err := homedir.Dir()
if err != nil {
return err
}

if err = os.MkdirAll(filepath.Join(home, ".infra", "client"), os.ModePerm); err != nil {
return err
}

if _, err := os.Stat(filepath.Join(home, ".infra", "client", "cert.pem")); os.IsNotExist(err) {
certBytes, keyBytes, err := certs.SelfSignedCert([]string{"localhost", "localhost:32710"})
if err != nil {
return err
}

if err = ioutil.WriteFile(filepath.Join(home, ".infra", "client", "cert.pem"), certBytes, 0o644); err != nil {
return err
}

if err = ioutil.WriteFile(filepath.Join(home, ".infra", "client", "key.pem"), keyBytes, 0o644); err != nil {
return err
}

// Kill client
contents, err := ioutil.ReadFile(filepath.Join(home, ".infra", "client", "pid"))
if err != nil && !os.IsNotExist(err) {
return err
}

var pid int
if !os.IsNotExist(err) {
pid, err = strconv.Atoi(string(contents))
if err != nil {
return err
}

process, _ := os.FindProcess(int(pid))
process.Kill()
}

os.Remove(filepath.Join(home, ".infra", "client", "pid"))
}

client, err = NewApiClient(config.Host, skipTLSVerify)
if err != nil {
return err
Expand All @@ -561,9 +516,14 @@ func login(config *Config) error {
return err
}

homeDir, err := os.UserHomeDir()
if err != nil {
return err
}

if len(destinations) > 0 {
kubeConfigPath := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(clientcmd.NewDefaultClientConfigLoadingRules(), &clientcmd.ConfigOverrides{}).ConfigAccess().GetDefaultFilename()
fmt.Fprintln(os.Stderr, blue("✓")+" Kubeconfig updated: "+termenv.String(strings.ReplaceAll(kubeConfigPath, home, "~")).Bold().String())
fmt.Fprintln(os.Stderr, blue("✓")+" Kubeconfig updated: "+termenv.String(strings.ReplaceAll(kubeConfigPath, homeDir, "~")).Bold().String())
}

context, err := switchToFirstInfraContext()
Expand Down Expand Up @@ -621,23 +581,6 @@ var logoutCmd = &cobra.Command{
return err
}

contents, err := ioutil.ReadFile(filepath.Join(home, ".infra", "client", "pid"))
if err != nil && !os.IsNotExist(err) {
return err
}

var pid int
if !os.IsNotExist(err) {
pid, err = strconv.Atoi(string(contents))
if err != nil {
return err
}

process, _ := os.FindProcess(int(pid))
process.Kill()
}

os.Remove(filepath.Join(home, ".infra", "client", "pid"))
os.Remove(filepath.Join(home, ".infra", "destinations"))

return updateKubeconfig([]api.Destination{})
Expand Down
4 changes: 2 additions & 2 deletions internal/registry/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ type Destination struct {
Name string `gorm:"unique"`
Type string

KubernetesCa string
KubernetesEndpoint string
KubernetesCa string
KubernetesEndpoint string
}

type Role struct {
Expand Down