clients

package
v0.0.0-...-6553033 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2024 License: MIT Imports: 20 Imported by: 0

README

Keycloak API strategy

  1. Request groups from kc /admin/realms/{realm}/groups/{id}
  2. Request roles of groups from kc /admin/realms/{realm}/groups/{id}

Case 1: Only kc groups are requested

  1. Get members of requested groups from kc /admin/realms/{realm}/groups/{id}/members
  2. Map kc groups and roles to members

Case 2: Some kc roles are requested

  1. Get groups for every requested roles
  2. Get all requested groups and merge with groups from step 3
  3. Get all groups of users from kc /admin/realms/{realm}/users/{id}/groups
  4. Get all roles of users from kc /admin/realms/{realm}/users/{id}/role-mappings/realm
  5. Map kc groups and roles to users

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AccessToValueMap = map[string]gitlab.AccessLevelValue{
	"Guest":      gitlab.GuestPermissions,
	"Reporter":   gitlab.ReporterPermissions,
	"Developer":  gitlab.DeveloperPermissions,
	"Maintainer": gitlab.MaintainerPermissions,
	"Owner":      gitlab.OwnerPermissions,
}

Functions

func DoHttpRequest

func DoHttpRequest(client ApiClient, options *HttpRequestOptions) (*http.Response, error)

func DoHttpRequestWithResult

func DoHttpRequestWithResult[T any](client ApiClient, options *HttpRequestOptions, result *T) (*http.Response, error)

func StartMockServer

func StartMockServer(ctx context.Context, config *KeycloakMockServerConfig) *http.Server

Types

type ApiClient

type ApiClient interface {
	GetName() string
	GetBaseUrl() string
	GetAuthorizationType() AuthorizationType
	GetAuthorization() string
}

type AuthorizationType

type AuthorizationType string
const (
	AuthorizationTypeApiKey AuthorizationType = "API_KEY"
	AuthorizationTypeBearer AuthorizationType = "BEARER"
)

type Client

type Client interface {
	TestConnection() error
}

type ClientSet

type ClientSet struct {
	KeycloakClients map[string]*KeycloakClient
	MailcowClients  map[string]*MailcowClient
	OutlineClients  map[string]*OutlineClient
	GitLabClients   map[string]*GitLabClient
}

func GetClientSet

func GetClientSet(config *config.BrokeConfig) (*ClientSet, error)

func (*ClientSet) GetUserSourceClient

func (c *ClientSet) GetUserSourceClient(userSource config.UserSourceConfig) (*KeycloakClient, error)

func (*ClientSet) GetUserTargetGitLabClient

func (c *ClientSet) GetUserTargetGitLabClient(userTarget *config.UserTargetConfig) (*GitLabClient, error)

func (*ClientSet) GetUserTargetMailcowClient

func (c *ClientSet) GetUserTargetMailcowClient(userTarget *config.UserTargetConfig) (*MailcowClient, error)

func (*ClientSet) GetUserTargetOutlineClient

func (c *ClientSet) GetUserTargetOutlineClient(userTarget *config.UserTargetConfig) (*OutlineClient, error)

func (*ClientSet) TestConnections

func (c *ClientSet) TestConnections() error

type CreateMailboxOptions

type CreateMailboxOptions struct {
	Name       string `json:"name"`
	Domain     string `json:"domain"`
	LocalPart  string `json:"local_part"`
	AuthSource string `json:"authsource"`
}

type GitLabClient

type GitLabClient struct {
	Client  *gitlab.Client
	Options *GitLabClientOptions
}

func NewGitLabClient

func NewGitLabClient(config *GitLabClientOptions) (*GitLabClient, error)

func (*GitLabClient) TestConnection

func (c *GitLabClient) TestConnection() error

type GitLabClientOptions

type GitLabClientOptions struct {
	Name  string `yaml:"name"`
	Url   string `yaml:"url"`
	Token string `yaml:"token"`
}

type HttpMethod

type HttpMethod string
const (
	GET    HttpMethod = "GET"
	POST   HttpMethod = "POST"
	PUT    HttpMethod = "PUT"
	DELETE HttpMethod = "DELETE"
)

type HttpRequestOptions

type HttpRequestOptions struct {
	Method             HttpMethod
	ContextPath        string
	Body               interface{}
	ExpectedStatusCode int
}

type JWT

type JWT struct {
	AccessToken      string `json:"access_token"`
	ExpiresIn        int    `json:"expires_in"`
	RefreshExpiresIn int    `json:"refresh_expires_in"`
	RefreshToken     string `json:"refresh_token"`
	TokenType        string `json:"token_type"`
	Scope            string `json:"scope"`
}

type KeycloakClient

type KeycloakClient struct {
	Client  *gocloak.GoCloak
	Token   *gocloak.JWT
	Realm   string
	Options *KeycloakClientOptions
}

func NewKeycloakClient

func NewKeycloakClient(ctx context.Context, options *KeycloakClientOptions) (*KeycloakClient, error)

func (*KeycloakClient) GetBrokeUserList

func (k *KeycloakClient) GetBrokeUserList(ctx context.Context) ([]*user.User, error)

func (*KeycloakClient) GetFullGroupList

func (k *KeycloakClient) GetFullGroupList(ctx context.Context) ([]*gocloak.Group, error)

func (*KeycloakClient) GetGroup

func (k *KeycloakClient) GetGroup(ctx context.Context, id string) (*gocloak.Group, error)

func (*KeycloakClient) GetGroupUsers

func (k *KeycloakClient) GetGroupUsers(ctx context.Context, id string) ([]*gocloak.User, error)

func (*KeycloakClient) GetGroups

func (k *KeycloakClient) GetGroups(ctx context.Context) ([]*gocloak.Group, error)

func (*KeycloakClient) GetGroupsCount

func (k *KeycloakClient) GetGroupsCount(ctx context.Context) (int, error)

func (*KeycloakClient) GetRoleUsers

func (k *KeycloakClient) GetRoleUsers(ctx context.Context, name string) ([]*gocloak.User, error)

func (*KeycloakClient) GetUserGroups

func (k *KeycloakClient) GetUserGroups(ctx context.Context, id string) ([]*gocloak.Group, error)

func (*KeycloakClient) GetUserRealmRoles

func (k *KeycloakClient) GetUserRealmRoles(ctx context.Context, id string) (*gocloak.MappingsRepresentation, error)

func (*KeycloakClient) GetUsers

func (k *KeycloakClient) GetUsers(ctx context.Context) ([]*gocloak.User, error)

func (*KeycloakClient) GetUsersCount

func (k *KeycloakClient) GetUsersCount(ctx context.Context) (int, error)

func (*KeycloakClient) TestConnection

func (c *KeycloakClient) TestConnection() error

type KeycloakClientOptions

type KeycloakClientOptions struct {
	Name     string `yaml:"name"`
	Url      string `yaml:"url"`
	Realm    string `yaml:"realm"`
	Username string `yaml:"username"`
	Password string `yaml:"password"`
	Insecure *bool  `yaml:"insecure,omitempty"`
}

type KeycloakMockServerAccess

type KeycloakMockServerAccess struct {
	View             bool `json:"view"`
	Manage           bool `json:"manage"`
	ViewMembers      bool `json:"viewMembers"`
	ManageMembers    bool `json:"manageMembers"`
	ManageMembership bool `json:"manageMembership"`
}

type KeycloakMockServerConfig

type KeycloakMockServerConfig struct {
	Port          int                    `yaml:"port"`
	AdminUsername string                 `yaml:"adminUsername"`
	AdminPassword string                 `yaml:"adminPassword"`
	Realm         string                 `yaml:"realm"`
	Data          KeycloakMockServerData `yaml:"data"`
}

type KeycloakMockServerData

type KeycloakMockServerData struct {
	Users  []KeycloakMockServerUser  `json:"users"`
	Groups []KeycloakMockServerGroup `json:"groups"`
}

type KeycloakMockServerGroup

type KeycloakMockServerGroup struct {
	Id         string                   `json:"id"`
	Name       string                   `json:"name"`
	Path       string                   `json:"path"`
	SubGroups  []string                 `json:"subGroups"`
	RealmRoles []string                 `json:"realmRoles"`
	Access     KeycloakMockServerAccess `json:"access"`
}

type KeycloakMockServerUser

type KeycloakMockServerUser struct {
	Id            string   `json:"id"`
	Username      string   `json:"username"`
	Enabled       bool     `json:"enabled"`
	EmailVerified bool     `json:"emailVerified"`
	FirstName     string   `json:"firstName"`
	LastName      string   `json:"lastName"`
	Email         string   `json:"email"`
	Groups        []string `json:"groups"`
}

type MailcowClient

type MailcowClient struct {
	Options *MailcowClientOptions
}

func NewMailcowClient

func NewMailcowClient(options *MailcowClientOptions) (*MailcowClient, error)

func (*MailcowClient) CreateMailbox

func (c *MailcowClient) CreateMailbox(options *CreateMailboxOptions) error

func (MailcowClient) GetAuthorization

func (c MailcowClient) GetAuthorization() string

func (MailcowClient) GetAuthorizationType

func (c MailcowClient) GetAuthorizationType() AuthorizationType

func (MailcowClient) GetBaseUrl

func (c MailcowClient) GetBaseUrl() string

func (MailcowClient) GetName

func (c MailcowClient) GetName() string

func (*MailcowClient) MailboxExists

func (c *MailcowClient) MailboxExists(email string) (bool, error)

func (*MailcowClient) TestConnection

func (c *MailcowClient) TestConnection() error

type MailcowClientOptions

type MailcowClientOptions struct {
	Name   string
	Url    string
	ApiKey string
}

type MailcowMailboxResult

type MailcowMailboxResult struct {
	Active    int    `json:"active"`
	Username  string `json:"username"`
	Domain    string `json:"domain"`
	LocalPart string `json:"local_part"`
	Name      string `json:"name"`
}

type OutlineClient

type OutlineClient struct {
	Options *OutlineClientOptions
}

func NewOutlineClient

func NewOutlineClient(options *OutlineClientOptions) (*OutlineClient, error)

func (OutlineClient) GetAuthorization

func (c OutlineClient) GetAuthorization() string

func (OutlineClient) GetAuthorizationType

func (c OutlineClient) GetAuthorizationType() AuthorizationType

func (OutlineClient) GetBaseUrl

func (c OutlineClient) GetBaseUrl() string

func (OutlineClient) GetName

func (c OutlineClient) GetName() string

func (*OutlineClient) GetUserIdByMail

func (c *OutlineClient) GetUserIdByMail(mail string) (*string, error)

func (*OutlineClient) TestConnection

func (c *OutlineClient) TestConnection() error

type OutlineClientOptions

type OutlineClientOptions struct {
	Name  string
	Url   string
	Token string
}

type Pagination

type Pagination struct {
	Offset int `json:"offset"`
	Limit  int `json:"limit"`
}

type User

type User struct {
	ID           string    `json:"id"`
	Name         string    `json:"name"`
	AvatarUrl    string    `json:"avatarUrl"`
	Email        string    `json:"email"`
	Role         string    `json:"role"`
	IsSuspended  bool      `json:"isSuspended"`
	LastActiveAt time.Time `json:"lastActiveAt"`
	CreatedAt    time.Time `json:"createdAt"`
}

type UserQueryOptions

type UserQueryOptions struct {
	Username string   `json:"username,omitempty"`
	Emails   []string `json:"emails,omitempty"`
}

type UsersResponse

type UsersResponse struct {
	Data       []User     `json:"data"`
	Pagination Pagination `json:"pagination"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL