-
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
67d2a93
commit 266cdb6
Showing
11 changed files
with
294 additions
and
7 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
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,17 @@ | ||
# TODO: The dnslink definition below is equal to: | ||
# REDIRECTS_DIR_CID=$(ipfs resolve -r /ipfs/$CAR_ROOT_CID/examples | cut -d "/" -f3) | ||
# Hardcoding here seems like a good start, but the actual behavior is calling: | ||
# fixture := car.MustOpenUnixfsCar("t0109-redirects.car") | ||
# redirectDir := fixture.MustGetNode("examples") | ||
# redirectDirCID := redirectDir.Base32Cid() | ||
# fmt.Printf("/ipfs/%s", redirectDirCID) | ||
dnslinks: | ||
# list of id: key, value. | ||
dnslink-enabled-on-fqdn: # this is the id, it can be reused through the test | ||
# this is the name -> value. | ||
# later it might be possible to rewrite the value on the left. | ||
subdomain: dnslink-enabled-on-fqdn. | ||
path: /ipfs/QmYBhLYDwVFvxos9h8CGU2ibaY66QNgv8hpfewxaQrPiZj | ||
|
||
# One tool will aggregate these dns link into `IPFS_NS_MAP="key:value" mapping. | ||
# One tool will load this dns link into a fixture. |
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,43 @@ | ||
package dnslink | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
) | ||
|
||
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 | ||
} |
Oops, something went wrong.