Skip to content

Commit

Permalink
Remove nginx client
Browse files Browse the repository at this point in the history
  • Loading branch information
peterjan committed Mar 16, 2022
2 parents f394f74 + 43f5871 commit 3532489
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 32 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ This service depends on the following environment variables:
* `API_HOST`, defaults to `sia`
* `API_PORT`, defaults to `9980`
* `SIA_API_PASSWORD`
* `NGINX_HOST`, defaults to `10.10.10.30`
* `NGINX_PORT`, defaults to `8000`
* `SKYNET_DB_HOST`
* `SKYNET_DB_PORT`
* `SKYNET_DB_USER`
Expand Down
23 changes: 1 addition & 22 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,6 @@ const (
// defaultSkydPort is where we connect to skyd unless overwritten by
// "API_PORT" environment variables.
defaultSkydPort = 9980

// defaultNginxHost is where we connect to nginx unless overwritten by
// "NGINX_HOST" environment variables.
defaultNginxHost = "10.10.10.30"

// defaultNginxPort is where we connect to nginx unless overwritten by
// "NGINX_PORT" environment variables.
defaultNginxPort = 8000
)

func main() {
Expand Down Expand Up @@ -80,15 +72,6 @@ func main() {
if skydHostEnv := os.Getenv("API_HOST"); skydHostEnv != "" {
skydHost = skydHostEnv
}
nginxPort := defaultNginxPort
nginxPortEnv, err := strconv.Atoi(os.Getenv("NGINX_PORT"))
if err == nil && nginxPortEnv > 0 {
nginxPort = nginxPortEnv
}
nginxHost := defaultNginxHost
if nginxHostEnv := os.Getenv("NGINX_HOST"); nginxHostEnv != "" {
nginxHost = nginxHostEnv
}
skydAPIPassword := os.Getenv("SIA_API_PASSWORD")
if skydAPIPassword == "" {
log.Fatal(errors.New("SIA_API_PASSWORD is empty, exiting"))
Expand All @@ -114,12 +97,8 @@ func main() {
log.Fatal(errors.New("skyd down, exiting"))
}

// Create a skyd client that actually talks to Nginx for the blocker
nginxUrl := fmt.Sprintf("http://%s:%d", nginxHost, nginxPort)
nginxClient := api.NewSkydClient(nginxUrl, headers)

// Create the blocker.
bl, err := blocker.New(ctx, nginxClient, db, logger)
bl, err := blocker.New(ctx, skydClient, db, logger)
if err != nil {
log.Fatal(errors.AddContext(err, "failed to instantiate blocker"))
}
Expand Down
10 changes: 2 additions & 8 deletions skyd/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ type (
// api is a helper struct that exposes some methods that allow making skyd
// API calls used by both the API and the blocker
api struct {
staticNginxHost string
staticNginxPort int

staticSkydHost string
staticSkydPort int
staticSkydAPIPassword string
Expand Down Expand Up @@ -82,7 +79,7 @@ func (br *blockResponse) InvalidHashes() ([]database.Hash, error) {
}

// NewAPI creates a new API instance.
func NewAPI(nginxHost string, nginxPort int, skydHost, skydPassword string, skydPort int, db *database.DB, logger *logrus.Logger) (API, error) {
func NewAPI(skydHost, skydPassword string, skydPort int, db *database.DB, logger *logrus.Logger) (API, error) {
if db == nil {
return nil, errors.New("no DB provided")
}
Expand All @@ -91,9 +88,6 @@ func NewAPI(nginxHost string, nginxPort int, skydHost, skydPassword string, skyd
}

return &api{
staticNginxHost: nginxHost,
staticNginxPort: nginxPort,

staticSkydHost: skydHost,
staticSkydPort: skydPort,
staticSkydAPIPassword: skydPassword,
Expand Down Expand Up @@ -126,7 +120,7 @@ func (api *api) BlockHashes(hashes []database.Hash) ([]database.Hash, []database
}

// execute the request
url := fmt.Sprintf("http://%s:%d/skynet/blocklist?timeout=%s", api.staticNginxHost, api.staticNginxPort, skydTimeout)
url := fmt.Sprintf("http://%s:%d/skynet/blocklist?timeout=%s", api.staticSkydHost, api.staticSkydPort, skydTimeout)
req, err := http.NewRequest(http.MethodPost, url, bytes.NewBuffer(reqBody))
if err != nil {
return nil, nil, errors.AddContext(err, "failed to build request to skyd")
Expand Down

0 comments on commit 3532489

Please sign in to comment.