Skip to content

Commit

Permalink
🐛 fix some logic
Browse files Browse the repository at this point in the history
  • Loading branch information
pikachu0310 committed Sep 30, 2024
1 parent 030f536 commit e811a9d
Showing 1 changed file with 31 additions and 21 deletions.
52 changes: 31 additions & 21 deletions grpc/federation/cel/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,28 @@ func (x *URL) GoURL() (url.URL, error) {
}

return url.URL{
Scheme: x.GetScheme(),
Opaque: x.GetOpaque(),
User: user,
Host: x.GetHost(),
Path: x.GetPath(),
RawPath: x.GetRawPath(),
ForceQuery: x.GetForceQuery(),
RawQuery: x.GetRawQuery(),
Fragment: x.GetFragment(),
Scheme: x.GetScheme(),
Opaque: x.GetOpaque(),
User: user,
Host: x.GetHost(),
Path: x.GetPath(),
RawPath: x.GetRawPath(),
OmitHost: x.GetOmitHost(),
ForceQuery: x.GetForceQuery(),
RawQuery: x.GetRawQuery(),
Fragment: x.GetFragment(),
RawFragment: x.GetRawFragment(),
}, nil
}

func (x *Userinfo) GoUserinfo() (*url.Userinfo, error) {
if x == nil {
return nil, nil
}
if x.GetPasswordSet() {
return url.UserPassword(x.GetUsername(), x.GetPassword()), nil
} else {
return url.User(x.GetUsername()), nil
}
return url.User(x.GetUsername()), nil
}

var _ cel.SingletonLibrary = new(URLLibrary)
Expand Down Expand Up @@ -267,17 +271,27 @@ func (lib *URLLibrary) CompileOptions() []cel.EnvOption {
},
),
),
// forceQuery is changed to return String
BindMemberFunction(
"omitHost",
MemberOverloadFunc(createURLID("omitHost_url_bool"), URLType, []*cel.Type{}, cel.BoolType,
func(_ context.Context, self ref.Val, args ...ref.Val) ref.Val {
v, err := self.Value().(*URL).GoURL()
if err != nil {
return types.NewErr(err.Error())
}
return types.Bool(v.OmitHost)
},
),
),
BindMemberFunction(
"forceQuery",
MemberOverloadFunc(createURLID("forceQuery_url_string"), URLType, []*cel.Type{}, cel.StringType,
MemberOverloadFunc(createURLID("forceQuery_url_string"), URLType, []*cel.Type{}, cel.BoolType,
func(_ context.Context, self ref.Val, args ...ref.Val) ref.Val {
v, err := self.Value().(*URL).GoURL()
if err != nil {
return types.NewErr(err.Error())
}
v.ForceQuery = true
return types.String(v.String())
return types.Bool(v.ForceQuery)
},
),
),
Expand Down Expand Up @@ -565,12 +579,8 @@ func (lib *URLLibrary) CompileOptions() []cel.EnvOption {
if err != nil {
return types.NewErr(err.Error())
}
password, hasPassword := v.Password()
if hasPassword {
return types.String(password)
} else {
return types.String("")
}
password, _ := v.Password()
return types.String(password)
},
),
),
Expand Down

0 comments on commit e811a9d

Please sign in to comment.