2020-02-06 20:42:46 -05:00
|
|
|
package dns
|
|
|
|
|
|
|
|
|
|
import (
|
2020-10-18 02:24:34 +00:00
|
|
|
"context"
|
2020-02-06 20:42:46 -05:00
|
|
|
"fmt"
|
2020-04-12 20:05:28 +00:00
|
|
|
"net/http"
|
2020-02-06 20:42:46 -05:00
|
|
|
|
2020-07-26 12:07:06 +00:00
|
|
|
"github.com/qdm12/gluetun/internal/constants"
|
2020-02-06 20:42:46 -05:00
|
|
|
"github.com/qdm12/golibs/files"
|
|
|
|
|
)
|
|
|
|
|
|
2020-10-18 02:24:34 +00:00
|
|
|
func (c *configurator) DownloadRootHints(ctx context.Context, uid, gid int) error {
|
2020-04-12 19:07:19 +00:00
|
|
|
c.logger.Info("downloading root hints from %s", constants.NamedRootURL)
|
2020-10-18 02:24:34 +00:00
|
|
|
content, status, err := c.client.Get(ctx, string(constants.NamedRootURL))
|
2020-02-06 20:42:46 -05:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
2020-04-12 20:05:28 +00:00
|
|
|
} else if status != http.StatusOK {
|
2020-02-06 20:42:46 -05:00
|
|
|
return fmt.Errorf("HTTP status code is %d for %s", status, constants.NamedRootURL)
|
|
|
|
|
}
|
|
|
|
|
return c.fileManager.WriteToFile(
|
|
|
|
|
string(constants.RootHints),
|
|
|
|
|
content,
|
2020-02-08 15:29:27 +00:00
|
|
|
files.Ownership(uid, gid),
|
2020-10-20 02:45:28 +00:00
|
|
|
files.Permissions(constants.UserReadPermission))
|
2020-02-06 20:42:46 -05:00
|
|
|
}
|
|
|
|
|
|
2020-10-18 02:24:34 +00:00
|
|
|
func (c *configurator) DownloadRootKey(ctx context.Context, uid, gid int) error {
|
2020-04-12 19:07:19 +00:00
|
|
|
c.logger.Info("downloading root key from %s", constants.RootKeyURL)
|
2020-10-18 02:24:34 +00:00
|
|
|
content, status, err := c.client.Get(ctx, string(constants.RootKeyURL))
|
2020-02-06 20:42:46 -05:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
2020-04-12 20:05:28 +00:00
|
|
|
} else if status != http.StatusOK {
|
2020-02-06 20:42:46 -05:00
|
|
|
return fmt.Errorf("HTTP status code is %d for %s", status, constants.RootKeyURL)
|
|
|
|
|
}
|
|
|
|
|
return c.fileManager.WriteToFile(
|
|
|
|
|
string(constants.RootKey),
|
|
|
|
|
content,
|
2020-02-08 15:29:27 +00:00
|
|
|
files.Ownership(uid, gid),
|
2020-10-20 02:45:28 +00:00
|
|
|
files.Permissions(constants.UserReadPermission))
|
2020-02-06 20:42:46 -05:00
|
|
|
}
|