-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8b224e1
commit 279e24a
Showing
12 changed files
with
304 additions
and
8 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"strings" | ||
|
||
"github.com/ipfs/gateway-conformance/tooling/dnslink" | ||
"github.com/ipfs/gateway-conformance/tooling/fixtures" | ||
) | ||
|
||
func main() { | ||
if len(os.Args) < 2 { | ||
fmt.Println("Usage: dnslinkgen <domain>") | ||
os.Exit(1) | ||
} | ||
|
||
domain := os.Args[1] | ||
|
||
fxs, err := fixtures.List() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
configs := fxs.ConfigFiles | ||
aggMap, err := dnslink.Aggregate(configs) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
// print k=v on stdout | ||
var kvs []string | ||
for k, v := range aggMap { | ||
kvs = append(kvs, fmt.Sprintf("%s%s:%s", k, domain, v)) | ||
} | ||
|
||
fmt.Println("export IPFS_NS_MAP=\"" + strings.Join(kvs, ",") + "\"") | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
dnslinks: | ||
custom-dnslink: | ||
subdomain: dnslink-enabled-on-fqdn | ||
# this is the cid of the folder | ||
# t0109-redirects.car:/examples/ | ||
path: /ipfs/QmYBhLYDwVFvxos9h8CGU2ibaY66QNgv8hpfewxaQrPiZj |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package dnslink | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path" | ||
|
||
"github.com/ipfs/gateway-conformance/tooling/fixtures" | ||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
type DNSLinks struct { | ||
DNSLinks map[string]DNSLink `yaml:"dnslinks"` | ||
} | ||
|
||
type DNSLink struct { | ||
Subdomain string `yaml:"subdomain"` | ||
Path string `yaml:"path"` | ||
} | ||
|
||
func OpenDNSLink(absPath string) (*DNSLinks, error) { | ||
data, err := os.ReadFile(absPath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var dnsLinks DNSLinks | ||
err = yaml.Unmarshal(data, &dnsLinks) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &dnsLinks, nil | ||
} | ||
|
||
func MustOpenDNSLink(file string) *DNSLinks { | ||
fixturePath := path.Join(fixtures.Dir(), file) | ||
dnsLinks, err := OpenDNSLink(fixturePath) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
return dnsLinks | ||
} | ||
|
||
func (d *DNSLinks) Get(id string) string { | ||
dnsLink, ok := d.DNSLinks[id] | ||
if !ok { | ||
panic(fmt.Errorf("dnslink %s not found", id)) | ||
} | ||
return dnsLink.Subdomain | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package dnslink | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
"strings" | ||
) | ||
|
||
func Aggregate(inputPaths []string) (map[string]string, error) { | ||
aggMap := make(map[string]string) | ||
|
||
for _, file := range inputPaths { | ||
dnsLinks, err := OpenDNSLink(file) | ||
if err != nil { | ||
return nil, fmt.Errorf("error loading file %s: %v", file, err) | ||
} | ||
|
||
for _, link := range dnsLinks.DNSLinks { | ||
if _, ok := aggMap[link.Subdomain]; ok { | ||
return nil, fmt.Errorf("collision detected for subdomain %s", link.Subdomain) | ||
} | ||
|
||
aggMap[link.Subdomain] = link.Path | ||
} | ||
} | ||
|
||
return aggMap, nil | ||
} | ||
|
||
func Merge(inputPaths []string, outputPath string) error { | ||
kvs, err := Aggregate(inputPaths) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
j, err := json.MarshalIndent(kvs, "", " ") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = os.WriteFile(outputPath, j, 0644) | ||
return err | ||
} | ||
|
||
func AsEnv(inputPaths []string, outputPath string) error { | ||
kvs, err := Aggregate(inputPaths) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var kvsStr []string | ||
for k, v := range kvs { | ||
kvsStr = append(kvsStr, fmt.Sprintf("%s:%s", k, v)) | ||
} | ||
|
||
env := strings.Join(kvsStr, ",") | ||
env = "export IPFS_NS_MAP=\"" + env + "\"" | ||
|
||
err = os.WriteFile(outputPath, []byte(env), 0644) | ||
|
||
return err | ||
} |
Oops, something went wrong.