Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate sessions-storage apis from v27 #129

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 1 addition & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ jobs:
build:
runs-on: ubuntu-latest
steps:

- name: golang
uses: actions/setup-go@v2
with:
go-version: 1.18
go-version: 1.19
iljaSL marked this conversation as resolved.
Show resolved Hide resolved

- name: checkout
uses: actions/checkout@v2
Expand Down
81 changes: 81 additions & 0 deletions api/auth/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,84 @@ func (store *Auth) RegenerateIdpClientConfig(idpID string) (*IdpClientConfig, er

return clientConfig, err
}

// UserSessions fetches valid sessions by userID.
func (store *Auth) UserSessions(offset, limit int, sortkey, sortdir, userID string) (*sessionsResult, error) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 2 locations. Consider refactoring.

filters := Params{
Offset: offset,
Limit: limit,
Sortkey: sortkey,
Sortdir: sortdir,
}
userSessions := &sessionsResult{}

_, err := store.api.
URL("/auth/api/v1/sessionstorage/users/%s/sessions", userID).
Query(&filters).
Get(&userSessions)

return userSessions, err
}

// SourceSessions fetches valid sessions by sourceID.
func (store *Auth) SourceSessions(offset, limit int, sortkey, sortdir, sourceID string) (*sessionsResult, error) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 2 locations. Consider refactoring.

filters := Params{
Offset: offset,
Limit: limit,
Sortkey: sortkey,
Sortdir: sortdir,
}
sourceSessions := &sessionsResult{}

_, err := store.api.
URL("/auth/api/v1/sessionstorage/sources/%s/sessions", sourceID).
Query(&filters).
Get(&sourceSessions)

return sourceSessions, err
}

// SearchSessions searches for sessions
func (store *Auth) SearchSessions(offset, limit int, sortkey, sortdir string, search *SearchParams) (*sessionsResult, error) {
filters := Params{
Offset: offset,
Limit: limit,
Sortkey: sortkey,
Sortdir: sortdir,
}
sessions := &sessionsResult{}

_, err := store.api.
URL("/auth/api/v1/sessionstorage/sessions/search").
Query(&filters).
Post(search, &sessions)

return sessions, err
}

// TerminateSession terminates single session by ID.
func (store *Auth) TerminateSession(sessionID string) error {

_, err := store.api.
URL("/auth/api/v1/sessionstorage/sessions/%s/terminate", sessionID).
Post(nil)
return err
}

// TerminateUserSessions terminates all sessions for a user.
func (store *Auth) TerminateUserSessions(userID string) error {

_, err := store.api.
URL("/auth/api/v1/sessionstorage/users/%s/sessions/terminate", userID).
Post(nil)
return err
}

// Logout logs out user.
func (store *Auth) Logout() error {

_, err := store.api.
URL("/auth/api/v1/logout").
Post(nil)
return err
}
37 changes: 37 additions & 0 deletions api/auth/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ type KeyValue struct {
Value string `json:"v"`
}

// Params query params definition
type Params struct {
Sortkey string `json:"sortkey,omitempty"`
Sortdir string `json:"sortdir,omitempty"`
Offset int `json:"offset,omitempty"`
Limit int `json:"limit,omitempty"`
}

// ServiceStatus auth service status definition
type ServiceStatus struct {
Variant string `json:"variant,omitempty"`
Expand Down Expand Up @@ -71,3 +79,32 @@ type IdpClientConfig struct {
type IDstruct struct {
ID string `json:"id"`
}

type Session struct {
ID string `json:"id"`
UserID string `json:"user_id"`
SourceID string `json:"source_id"`
Domain string `json:"domain"`
Username string `json:"username"`
RemoteAddr string `json:"remote_addr"`
UserAgent string `json:"user_agent"`
Type string `json:"type" jsonschema:"enum=login,enum=sso"`
iljaSL marked this conversation as resolved.
Show resolved Hide resolved
Created time.Time `json:"created"`
Updated time.Time `json:"updated"`
Expires time.Time `json:"expires"`
TokenExpires time.Time `json:"token_expires"`
LoggedOut bool `json:"logged_out"`
Current bool `json:"current,omitempty"`
}

type sessionsResult struct {
Items []Session `json:"items"`
Count int `json:"count"`
}

// SearchParams search params definition
type SearchParams struct {
Keywords string `json:"keywords,omitempty"`
UserID string `json:"user_id,omitempty"`
Type string `json:"type.omitempty" jsonschema:"enum=login,enum=sso"`
iljaSL marked this conversation as resolved.
Show resolved Hide resolved
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/SSHcom/privx-sdk-go

go 1.18
go 1.19
iljaSL marked this conversation as resolved.
Show resolved Hide resolved

require (
github.com/BurntSushi/toml v1.1.0
Expand Down