Skip to content

Commit

Permalink
Refactoring: Read endpoints from external csv file
Browse files Browse the repository at this point in the history
  • Loading branch information
reoim committed Sep 15, 2019
1 parent 87d2c1b commit 8b129fe
Show file tree
Hide file tree
Showing 12 changed files with 272 additions and 366 deletions.
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,42 @@ Use "pingcloud-cli [command] --help" for more information about a command.
2. Run `GO111MODULE=on go mod vendor`
3. Run `go build -v`
4. Run `go install`
5. Set Environment variable `PINGCLOUD_DIR` as your pingcloud-cli directory(absolute path).
* Linux & Mac

Add following code to your `.profile` or `.bash_profile`.

Make sure change `[YOUR pingcloud-cli DIR]` to absolute path of the git cloned directory.
```
# pingcloud-cli settings
export PINGCLOUD_DIR="[YOUR pingcloud-cli DIR]"
```
Restart terminal and check if `PINGCLOUD_DIR` is set proferly.
```
echo $PINGCLOUD_DIR
```
Output should be like this (example)
```
/Users/reolee/Downloads/pingcloud-cli
```
* Windows

1. Open **System** in **Control panel**
2. In the **System** window, click the **Advanced system settings**
3. In the System Properties window, click on the **Advanced** tab, then click the **Environment Variables** button near the bottom of the tab
![windows env setting](/assets/images/winenv.jpg)
4. In the Environment Variables window, click the **New** button of the **User variables** section
5. Set **Variable name** as `PINGCLOUD_DIR`
6. Set **Variable value** as absolute path of `pingcloud-cli` directory like as shown below.
```
C:\Users\reolee\Downloads\pingcloud-cli
```
7. Click **OK** button
8. Open new cmd and run `echo %PINGCLOUD_DIR%`
9. Output should be like this (example)
```
C:\Users\reolee\Downloads\pingcloud-cli
```


## Usage
Expand Down Expand Up @@ -94,6 +130,12 @@ List all region codes and region names of the cloud provider. Add -l or --list f

![pingcloud-cli gcp -l](/assets/images/gcp-list.png)

### Add/Edit/Delete regions
You can add/edit/delete regions by manifulating endpoints CSV files.

The CSV files of cloud platforms are located in `pingcloud-cli/endpoints` folder.

Make sure you follw the original csv format of the files.


## Notes
Expand All @@ -113,3 +155,8 @@ So latencies from Azure are relatively high compare to AWS and GCP because it ne
Changed Azure test endpoints https -> http.

No more TLS handshaking time.

### 2019-09-16
Removed endpoint information from code.

pingcloud-cli will read the endpoint information from external csv files which can be edited anytime by user.
Binary file added assets/images/winenv.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
67 changes: 7 additions & 60 deletions cmd/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@ limitations under the License.
package cmd

import (
"fmt"
"os"
"text/tabwriter"

"github.com/reoim/pingcloud-cli/ping"
"github.com/reoim/pingcloud-cli/ping/aws"
"github.com/spf13/cobra"
)

Expand All @@ -30,62 +25,14 @@ var awsCmd = &cobra.Command{
Use: "aws",
Short: "Check latencies of AWS regions.",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("")
if list {

// Init tabwriter
tr := tabwriter.NewWriter(os.Stdout, 40, 8, 2, '\t', 0)
fmt.Fprintf(tr, "AWS Region Code\tAWS Region Name")
fmt.Fprintln(tr)
fmt.Fprintf(tr, "------------------------------\t------------------------------")
fmt.Fprintln(tr)
for r, n := range aws.AWSRegions {
fmt.Fprintf(tr, "[%v]\t[%v]", r, n)
fmt.Fprintln(tr)
}
// Flush tabwriter
tr.Flush()
} else if len(args) == 0 {

// Init tabwriter
tr := tabwriter.NewWriter(os.Stdout, 40, 8, 2, '\t', 0)
fmt.Fprintf(tr, "AWS Region Code\tAWS Region Name\tLatency")
fmt.Fprintln(tr)
fmt.Fprintf(tr, "------------------------------\t------------------------------\t------------------------------")
fmt.Fprintln(tr)

// Flush tabwriter
tr.Flush()

for r, i := range aws.AWSEndpoints {
p := ping.PingDto{
Region: r,
Name: aws.AWSRegions[r],
Address: i,
}
p.Ping()
}
fmt.Println("")
fmt.Println("You can also add region after command if you want http trace information of the specific region")
fmt.Println("ex> pingcloud-cli aws us-east-1")
} else {
for _, r := range args {
if i, ok := aws.AWSEndpoints[r]; ok {
p := ping.PingDto{
Region: r,
Name: aws.AWSRegions[r],
Address: i,
}
p.VerbosePing()
} else {
fmt.Printf("Region code [%v] is wrong. To check available region codes run the command with -l or --list flag\n", r)
fmt.Println("Usage: pingcloud-cli aws -l")
fmt.Println("Usage: pingcloud-cli aws --list")

}
}
c := ping.CmdOption{
Option: "aws",
OptionName: "AWS",
ListFlg: list,
Args: args,
}
fmt.Println("")

c.StartCmd()
},
}

Expand Down
68 changes: 6 additions & 62 deletions cmd/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@ limitations under the License.
package cmd

import (
"fmt"
"os"
"text/tabwriter"

"github.com/reoim/pingcloud-cli/ping"
"github.com/reoim/pingcloud-cli/ping/azure"
"github.com/spf13/cobra"
)

Expand All @@ -30,65 +25,14 @@ var azureCmd = &cobra.Command{
Use: "azure",
Short: "Check latencies of Azure regions.",
Run: func(cmd *cobra.Command, args []string) {

fmt.Println("")
if list {

// Init tabwriter
tr := tabwriter.NewWriter(os.Stdout, 40, 8, 2, '\t', 0)
fmt.Fprintf(tr, "Azure Region Code\tAzure Region Name")
fmt.Fprintln(tr)
fmt.Fprintf(tr, "------------------------------\t------------------------------")
fmt.Fprintln(tr)
for r, n := range azure.AZURERegions {
fmt.Fprintf(tr, "[%v]\t[%v]", r, n)
fmt.Fprintln(tr)
}
// Flush tabwriter
tr.Flush()
} else if len(args) == 0 {

// Init tabwriter
tr := tabwriter.NewWriter(os.Stdout, 40, 8, 2, '\t', 0)
fmt.Fprintf(tr, "Azure Region Code\tAzure Region Name\tLatency")
fmt.Fprintln(tr)
fmt.Fprintf(tr, "------------------------------\t------------------------------\t------------------------------")
fmt.Fprintln(tr)

// Flush tabwriter
tr.Flush()

for r, i := range azure.AZUREEndpoints {
p := ping.PingDto{
Region: r,
Name: azure.AZURERegions[r],
Address: i,
}
p.Ping()
}
fmt.Println("")
fmt.Println("You can also add region after command if you want http trace information of the specific region")
fmt.Println("ex> pingcloud-cli azure centralus")
} else {
for _, r := range args {
if i, ok := azure.AZUREEndpoints[r]; ok {
p := ping.PingDto{
Region: r,
Name: azure.AZURERegions[r],
Address: i,
}
p.VerbosePing()
} else {
fmt.Printf("Region code [%v] is wrong. To check available region codes run the command with -l or --list flag\n", r)
fmt.Println("Usage: pingcloud-cli azure -l")
fmt.Println("Usage: pingcloud-cli azure --list")

}
}

c := ping.CmdOption{
Option: "azure",
OptionName: "Azure",
ListFlg: list,
Args: args,
}
fmt.Println("")

c.StartCmd()
},
}

Expand Down
68 changes: 7 additions & 61 deletions cmd/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@ limitations under the License.
package cmd

import (
"fmt"
"os"
"text/tabwriter"

"github.com/reoim/pingcloud-cli/ping"
"github.com/reoim/pingcloud-cli/ping/gcp"
"github.com/spf13/cobra"
)

Expand All @@ -33,63 +28,14 @@ var gcpCmd = &cobra.Command{
Use: "gcp",
Short: "Check latencies of GCP regions.",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("")
if list {

// Init tabwriter
tr := tabwriter.NewWriter(os.Stdout, 40, 8, 2, '\t', 0)
fmt.Fprintf(tr, "GCP Region Code\tGCP Region Name")
fmt.Fprintln(tr)
fmt.Fprintf(tr, "------------------------------\t------------------------------")
fmt.Fprintln(tr)
for r, n := range gcp.GCPRegions {
fmt.Fprintf(tr, "[%v]\t[%v]", r, n)
fmt.Fprintln(tr)
}
// Flush tabwriter
tr.Flush()
} else if len(args) == 0 {

// Init tabwriter
tr := tabwriter.NewWriter(os.Stdout, 40, 8, 2, '\t', 0)
fmt.Fprintf(tr, "GCP Region Code\tGCP Region Name\tLatency")
fmt.Fprintln(tr)
fmt.Fprintf(tr, "------------------------------\t------------------------------\t------------------------------")
fmt.Fprintln(tr)

// Flush tabwriter
tr.Flush()

for r, i := range gcp.GCPEndpoints {
p := ping.PingDto{
Region: r,
Name: gcp.GCPRegions[r],
Address: i,
}
p.Ping()
}
fmt.Println("")
fmt.Println("You can also add region after command if you want http trace information of the specific region")
fmt.Println("ex> pingcloud-cli gcp us-central1")
} else {
for _, r := range args {
if i, ok := gcp.GCPEndpoints[r]; ok {
p := ping.PingDto{
Region: r,
Name: gcp.GCPRegions[r],
Address: i,
}
p.VerbosePing()
} else {
fmt.Printf("Region code [%v] is wrong. To check available region codes run the command with -l or --list flag\n", r)
fmt.Println("Usage: pingcloud-cli gcp -l")
fmt.Println("Usage: pingcloud-cli gcp --list")

}
}

c := ping.CmdOption{
Option: "gcp",
OptionName: "GCP",
ListFlg: list,
Args: args,
}
fmt.Println("")

c.StartCmd()

},
}
Expand Down
20 changes: 20 additions & 0 deletions endpoints/aws.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[RegionCode],[RegionName],[Endpoint]
us-east-1,US East (N. Virginia),http://3.80.0.0/green-icon.gif
us-east-2,US East (Ohio),http://3.13.0.254/green-icon.gif
us-west-1,US West (N. California),http://13.52.0.0/green-icon.gif
us-west-2,US West (Oregon),http://18.236.0.0/green-icon.gif
ca-central-1,Canada (Central),http://15.222.0.0/green-icon.gif
eu-central-1,EU (Frankfurt),http://3.120.0.0/green-icon.gif
eu-west-1,EU (Ireland),http://3.248.0.0/green-icon.gif
eu-west-2,EU (London),http://3.8.0.0/green-icon.gif
eu-west-3,EU (Paris),http://15.188.0.0/green-icon.gif
eu-north-1,EU (Stockholm),http://13.48.0.0/green-icon.gif
ap-east-1,Asia Pacific (Hong Kong),http://18.162.80.8/green-icon.gif
ap-northeast-1,Asia Pacific (Tokyo),http://3.112.0.0/green-icon.gif
ap-northeast-2,Asia Pacific (Seoul),http://13.124.63.251/green-icon.gif
ap-northeast-3,Asia Pacific (Osaka-Local),http://13.208.32.253/green-icon.gif
ap-southeast-1,Asia Pacific (Singapore),http://3.0.0.9/green-icon.gif
ap-southeast-2,Asia Pacific (Sydney),http://3.24.0.0/green-icon.gif
ap-south-1,Asia Pacific (Mumbai),http://13.126.0.252/green-icon.gif
me-south-1,Middle East (Bahrain),http://15.185.32.254/green-icon.gif
sa-east-1,South America (São Paulo),http://18.228.0.0/green-icon.gif
29 changes: 29 additions & 0 deletions endpoints/azure.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[RegionCode],[RegionName],[Endpoint]
centralus,United States (Central US),http://astcentralus.blob.core.windows.net/public/callback.js
eastus2,United States (East US 2),http://asteastus2.blob.core.windows.net/public/callback.js
eastus,United States (East US),http://asteastus.blob.core.windows.net/public/callback.js
northcentralus,United States (North Central US),http://astnorthcentralus.blob.core.windows.net/public/callback.js
southcentralus,United States (South Central US),http://astsouthcentralus.blob.core.windows.net/public/callback.js
westus2,United States (West US 2),http://astwestus2.blob.core.windows.net/public/callback.js
westcentralus,United States (West Central US),http://astwestcentralus.blob.core.windows.net/public/callback.js
westus,United States (West US),http://astwestus.blob.core.windows.net/public/callback.js
canadacentral,Canada (Canada Central),http://astcanadacentral.blob.core.windows.net/public/callback.js
canadaeast,Canada (Canada East),http://astcanadaeast.blob.core.windows.net/public/callback.js
brazilsouth,Brazil (Brazil South),http://astbrazilsouth.blob.core.windows.net/public/callback.js
northeurope,Europe (North Europe),http://astnortheurope.blob.core.windows.net/public/callback.js
westeurope,Europe (West Europe),http://astwesteurope.blob.core.windows.net/public/callback.js
francecentral,France (France Central),http://astfrancecentral.blob.core.windows.net/public/callback.js
uksouth,United Kingdom (UK South),http://astuksouth.blob.core.windows.net/public/callback.js
ukwest,United Kingdom (UK West),http://astukwest.blob.core.windows.net/public/callback.js
eastasia,Asia Pacific (East Asia),http://asteastasia.blob.core.windows.net/public/callback.js
southeastasia,Asia Pacific (Southeast Asia),http://astsoutheastasia.blob.core.windows.net/public/callback.js
australiaeast,Australia (Australia East),http://astaustraliaeast.blob.core.windows.net/public/callback.js
australiasoutheast,Australia (Australia Southeast),http://astaustraliasoutheast.blob.core.windows.net/public/callback.js
centralindia,India (Central India),http://astcentralindia.blob.core.windows.net/public/callback.js
southindia,India (South India),http://astsouthindia.blob.core.windows.net/public/callback.js
westindia,India (West India),http://astwestindia.blob.core.windows.net/public/callback.js
japaneast,Japan (Japan East),http://astjapaneast.blob.core.windows.net/public/callback.js
japanwest,Japan (Japan West),http://astjapanwest.blob.core.windows.net/public/callback.js
koreacentral,Korea (Korea Central),http://astkoreacentral.blob.core.windows.net/public/callback.js
koreasouth,Korea (Korea South),http://astkoreasouth.blob.core.windows.net/public/callback.js
southafricanorth,Africa (South Africa North),http://astsouthafricanorth.blob.core.windows.net/public/callback.js
22 changes: 22 additions & 0 deletions endpoints/gcp.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[RegionCode],[RegionName],[Endpoint]
global,Global HTTP Load Balancer,http://35.186.221.153/ping
asia-east1,Changhua County - Taiwan,http://104.155.201.52/ping
asia-east2,Hong Kong,http://35.220.162.209/ping
asia-northeast1,Tokyo - Japan,http://104.198.86.148/ping
asia-northeast2,Osaka - Japan,http://34.97.196.51/ping
asia-south1,Mumbai - India,http://35.200.186.152/ping
asia-southeast1,Jurong West - Singapore,http://35.185.179.198/ping
australia-southeast1,Sydney - Australia,http://35.189.6.113/ping
europe-north1,Hamina - Finland,http://35.228.170.201/ping
europe-west1,St. Ghislain - Belgium,http://104.199.82.109/ping
europe-west2,London - UK,http://35.189.67.146/ping
europe-west3,Frankfurt - Germany,http://35.198.78.172/ping
europe-west4,Eemshaven - Netherlands,http://35.204.93.82/ping
europe-west6,Zürich - Switzerland,http://34.65.3.254/ping
northamerica-northeast1,Québec - Canada,http://35.203.57.164/ping
southamerica-east1,Osasco (São Paulo) - Brazil,http://35.198.10.68/ping
us-central1,Iowa - USA,http://104.197.165.8/ping
us-east1,South Carolina - USA,http://104.196.161.21/ping
us-east4,Northern Virginia - USA,http://35.186.168.152/ping
us-west1,Oregon - USA,http://104.199.116.74/ping
us-west2,California - USA,http://35.236.45.25/ping
Loading

0 comments on commit 8b129fe

Please sign in to comment.