Przeglądaj źródła

Merge pull request #85 from rauls5382/tls

Merge commits from Go distribution
Raul Silvera 8 lat temu
rodzic
commit
2d6d840df8
2 zmienionych plików z 42 dodań i 28 usunięć
  1. 19
    3
      internal/driver/fetch.go
  2. 23
    25
      profile/legacy_profile.go

+ 19
- 3
internal/driver/fetch.go Wyświetl plik

@@ -16,6 +16,7 @@ package driver
16 16
 
17 17
 import (
18 18
 	"bytes"
19
+	"crypto/tls"
19 20
 	"fmt"
20 21
 	"io"
21 22
 	"io/ioutil"
@@ -487,12 +488,27 @@ func adjustURL(source string, duration, timeout time.Duration) (string, time.Dur
487 488
 
488 489
 // httpGet is a wrapper around http.Get; it is defined as a variable
489 490
 // so it can be redefined during for testing.
490
-var httpGet = func(url string, timeout time.Duration) (*http.Response, error) {
491
+var httpGet = func(source string, timeout time.Duration) (*http.Response, error) {
492
+	url, err := url.Parse(source)
493
+	if err != nil {
494
+		return nil, err
495
+	}
496
+
497
+	var tlsConfig *tls.Config
498
+	if url.Scheme == "https+insecure" {
499
+		tlsConfig = &tls.Config{
500
+			InsecureSkipVerify: true,
501
+		}
502
+		url.Scheme = "https"
503
+		source = url.String()
504
+	}
505
+
491 506
 	client := &http.Client{
492 507
 		Transport: &http.Transport{
493 508
 			ResponseHeaderTimeout: timeout + 5*time.Second,
494
-			Proxy: http.ProxyFromEnvironment,
509
+			Proxy:           http.ProxyFromEnvironment,
510
+			TLSClientConfig: tlsConfig,
495 511
 		},
496 512
 	}
497
-	return client.Get(url)
513
+	return client.Get(source)
498 514
 }

+ 23
- 25
profile/legacy_profile.go Wyświetl plik

@@ -710,15 +710,12 @@ func parseContention(b []byte) (*Profile, error) {
710 710
 	const delimiter = "="
711 711
 	for s.Scan() {
712 712
 		line := s.Text()
713
-
714
-		if line = strings.TrimSpace(line); line == "" {
713
+		if line = strings.TrimSpace(line); isSpaceOrComment(line) {
715 714
 			continue
716 715
 		}
717
-
718 716
 		if strings.HasPrefix(line, "---") {
719 717
 			break
720 718
 		}
721
-
722 719
 		attr := strings.SplitN(line, delimiter, 2)
723 720
 		if len(attr) != 2 {
724 721
 			break
@@ -761,30 +758,31 @@ func parseContention(b []byte) (*Profile, error) {
761 758
 		if strings.HasPrefix(line, "---") {
762 759
 			break
763 760
 		}
764
-		value, addrs, err := parseContentionSample(line, p.Period, cpuHz)
765
-		if err != nil {
766
-			return nil, err
767
-		}
768
-		var sloc []*Location
769
-		for _, addr := range addrs {
770
-			// Addresses from stack traces point to the next instruction after
771
-			// each call. Adjust by -1 to land somewhere on the actual call.
772
-			addr--
773
-			loc := locs[addr]
774
-			if locs[addr] == nil {
775
-				loc = &Location{
776
-					Address: addr,
761
+		if !isSpaceOrComment(line) {
762
+			value, addrs, err := parseContentionSample(line, p.Period, cpuHz)
763
+			if err != nil {
764
+				return nil, err
765
+			}
766
+			var sloc []*Location
767
+			for _, addr := range addrs {
768
+				// Addresses from stack traces point to the next instruction after
769
+				// each call. Adjust by -1 to land somewhere on the actual call.
770
+				addr--
771
+				loc := locs[addr]
772
+				if locs[addr] == nil {
773
+					loc = &Location{
774
+						Address: addr,
775
+					}
776
+					p.Location = append(p.Location, loc)
777
+					locs[addr] = loc
777 778
 				}
778
-				p.Location = append(p.Location, loc)
779
-				locs[addr] = loc
779
+				sloc = append(sloc, loc)
780 780
 			}
781
-			sloc = append(sloc, loc)
781
+			p.Sample = append(p.Sample, &Sample{
782
+				Value:    value,
783
+				Location: sloc,
784
+			})
782 785
 		}
783
-		p.Sample = append(p.Sample, &Sample{
784
-			Value:    value,
785
-			Location: sloc,
786
-		})
787
-
788 786
 		if !s.Scan() {
789 787
 			break
790 788
 		}