diff --git a/ec2_cache.go b/ec2_cache.go index 770b2cf..e7eefea 100644 --- a/ec2_cache.go +++ b/ec2_cache.go @@ -54,7 +54,7 @@ type EC2Cache struct { // NewEC2Cache creates a new EC2Cache that uses the provided // EC2 client to lookup instances. It starts a goroutine that // keeps the cache up-to-date. -func NewEC2Cache(regionName, accessKey, secretKey string) (*EC2Cache, error) { +func NewEC2Cache(regionName, accessKey, secretKey, tagname string) (*EC2Cache, error) { region, ok := aws.Regions[regionName] if !ok { @@ -68,13 +68,13 @@ func NewEC2Cache(regionName, accessKey, secretKey string) (*EC2Cache, error) { records: make(map[Key][]*Record), } - if err := cache.refresh(); err != nil { + if err := cache.refresh(tagname); err != nil { return nil, err } go func() { for _ = range time.Tick(1 * time.Minute) { - err := cache.refresh() + err := cache.refresh(tagname) if err != nil { log.Println("ERROR: " + err.Error()) } @@ -112,7 +112,7 @@ func sanitize(tag string) string { return SANE_DNS_REPL.ReplaceAllString(out, "-") } -func (cache *EC2Cache) refresh() error { +func (cache *EC2Cache) refresh(tagname string) error { result, err := cache.Instances() validUntil := time.Now().Add(TTL) @@ -138,7 +138,7 @@ func (cache *EC2Cache) refresh() error { } record.ValidUntil = validUntil for _, tag := range instance.Tags { - if tag.Key == "Name" { + if tag.Key == tagname { name := sanitize(tag.Value) records[Key{LOOKUP_NAME, name}] = append(records[Key{LOOKUP_NAME, name}], &record) } diff --git a/main.go b/main.go index 9831eaf..fe4d7c9 100644 --- a/main.go +++ b/main.go @@ -13,6 +13,7 @@ import ( const USAGE = `Usage: aws-name-server --domain [ --hostname + --tagname --aws-region us-east-1 --aws-access-key-id --aws-secret-access-key ] @@ -42,6 +43,7 @@ func main() { domain := flag.String("domain", "", "the domain heirarchy to serve (e.g. aws.example.com)") hostname := flag.String("hostname", "", "the public hostname of this server (e.g. ec2-12-34-56-78.compute-1.amazonaws.com)") help := flag.Bool("help", false, "show help") + tagname := flag.String("tagname", "Name", "the tag to use instead of NAME") region := flag.String("aws-region", "us-east-1", "The AWS Region") accessKey := flag.String("aws-access-key-id", "", "The AWS Access Key Id") @@ -59,7 +61,7 @@ func main() { hostnameFuture := getHostname() - cache, err := NewEC2Cache(*region, *accessKey, *secretKey) + cache, err := NewEC2Cache(*region, *accessKey, *secretKey, *tagname) if err != nil { log.Fatalf("FATAL: %s", err) }