authorizations.go (nsq-1.2.0) | : | authorizations.go (nsq-1.2.1) | ||
---|---|---|---|---|
package auth | package auth | |||
import ( | import ( | |||
"errors" | "errors" | |||
"fmt" | "fmt" | |||
"log" | "log" | |||
"math/rand" | "math/rand" | |||
"net/url" | "net/url" | |||
"regexp" | "regexp" | |||
"strings" | ||||
"time" | "time" | |||
"github.com/nsqio/nsq/internal/http_api" | "github.com/nsqio/nsq/internal/http_api" | |||
) | ) | |||
type Authorization struct { | type Authorization struct { | |||
Topic string `json:"topic"` | Topic string `json:"topic"` | |||
Channels []string `json:"channels"` | Channels []string `json:"channels"` | |||
Permissions []string `json:"permissions"` | Permissions []string `json:"permissions"` | |||
} | } | |||
skipping to change at line 108 | skipping to change at line 109 | |||
v := url.Values{} | v := url.Values{} | |||
v.Set("remote_ip", remoteIP) | v.Set("remote_ip", remoteIP) | |||
if tlsEnabled { | if tlsEnabled { | |||
v.Set("tls", "true") | v.Set("tls", "true") | |||
} else { | } else { | |||
v.Set("tls", "false") | v.Set("tls", "false") | |||
} | } | |||
v.Set("secret", authSecret) | v.Set("secret", authSecret) | |||
v.Set("common_name", commonName) | v.Set("common_name", commonName) | |||
endpoint := fmt.Sprintf("http://%s/auth?%s", authd, v.Encode()) | var endpoint string | |||
if strings.Contains(authd, "://") { | ||||
endpoint = fmt.Sprintf("%s?%s", authd, v.Encode()) | ||||
} else { | ||||
endpoint = fmt.Sprintf("http://%s/auth?%s", authd, v.Encode()) | ||||
} | ||||
var authState State | var authState State | |||
client := http_api.NewClient(nil, connectTimeout, requestTimeout) | client := http_api.NewClient(nil, connectTimeout, requestTimeout) | |||
if err := client.GETV1(endpoint, &authState); err != nil { | if err := client.GETV1(endpoint, &authState); err != nil { | |||
return nil, err | return nil, err | |||
} | } | |||
// validation on response | // validation on response | |||
for _, auth := range authState.Authorizations { | for _, auth := range authState.Authorizations { | |||
for _, p := range auth.Permissions { | for _, p := range auth.Permissions { | |||
End of changes. 2 change blocks. | ||||
1 lines changed or deleted | 7 lines changed or added |