Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
auth "github.com/mutablelogic/go-server/pkg/auth/cmd"
certmanager "github.com/mutablelogic/go-server/pkg/cert/cmd"
cmd "github.com/mutablelogic/go-server/pkg/cmd"
ldap "github.com/mutablelogic/go-server/pkg/ldap/cmd"
pgmanager "github.com/mutablelogic/go-server/pkg/pgmanager/cmd"
pgqueue "github.com/mutablelogic/go-server/pkg/pgqueue/cmd"
)
Expand All @@ -31,6 +32,10 @@ type CLI struct {
auth.UserCommands
auth.TokenCommands
auth.AuthCommands

// LDAP commands
LDAP struct{ ldap.ObjectCommands } `cmd:""`

VersionCommands
}

Expand Down
15 changes: 15 additions & 0 deletions cmd/server/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
cert "github.com/mutablelogic/go-server/pkg/cert/config"
httprouter "github.com/mutablelogic/go-server/pkg/httprouter/config"
httpserver "github.com/mutablelogic/go-server/pkg/httpserver/config"
ldap "github.com/mutablelogic/go-server/pkg/ldap/config"
logger "github.com/mutablelogic/go-server/pkg/logger/config"
pg "github.com/mutablelogic/go-server/pkg/pgmanager/config"
pgqueue "github.com/mutablelogic/go-server/pkg/pgqueue/config"
Expand Down Expand Up @@ -199,6 +200,20 @@ func (cmd *ServiceRunCommand) Run(app server.Cmd) error {

return nil
}))

err = errors.Join(err, provider.Load("ldap", "main", func(ctx context.Context, label string, config server.Plugin) error {
ldap := config.(*ldap.Config)

// Set the router
if router, ok := ref.Provider(ctx).Task(ctx, "httprouter.main").(server.HTTPRouter); !ok || router == nil {
return httpresponse.ErrInternalError.With("Invalid router")
} else {
ldap.Router = router
}

return nil
}))

if err != nil {
return err
}
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/alecthomas/kong v1.10.0
github.com/djthorpe/go-marshaler v1.0.0
github.com/djthorpe/go-pg v1.0.6
github.com/go-ldap/ldap/v3 v3.4.11
github.com/golang-jwt/jwt/v5 v5.2.2
github.com/mutablelogic/go-client v1.0.12
github.com/stretchr/testify v1.10.0
Expand All @@ -14,6 +15,7 @@ require (
require (
dario.cat/mergo v1.0.0 // indirect
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/Azure/go-ntlmssp v0.0.0-20221128193559-754e69321358 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/containerd/containerd v1.7.27 // indirect
Expand All @@ -27,6 +29,7 @@ require (
github.com/docker/go-connections v0.5.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-asn1-ber/asn1-ber v1.5.8-0.20250403174932-29230038a667 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
Expand Down
22 changes: 22 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 h1:bvDV9
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24/go.mod h1:8o94RPi1/7XTJvwPpRSzSUedZrtlirdB3r9Z20bi2f8=
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8=
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
github.com/Azure/go-ntlmssp v0.0.0-20221128193559-754e69321358 h1:mFRzDkZVAjdal+s7s0MwaRv9igoPqLRdzOLzw/8Xvq8=
github.com/Azure/go-ntlmssp v0.0.0-20221128193559-754e69321358/go.mod h1:chxPXzSsl7ZWRAuOIE23GDNzjWuZquvFlgA8xmpunjU=
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
github.com/alecthomas/assert/v2 v2.11.0 h1:2Q9r3ki8+JYXvGsDyBXwH3LcJ+WK5D0gc5E8vS6K3D0=
Expand All @@ -12,6 +14,8 @@ github.com/alecthomas/kong v1.10.0 h1:8K4rGDpT7Iu+jEXCIJUeKqvpwZHbsFRoebLbnzlmrp
github.com/alecthomas/kong v1.10.0/go.mod h1:p2vqieVMeTAnaC83txKtXe8FLke2X07aruPWXyMPQrU=
github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc=
github.com/alecthomas/repr v0.4.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
github.com/alexbrainman/sspi v0.0.0-20231016080023-1a75b4708caa h1:LHTHcTQiSGT7VVbI0o4wBRNQIgn917usHWOd6VAffYI=
github.com/alexbrainman/sspi v0.0.0-20231016080023-1a75b4708caa/go.mod h1:cEWa1LVoE5KvSD9ONXsZrj0z6KqySlCCNKHlLzbqAt4=
github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM=
github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/containerd/containerd v1.7.27 h1:yFyEyojddO3MIGVER2xJLWoCIn+Up4GaHFquP7hsFII=
Expand Down Expand Up @@ -44,6 +48,10 @@ github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/go-asn1-ber/asn1-ber v1.5.8-0.20250403174932-29230038a667 h1:BP4M0CvQ4S3TGls2FvczZtj5Re/2ZzkV9VwqPHH/3Bo=
github.com/go-asn1-ber/asn1-ber v1.5.8-0.20250403174932-29230038a667/go.mod h1:hEBeB/ic+5LoWskz+yKT7vGhhPYkProFKoKdwZRWMe0=
github.com/go-ldap/ldap/v3 v3.4.11 h1:4k0Yxweg+a3OyBLjdYn5OKglv18JNvfDykSoI8bW0gU=
github.com/go-ldap/ldap/v3 v3.4.11/go.mod h1:bY7t0FLK8OAVpp/vV6sSlpz3EQDGcQwc8pF0ujLgKvM=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
Expand All @@ -65,6 +73,8 @@ github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 h1:YBftPWNWd4WwGqtY2yeZL2ef8rH
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0/go.mod h1:YN5jB8ie0yfIUg6VvR9Kz84aCaG7AsGZnLjhHbUqwPg=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8=
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
Expand All @@ -75,6 +85,18 @@ github.com/jackc/pgx/v5 v5.7.3 h1:PO1wNKj/bTAwxSJnO1Z4Ai8j4magtqg2SLNjEDzcXQo=
github.com/jackc/pgx/v5 v5.7.3/go.mod h1:ncY89UGWxg82EykZUwSpUKEfccBGGYq1xjrOpsbsfGQ=
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
github.com/jcmturner/aescts/v2 v2.0.0 h1:9YKLH6ey7H4eDBXW8khjYslgyqG2xZikXP0EQFKrle8=
github.com/jcmturner/aescts/v2 v2.0.0/go.mod h1:AiaICIRyfYg35RUkr8yESTqvSy7csK90qZ5xfvvsoNs=
github.com/jcmturner/dnsutils/v2 v2.0.0 h1:lltnkeZGL0wILNvrNiVCR6Ro5PGU/SeBvVO/8c/iPbo=
github.com/jcmturner/dnsutils/v2 v2.0.0/go.mod h1:b0TnjGOvI/n42bZa+hmXL+kFJZsFT7G4t3HTlQ184QM=
github.com/jcmturner/gofork v1.7.6 h1:QH0l3hzAU1tfT3rZCnW5zXl+orbkNMMRGJfdJjHVETg=
github.com/jcmturner/gofork v1.7.6/go.mod h1:1622LH6i/EZqLloHfE7IeZ0uEJwMSUyQ/nDd82IeqRo=
github.com/jcmturner/goidentity/v6 v6.0.1 h1:VKnZd2oEIMorCTsFBnJWbExfNN7yZr3EhJAxwOkZg6o=
github.com/jcmturner/goidentity/v6 v6.0.1/go.mod h1:X1YW3bgtvwAXju7V3LCIMpY0Gbxyjn/mY9zx4tFonSg=
github.com/jcmturner/gokrb5/v8 v8.4.4 h1:x1Sv4HaTpepFkXbt2IkL29DXRf8sOfZXo8eRKh687T8=
github.com/jcmturner/gokrb5/v8 v8.4.4/go.mod h1:1btQEpgT6k+unzCwX1KdWMEwPPkkgBtP+F6aCACiMrs=
github.com/jcmturner/rpc/v2 v2.0.3 h1:7FXXj8Ti1IaVFpSAziCZWNzbNuZmnvw/i6CqLNdWfZY=
github.com/jcmturner/rpc/v2 v2.0.3/go.mod h1:VUJYCIDm3PVOEHw8sgt091/20OJjskO/YJki3ELg/Hc=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.17.4 h1:Ej5ixsIri7BrIjBkRZLTo6ghwrEtHFk7ijlczPW4fZ4=
Expand Down
27 changes: 27 additions & 0 deletions pkg/ldap/client/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package client

import (
// Packages
client "github.com/mutablelogic/go-client"
)

///////////////////////////////////////////////////////////////////////////////
// TYPES

type Client struct {
*client.Client
}

///////////////////////////////////////////////////////////////////////////////
// LIFECYCLE

// Create a new client
func New(url string, opts ...client.ClientOpt) (*Client, error) {
c := new(Client)
if client, err := client.New(append(opts, client.OptEndpoint(url))...); err != nil {
return nil, err
} else {
c.Client = client
}
return c, nil
}
31 changes: 31 additions & 0 deletions pkg/ldap/client/objects.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package client

import (
"context"

// Packages
client "github.com/mutablelogic/go-client"
schema "github.com/mutablelogic/go-server/pkg/ldap/schema"
)

///////////////////////////////////////////////////////////////////////////////
// PUBLIC METHODS

func (c *Client) ListObjects(ctx context.Context, opts ...Opt) (*schema.ObjectList, error) {
req := client.NewRequest()

// Apply options
opt, err := applyOpts(opts...)
if err != nil {
return nil, err
}

// Perform request
var response schema.ObjectList
if err := c.DoWithContext(ctx, req, &response, client.OptPath("object"), client.OptQuery(opt.Values)); err != nil {
return nil, err
}

// Return the responses
return &response, nil
}
65 changes: 65 additions & 0 deletions pkg/ldap/client/opts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package client

import (
"fmt"
"net/url"

// Packages
types "github.com/mutablelogic/go-server/pkg/types"
)

////////////////////////////////////////////////////////////////////////////////
// TYPES

type opt struct {
url.Values
}

// An Option to set on the client
type Opt func(*opt) error

////////////////////////////////////////////////////////////////////////////////
// LIFECYCLE

func applyOpts(opts ...Opt) (*opt, error) {
o := new(opt)
o.Values = make(url.Values)
for _, opt := range opts {
if err := opt(o); err != nil {
return nil, err
}
}
return o, nil
}

////////////////////////////////////////////////////////////////////////////////
// OPTIONS

// Set offset and limit
func WithOffsetLimit(offset uint64, limit *uint64) Opt {
return func(o *opt) error {
if offset > 0 {
o.Set("offset", fmt.Sprint(offset))
}
if limit != nil {
o.Set("limit", fmt.Sprint(*limit))
}
return nil
}
}

// Set LDAP filter
func WithFilter(v *string) Opt {
return OptSet("filter", types.PtrString(v))
}

func OptSet(k, v string) Opt {
return func(o *opt) error {
if v == "" {
o.Del(k)
} else {
o.Set(k, v)
}
return nil
}
}
38 changes: 38 additions & 0 deletions pkg/ldap/cmd/object.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package cmd

import (
"context"
"fmt"

// Packages
server "github.com/mutablelogic/go-server"
client "github.com/mutablelogic/go-server/pkg/ldap/client"
schema "github.com/mutablelogic/go-server/pkg/ldap/schema"
)

///////////////////////////////////////////////////////////////////////////////
// TYPES

type ObjectCommands struct {
Objects ObjectListCommand `cmd:"" group:"LDAP" help:"List queues"`
}

type ObjectListCommand struct {
schema.ObjectListRequest
}

///////////////////////////////////////////////////////////////////////////////
// PUBLIC METHODS

func (cmd ObjectListCommand) Run(ctx server.Cmd) error {
return run(ctx, func(ctx context.Context, provider *client.Client) error {
queues, err := provider.ListObjects(ctx, client.WithFilter(cmd.Filter), client.WithOffsetLimit(cmd.Offset, cmd.Limit))
if err != nil {
return err
}

// Print queues
fmt.Println(queues)
return nil
})
}
23 changes: 23 additions & 0 deletions pkg/ldap/cmd/run.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package cmd

import (
"context"

// Packages
server "github.com/mutablelogic/go-server"
client "github.com/mutablelogic/go-server/pkg/ldap/client"
schema "github.com/mutablelogic/go-server/pkg/ldap/schema"
)

///////////////////////////////////////////////////////////////////////////////
// PRIVATE METHODS

func run(ctx server.Cmd, fn func(context.Context, *client.Client) error) error {
// Create a client
provider, err := client.New(ctx.GetEndpoint(schema.APIPrefix).String(), ctx.GetClientOpts()...)
if err != nil {
return err
}
// Run the function
return fn(ctx.Context(), provider)
}
66 changes: 66 additions & 0 deletions pkg/ldap/config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package config

import (
"context"
"net/url"

// Packages
server "github.com/mutablelogic/go-server"
ldap "github.com/mutablelogic/go-server/pkg/ldap"
handler "github.com/mutablelogic/go-server/pkg/ldap/handler"
schema "github.com/mutablelogic/go-server/pkg/ldap/schema"
)

////////////////////////////////////////////////////////////////////////////////
// TYPES

type Config struct {
Url *url.URL `env:"LDAP_URL" help:"LDAP connection URL"` // Connection URL
Password string `env:"LDAP_PASSWORD" help:"Password"` // Password
BaseDN string `env:"LDAP_BASE_DN" help:"Base DN"` // Base DN
Router server.HTTPRouter `kong:"-"` // HTTP Router
}

var _ server.Plugin = Config{}

////////////////////////////////////////////////////////////////////////////////
// LIFECYCLE

func (c Config) New(ctx context.Context) (server.Task, error) {
// Add options
opts := []ldap.Opt{}
if c.Url != nil {
opts = append(opts, ldap.WithUrl(c.Url.String()))
}
if c.Password != "" {
opts = append(opts, ldap.WithPassword(c.Password))
}
if c.BaseDN != "" {
opts = append(opts, ldap.WithBaseDN(c.BaseDN))
}

// Create a new LDAP manager
manager, err := ldap.NewManager(opts...)
if err != nil {
return nil, err
}

// Register HTTP handlers
if c.Router != nil {
handler.Register(ctx, c.Router, manager)
}

// Return the task
return NewTask(manager)
}

////////////////////////////////////////////////////////////////////////////////
// MODULE

func (c Config) Name() string {
return schema.SchemaName
}

func (c Config) Description() string {
return "LDAP manager"
}
Loading