feat(ModemAuthentication): add pin, GetModemAuthentication #4
@@ -222,4 +222,19 @@ func (c *Client) GetModemConfiguration(ctx context.Context) (any, error) {
|
||||
return config, nil
|
||||
}
|
||||
|
||||
// GetModemConfiguration implements protocol.Operations.
|
||||
func (c *Client) GetModemAuthentication(ctx context.Context) (any, error) {
|
||||
_, ops, err := c.getProtocol(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
config, err := ops.GetModemAuthentication(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
return config, nil
|
||||
}
|
||||
|
||||
var _ protocol.Operations = &Client{}
|
||||
|
@@ -5,6 +5,7 @@ type SetModemOptions struct {
|
||||
Type *string
|
||||
Username *string
|
||||
Password *string
|
||||
Pin *string
|
||||
}
|
||||
|
||||
type SetModemOptionsFunc func(opts *SetModemOptions)
|
||||
@@ -34,8 +35,15 @@ func WithUsername(value string) SetModemOptionsFunc {
|
||||
opts.Username = &value
|
||||
}
|
||||
}
|
||||
|
||||
func WithPassword(value string) SetModemOptionsFunc {
|
||||
return func(opts *SetModemOptions) {
|
||||
opts.Password = &value
|
||||
}
|
||||
}
|
||||
|
||||
func WithPin(value string) SetModemOptionsFunc {
|
||||
return func(opts *SetModemOptions) {
|
||||
opts.Pin = &value
|
||||
}
|
||||
}
|
||||
|
@@ -64,4 +64,7 @@ type Operations interface {
|
||||
|
||||
//GetModemConfiguration mobile data config
|
||||
GetModemConfiguration(ctx context.Context) (any, error)
|
||||
|
||||
//GetModemAuthentication mobile data config
|
||||
GetModemAuthentication(ctx context.Context) (any, error)
|
||||
}
|
||||
|
@@ -400,4 +400,9 @@ func (o *Operations) GetModemConfiguration(ctx context.Context) (any, error) {
|
||||
return nil, protocol.ErrUnimplemented
|
||||
}
|
||||
|
||||
// Deprecated : is no longer maintained for modules in V1
|
||||
func (o *Operations) GetModemAuthentication(ctx context.Context) (any, error) {
|
||||
return nil, protocol.ErrUnimplemented
|
||||
}
|
||||
|
||||
var _ protocol.Operations = &Operations{}
|
||||
|
@@ -174,7 +174,7 @@ func (o *Operations) PostModem(ctx context.Context, config *model.ModemAuthentic
|
||||
return &updated, nil
|
||||
}
|
||||
|
||||
func (o *Operations) GetModem(ctx context.Context) (*model.ModemConfiguration, error) {
|
||||
func (o *Operations) GetModemInfo(ctx context.Context) (*model.ModemConfiguration, error) {
|
||||
config := &model.ModemConfiguration{}
|
||||
|
||||
if err := o.GetJSON("/modem/1/info", config); err != nil {
|
||||
@@ -183,3 +183,13 @@ func (o *Operations) GetModem(ctx context.Context) (*model.ModemConfiguration, e
|
||||
|
||||
return config, nil
|
||||
}
|
||||
|
||||
func (o *Operations) GetModemSettings(ctx context.Context) (*model.ModemAuthentication, error) {
|
||||
config := &model.ModemAuthentication{}
|
||||
|
||||
if err := o.GetJSON("/modem/1/settings", config); err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
return config, nil
|
||||
}
|
||||
|
@@ -3,12 +3,13 @@ package model
|
||||
// type : null, pap_chap, pap, chap
|
||||
// if type selected, username and password are mandatory
|
||||
type ModemAuthentication struct {
|
||||
Authentication struct {
|
||||
Apn string `json:"apn"`
|
||||
Authentication *struct {
|
||||
Apn string `json:"apn,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
Username string `json:"username,omitempty"`
|
||||
Password string `json:"password,omitempty"`
|
||||
} `json:"authentication"`
|
||||
} `json:"authentication,omitempty"`
|
||||
Pin string `json:"pin,omitempty"`
|
||||
}
|
||||
|
||||
type ModemConfiguration struct {
|
||||
|
@@ -366,20 +366,29 @@ func (o *Operations) SetBaseCorrections(ctx context.Context, funcs ...protocol.S
|
||||
func (o *Operations) SetModem(ctx context.Context, funcs ...protocol.SetModemOptionsFunc) error {
|
||||
opts := protocol.NewSetModemOptions(funcs...)
|
||||
modem := &model.ModemAuthentication{}
|
||||
if opts.Apn != nil {
|
||||
modem.Authentication.Apn = *opts.Apn
|
||||
if opts.Pin != nil {
|
||||
modem.Pin = *opts.Pin
|
||||
}
|
||||
|
||||
if opts.Type != nil {
|
||||
modem.Authentication.Type = *opts.Type
|
||||
}
|
||||
|
||||
if opts.Password != nil {
|
||||
modem.Authentication.Password = *opts.Password
|
||||
}
|
||||
|
||||
if opts.Username != nil {
|
||||
modem.Authentication.Username = *opts.Username
|
||||
if opts.Apn != nil || opts.Type != nil || opts.Username != nil || opts.Password != nil {
|
||||
modem.Authentication = &struct {
|
||||
Apn string `json:"apn,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
Username string `json:"username,omitempty"`
|
||||
Password string `json:"password,omitempty"`
|
||||
}{}
|
||||
if opts.Apn != nil {
|
||||
modem.Authentication.Apn = *opts.Apn
|
||||
}
|
||||
if opts.Type != nil {
|
||||
modem.Authentication.Type = *opts.Type
|
||||
}
|
||||
if opts.Username != nil {
|
||||
modem.Authentication.Username = *opts.Username
|
||||
}
|
||||
if opts.Password != nil {
|
||||
modem.Authentication.Password = *opts.Password
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := o.PostModem(ctx, modem); err != nil {
|
||||
@@ -388,9 +397,20 @@ func (o *Operations) SetModem(ctx context.Context, funcs ...protocol.SetModemOpt
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetModem implements protocol.Operations.
|
||||
// GetModem implements protocol.Operations.
|
||||
func (o *Operations) GetModemConfiguration(ctx context.Context) (any, error) {
|
||||
config, err := o.GetModem(ctx)
|
||||
config, err := o.GetModemInfo(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
return config, nil
|
||||
|
||||
}
|
||||
|
||||
// GetModemSettings implements protocol.Operations.
|
||||
func (o *Operations) GetModemAuthentication(ctx context.Context) (any, error) {
|
||||
config, err := o.GetModemSettings(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user