mirror of
https://github.com/Snawoot/opera-proxy.git
synced 2025-09-01 18:20:23 +00:00
seclient: add device_generate_password method
This commit is contained in:
parent
ddc27f34ab
commit
298c91b4b5
2 changed files with 41 additions and 10 deletions
|
@ -62,6 +62,15 @@ type SERegisterDeviceResponse struct {
|
|||
Status SEStatusPair `json:"return_code"`
|
||||
}
|
||||
|
||||
type SEDeviceGeneratePasswordData struct {
|
||||
DevicePassword string `json:"device_password"`
|
||||
}
|
||||
|
||||
type SEDeviceGeneratePasswordResponse struct {
|
||||
Data SEDeviceGeneratePasswordData `json:"data"`
|
||||
Status SEStatusPair `json:"return_code"`
|
||||
}
|
||||
|
||||
type SEGeoEntry struct {
|
||||
Country string `json:"country,omitempty"`
|
||||
CountryCode string `json:"country_code"`
|
||||
|
|
|
@ -25,19 +25,21 @@ const (
|
|||
)
|
||||
|
||||
type SEEndpoints struct {
|
||||
RegisterSubscriber string
|
||||
SubscriberLogin string
|
||||
RegisterDevice string
|
||||
GeoList string
|
||||
Discover string
|
||||
RegisterSubscriber string
|
||||
SubscriberLogin string
|
||||
RegisterDevice string
|
||||
DeviceGeneratePassword string
|
||||
GeoList string
|
||||
Discover string
|
||||
}
|
||||
|
||||
var DefaultSEEndpoints = SEEndpoints{
|
||||
RegisterSubscriber: "https://api.sec-tunnel.com/v4/register_subscriber",
|
||||
SubscriberLogin: "https://api.sec-tunnel.com/v4/subscriber_login",
|
||||
RegisterDevice: "https://api.sec-tunnel.com/v4/register_device",
|
||||
GeoList: "https://api.sec-tunnel.com/v4/geo_list",
|
||||
Discover: "https://api.sec-tunnel.com/v4/discover",
|
||||
RegisterSubscriber: "https://api.sec-tunnel.com/v4/register_subscriber",
|
||||
SubscriberLogin: "https://api.sec-tunnel.com/v4/subscriber_login",
|
||||
RegisterDevice: "https://api.sec-tunnel.com/v4/register_device",
|
||||
DeviceGeneratePassword: "https://api.sec-tunnel.com/v4/device_generate_password",
|
||||
GeoList: "https://api.sec-tunnel.com/v4/geo_list",
|
||||
Discover: "https://api.sec-tunnel.com/v4/discover",
|
||||
}
|
||||
|
||||
type SESettings struct {
|
||||
|
@ -217,6 +219,26 @@ func (c *SEClient) Login(ctx context.Context) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (c *SEClient) DeviceGeneratePassword(ctx context.Context) error {
|
||||
var genRes SEDeviceGeneratePasswordResponse
|
||||
err := c.RpcCall(ctx, c.Settings.Endpoints.DeviceGeneratePassword, StrKV{
|
||||
"device_id": c.AssignedDeviceID,
|
||||
}, &genRes)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if genRes.Status.Code != SE_STATUS_OK {
|
||||
return fmt.Errorf("API responded with error message: code=%d, msg=\"%s\"",
|
||||
genRes.Status.Code, genRes.Status.Message)
|
||||
}
|
||||
|
||||
c.StateMux.Lock()
|
||||
c.DevicePassword = genRes.Data.DevicePassword
|
||||
c.StateMux.Unlock()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *SEClient) GetProxyCredentials() (string, string) {
|
||||
c.StateMux.RLock()
|
||||
assignedDeviceIDHash := c.AssignedDeviceIDHash
|
||||
|
|
Loading…
Add table
Reference in a new issue