Merge pull request 'feat(ModemAuthentication): add pin, GetModemAuthentication' (#4) from issue-324 into master
Reviewed-on: #4
This commit is contained in:
@@ -222,4 +222,19 @@ func (c *Client) GetModemConfiguration(ctx context.Context) (any, error) {
|
|||||||
return config, nil
|
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{}
|
var _ protocol.Operations = &Client{}
|
||||||
|
@@ -5,6 +5,7 @@ type SetModemOptions struct {
|
|||||||
Type *string
|
Type *string
|
||||||
Username *string
|
Username *string
|
||||||
Password *string
|
Password *string
|
||||||
|
Pin *string
|
||||||
}
|
}
|
||||||
|
|
||||||
type SetModemOptionsFunc func(opts *SetModemOptions)
|
type SetModemOptionsFunc func(opts *SetModemOptions)
|
||||||
@@ -34,8 +35,15 @@ func WithUsername(value string) SetModemOptionsFunc {
|
|||||||
opts.Username = &value
|
opts.Username = &value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithPassword(value string) SetModemOptionsFunc {
|
func WithPassword(value string) SetModemOptionsFunc {
|
||||||
return func(opts *SetModemOptions) {
|
return func(opts *SetModemOptions) {
|
||||||
opts.Password = &value
|
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 mobile data config
|
||||||
GetModemConfiguration(ctx context.Context) (any, error)
|
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
|
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{}
|
var _ protocol.Operations = &Operations{}
|
||||||
|
@@ -174,7 +174,7 @@ func (o *Operations) PostModem(ctx context.Context, config *model.ModemAuthentic
|
|||||||
return &updated, nil
|
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{}
|
config := &model.ModemConfiguration{}
|
||||||
|
|
||||||
if err := o.GetJSON("/modem/1/info", config); err != nil {
|
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
|
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
|
// type : null, pap_chap, pap, chap
|
||||||
// if type selected, username and password are mandatory
|
// if type selected, username and password are mandatory
|
||||||
type ModemAuthentication struct {
|
type ModemAuthentication struct {
|
||||||
Authentication struct {
|
Authentication *struct {
|
||||||
Apn string `json:"apn"`
|
Apn string `json:"apn,omitempty"`
|
||||||
Type string `json:"type,omitempty"`
|
Type string `json:"type,omitempty"`
|
||||||
Username string `json:"username,omitempty"`
|
Username string `json:"username,omitempty"`
|
||||||
Password string `json:"password,omitempty"`
|
Password string `json:"password,omitempty"`
|
||||||
} `json:"authentication"`
|
} `json:"authentication,omitempty"`
|
||||||
|
Pin string `json:"pin,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ModemConfiguration struct {
|
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 {
|
func (o *Operations) SetModem(ctx context.Context, funcs ...protocol.SetModemOptionsFunc) error {
|
||||||
opts := protocol.NewSetModemOptions(funcs...)
|
opts := protocol.NewSetModemOptions(funcs...)
|
||||||
modem := &model.ModemAuthentication{}
|
modem := &model.ModemAuthentication{}
|
||||||
|
if opts.Pin != nil {
|
||||||
|
modem.Pin = *opts.Pin
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
if opts.Apn != nil {
|
||||||
modem.Authentication.Apn = *opts.Apn
|
modem.Authentication.Apn = *opts.Apn
|
||||||
}
|
}
|
||||||
|
|
||||||
if opts.Type != nil {
|
if opts.Type != nil {
|
||||||
modem.Authentication.Type = *opts.Type
|
modem.Authentication.Type = *opts.Type
|
||||||
}
|
}
|
||||||
|
if opts.Username != nil {
|
||||||
|
modem.Authentication.Username = *opts.Username
|
||||||
|
}
|
||||||
if opts.Password != nil {
|
if opts.Password != nil {
|
||||||
modem.Authentication.Password = *opts.Password
|
modem.Authentication.Password = *opts.Password
|
||||||
}
|
}
|
||||||
|
|
||||||
if opts.Username != nil {
|
|
||||||
modem.Authentication.Username = *opts.Username
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := o.PostModem(ctx, modem); err != nil {
|
if _, err := o.PostModem(ctx, modem); err != nil {
|
||||||
@@ -388,9 +397,20 @@ func (o *Operations) SetModem(ctx context.Context, funcs ...protocol.SetModemOpt
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetModem implements protocol.Operations.
|
// GetModem implements protocol.Operations.
|
||||||
func (o *Operations) GetModemConfiguration(ctx context.Context) (any, error) {
|
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 {
|
if err != nil {
|
||||||
return nil, errors.WithStack(err)
|
return nil, errors.WithStack(err)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user