Created
June 15, 2016 23:33
-
-
Save st3v/88ecb4b016377af6c8f258ed14ec7b4c to your computer and use it in GitHub Desktop.
Access Eureka with OAuth2 Bearer Tokens
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"flag" | |
"log" | |
"github.com/st3v/fargo" | |
"golang.org/x/oauth2" | |
"golang.org/x/oauth2/clientcredentials" | |
) | |
var ( | |
eurekaUrl = flag.String("eureka-url", "", "Eureka URL") | |
tokenUrl = flag.String("token-url", "", "Token URL") | |
clientId = flag.String("client-id", "", "Client ID") | |
clientSecret = flag.String("client-secret", "", "Client Secret") | |
) | |
func init() { | |
flag.Parse() | |
log.SetFlags(0) | |
} | |
func main() { | |
config := clientcredentials.Config{ | |
ClientID: *clientId, | |
ClientSecret: *clientSecret, | |
TokenURL: *tokenUrl, | |
} | |
fargo.HttpClient = config.Client(oauth2.NoContext) | |
conn := fargo.NewConn(*eurekaUrl) | |
err := conn.RegisterInstance(instance) | |
if err != nil { | |
log.Fatal(err) | |
} | |
apps, err := conn.GetApps() | |
if err != nil { | |
log.Fatal(err) | |
} | |
for _, app := range apps { | |
log.Println(app.Name) | |
} | |
} | |
var instance = &fargo.Instance{ | |
App: "TEST", | |
IPAddr: "1.2.3.4", | |
VipAddress: "1.2.3.4", | |
SecureVipAddress: "1.2.3.4", | |
Port: 567, | |
Status: fargo.UP, | |
DataCenterInfo: fargo.DataCenterInfo{Name: fargo.MyOwn}, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment