Skip to content

Commit

Permalink
Refactor Credentials.Parse
Browse files Browse the repository at this point in the history
  • Loading branch information
inancgumus committed Nov 5, 2024
1 parent 53db24d commit 44fa0c0
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions common/network_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ func NewCredentials() *Credentials {

// Parse credentials details from a given sobek credentials value.
func (c *Credentials) Parse(ctx context.Context, credentials sobek.Value) error {
rt := k6ext.Runtime(ctx)
if credentials != nil && !sobek.IsUndefined(credentials) && !sobek.IsNull(credentials) {
credentials := credentials.ToObject(rt)
for _, k := range credentials.Keys() {
switch k {
case "username":
c.Username = credentials.Get(k).String()
case "password":
c.Password = credentials.Get(k).String()
}
if !sobekValueExists(credentials) {
return errors.New("credentials are required")
}
o := credentials.ToObject(k6ext.Runtime(ctx))
for _, k := range o.Keys() {
switch k {
case "username":
c.Username = o.Get(k).String()
case "password":
c.Password = o.Get(k).String()
}
}

Expand Down

0 comments on commit 44fa0c0

Please sign in to comment.