mirror of
https://github.com/mainflux/mainflux.git
synced 2025-05-02 22:17:10 +08:00

* Upgrade InfluxDB from 1.x to 2.x Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Influx DB configuration updated Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Connection to InfluxDBv2 Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Token cannot be created Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Connected to InfluxDB2 Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Connected to InfluxDB2 Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * InfluxDB v2 Consumer Implementation Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * quickfix Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Influxdb-Writer Unit Tests Update Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Consumer Update Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * InfluxDB Writer Tests Implemented Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * fix Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * InfluxDB Connection Check Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Resolving Remarks Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Resolved consumer-test remark Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * consumer-test slow working version Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * reader changes Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Consumer tests time issue fixed Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Eof warning fixed Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Resolved Reviews Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Makefile Fixed Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Resolved Reviews Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Resolved Reviews Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Resolved Reviews Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Resolved Reviews Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Resolved Reviews Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Readers Initial Setup Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * consumer json fix Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * readers simple version Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * readers simple version fix Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * readers simple version fix Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * readers simple version fix Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * readers simple version fix Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * readers simple version fix Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * readers simple version fix Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Influxdb Reader Parsers Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Influxdb Reader Parsers Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Influxdb Reader Parsers Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Bugfix and resolves comments. Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * one test fails Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * solved last page read Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * writers future time problem fixed Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * weird Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * weird Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Tests Passes Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Resolve Semaphore Issues Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * UUID comment on consumer tests resolved Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Inclusive from and Exclusive to Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Inclusive from and Exclusive to Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * 1 second limits Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * 1 second limits Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * resolved review Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * resolved review Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * resolved review Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * resolved review Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * fixed json time Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * fixed CI error Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * resolved request Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * resolved request Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * resolved requests Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * removed blank line Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * resolved comment Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * deleted unnecessary string builder Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * initial commit Signed-off-by: aryan <aryangodara03@gmail.com> * change influxdb docker image version. Signed-off-by: aryan <aryangodara03@gmail.com> * go mod and vendor fixing Signed-off-by: aryan <aryangodara03@gmail.com> * Upgrade InfluxDB from 1.x to 2.x Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Influx DB configuration updated Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Connection to InfluxDBv2 Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Token cannot be created Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Connected to InfluxDB2 Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Connected to InfluxDB2 Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * InfluxDB v2 Consumer Implementation Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * quickfix Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Influxdb-Writer Unit Tests Update Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Consumer Update Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * InfluxDB Writer Tests Implemented Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * fix Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * InfluxDB Connection Check Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Resolving Remarks Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Resolved consumer-test remark Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * consumer-test slow working version Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * reader changes Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Consumer tests time issue fixed Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Resolved Reviews Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Resolved Reviews Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Resolved Reviews Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Resolved Reviews Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Resolved Reviews Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Resolved Reviews Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Readers Initial Setup Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * consumer json fix Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * readers simple version Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * readers simple version fix Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * readers simple version fix Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * readers simple version fix Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * readers simple version fix Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * readers simple version fix Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * readers simple version fix Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Influxdb Reader Parsers Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Influxdb Reader Parsers Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Influxdb Reader Parsers Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Bugfix and resolves comments. Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * one test fails Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * solved last page read Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * writers future time problem fixed Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * weird Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * weird Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Tests Passes Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Resolve Semaphore Issues Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * UUID comment on consumer tests resolved Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Inclusive from and Exclusive to Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * Inclusive from and Exclusive to Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * 1 second limits Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * 1 second limits Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * resolved review Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * resolved review Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * resolved review Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * resolved review Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * fixed json time Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * fixed CI error Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * resolved request Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * resolved request Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * resolved requests Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * removed blank line Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * resolved comment Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * deleted unnecessary string builder Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> * initial commit Signed-off-by: aryan <aryangodara03@gmail.com> * change influxdb docker image version. Signed-off-by: aryan <aryangodara03@gmail.com> * go mod and vendor fixing Signed-off-by: aryan <aryangodara03@gmail.com> * go mod fixing Signed-off-by: aryan <aryangodara03@gmail.com> * make tests pass locally, fix errors Signed-off-by: aryan <aryangodara03@gmail.com> * rem unsused variables/consts Signed-off-by: aryan <aryangodara03@gmail.com> * go mod tidy vendor Signed-off-by: aryan <aryangodara03@gmail.com> * add env var and data types Signed-off-by: aryan <aryangodara03@gmail.com> * update influxdb version to latest (2.3 to 2.12) Signed-off-by: aryan <aryangodara03@gmail.com> * change time precision for message tests Signed-off-by: aryan <aryangodara03@gmail.com> * renamed influxdb2 to influxdata Signed-off-by: aryan <aryangodara03@gmail.com> * address remarks on PR Signed-off-by: aryan <aryangodara03@gmail.com> * update influxbd according to latest mf commit Signed-off-by: aryan <aryangodara03@gmail.com> * temp commit, rem before pushing Signed-off-by: aryan <aryangodara03@gmail.com> * update main files and cassandra-reader messages_tests Signed-off-by: aryan <aryangodara03@gmail.com> * fix name of logger while importing Signed-off-by: aryan <aryangodara03@gmail.com> * remove unnecessary print lines Signed-off-by: aryan <aryangodara03@gmail.com> * correct env var name Signed-off-by: aryan <aryangodara03@gmail.com> * change to async consume Signed-off-by: aryan <aryangodara03@gmail.com> * add option to switch bw sync and async Signed-off-by: aryan <aryangodara03@gmail.com> * test for both async and sync Signed-off-by: aryan <aryangodara03@gmail.com> * update consumer and add writeAPIs to config Signed-off-by: aryan <aryangodara03@gmail.com> * revert back to sync consuming Signed-off-by: aryan <aryangodara03@gmail.com> * temp fix for default timeout value Signed-off-by: aryan <aryangodara03@gmail.com> * set default timeout in config. Signed-off-by: aryan <aryangodara03@gmail.com> * remove unwanted env vars, add required ones. Signed-off-by: aryan <aryangodara03@gmail.com> * rem unused username password from config Signed-off-by: aryan <aryangodara03@gmail.com> * update readme, env vars, and remove grafana Signed-off-by: aryan <aryangodara03@gmail.com> * update readme Signed-off-by: aryan <aryangodara03@gmail.com> * fix typo Signed-off-by: aryan <aryangodara03@gmail.com> * update readme description. Signed-off-by: aryan <aryangodara03@gmail.com> * fix more typos. Signed-off-by: aryan <aryangodara03@gmail.com> * add link to official docs to readme. Signed-off-by: aryan <aryangodara03@gmail.com> --------- Signed-off-by: fatih <fatihdurmaz@sabanciuniv.edu> Signed-off-by: aryan <aryangodara03@gmail.com> Co-authored-by: fatih <fatihdurmaz@sabanciuniv.edu> Co-authored-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com>
242 lines
7.3 KiB
Go
242 lines
7.3 KiB
Go
// Copyright 2020-2021 InfluxData, Inc. All rights reserved.
|
|
// Use of this source code is governed by MIT
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package api
|
|
|
|
import (
|
|
"context"
|
|
"encoding/base64"
|
|
"fmt"
|
|
nethttp "net/http"
|
|
"net/http/cookiejar"
|
|
"sync"
|
|
|
|
"github.com/influxdata/influxdb-client-go/v2/api/http"
|
|
"github.com/influxdata/influxdb-client-go/v2/domain"
|
|
"golang.org/x/net/publicsuffix"
|
|
)
|
|
|
|
// UsersAPI provides methods for managing users in a InfluxDB server
|
|
type UsersAPI interface {
|
|
// GetUsers returns all users
|
|
GetUsers(ctx context.Context) (*[]domain.User, error)
|
|
// FindUserByID returns user with userID
|
|
FindUserByID(ctx context.Context, userID string) (*domain.User, error)
|
|
// FindUserByName returns user with name userName
|
|
FindUserByName(ctx context.Context, userName string) (*domain.User, error)
|
|
// CreateUser creates new user
|
|
CreateUser(ctx context.Context, user *domain.User) (*domain.User, error)
|
|
// CreateUserWithName creates new user with userName
|
|
CreateUserWithName(ctx context.Context, userName string) (*domain.User, error)
|
|
// UpdateUser updates user
|
|
UpdateUser(ctx context.Context, user *domain.User) (*domain.User, error)
|
|
// UpdateUserPassword sets password for a user
|
|
UpdateUserPassword(ctx context.Context, user *domain.User, password string) error
|
|
// UpdateUserPasswordWithID sets password for a user with userID
|
|
UpdateUserPasswordWithID(ctx context.Context, userID string, password string) error
|
|
// DeleteUserWithID deletes an user with userID
|
|
DeleteUserWithID(ctx context.Context, userID string) error
|
|
// DeleteUser deletes an user
|
|
DeleteUser(ctx context.Context, user *domain.User) error
|
|
// Me returns actual user
|
|
Me(ctx context.Context) (*domain.User, error)
|
|
// MeUpdatePassword set password of actual user
|
|
MeUpdatePassword(ctx context.Context, oldPassword, newPassword string) error
|
|
// SignIn exchanges username and password credentials to establish an authenticated session with the InfluxDB server. The Client's authentication token is then ignored, it can be empty.
|
|
SignIn(ctx context.Context, username, password string) error
|
|
// SignOut signs out previously signed-in user
|
|
SignOut(ctx context.Context) error
|
|
}
|
|
|
|
// usersAPI implements UsersAPI
|
|
type usersAPI struct {
|
|
apiClient *domain.Client
|
|
httpService http.Service
|
|
httpClient *nethttp.Client
|
|
deleteCookieJar bool
|
|
lock sync.Mutex
|
|
}
|
|
|
|
// NewUsersAPI creates new instance of UsersAPI
|
|
func NewUsersAPI(apiClient *domain.Client, httpService http.Service, httpClient *nethttp.Client) UsersAPI {
|
|
return &usersAPI{
|
|
apiClient: apiClient,
|
|
httpService: httpService,
|
|
httpClient: httpClient,
|
|
}
|
|
}
|
|
|
|
func (u *usersAPI) GetUsers(ctx context.Context) (*[]domain.User, error) {
|
|
params := &domain.GetUsersParams{}
|
|
response, err := u.apiClient.GetUsers(ctx, params)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return userResponsesToUsers(response.Users), nil
|
|
}
|
|
|
|
func (u *usersAPI) FindUserByID(ctx context.Context, userID string) (*domain.User, error) {
|
|
params := &domain.GetUsersIDAllParams{
|
|
UserID: userID,
|
|
}
|
|
response, err := u.apiClient.GetUsersID(ctx, params)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return userResponseToUser(response), nil
|
|
}
|
|
|
|
func (u *usersAPI) FindUserByName(ctx context.Context, userName string) (*domain.User, error) {
|
|
users, err := u.GetUsers(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var user *domain.User
|
|
for _, u := range *users {
|
|
if u.Name == userName {
|
|
user = &u
|
|
break
|
|
}
|
|
}
|
|
if user == nil {
|
|
return nil, fmt.Errorf("user '%s' not found", userName)
|
|
}
|
|
return user, nil
|
|
}
|
|
|
|
func (u *usersAPI) CreateUserWithName(ctx context.Context, userName string) (*domain.User, error) {
|
|
user := &domain.User{Name: userName}
|
|
return u.CreateUser(ctx, user)
|
|
}
|
|
|
|
func (u *usersAPI) CreateUser(ctx context.Context, user *domain.User) (*domain.User, error) {
|
|
params := &domain.PostUsersAllParams{
|
|
Body: domain.PostUsersJSONRequestBody(*user),
|
|
}
|
|
response, err := u.apiClient.PostUsers(ctx, params)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return userResponseToUser(response), nil
|
|
}
|
|
|
|
func (u *usersAPI) UpdateUser(ctx context.Context, user *domain.User) (*domain.User, error) {
|
|
params := &domain.PatchUsersIDAllParams{
|
|
Body: domain.PatchUsersIDJSONRequestBody(*user),
|
|
UserID: *user.Id,
|
|
}
|
|
response, err := u.apiClient.PatchUsersID(ctx, params)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return userResponseToUser(response), nil
|
|
}
|
|
|
|
func (u *usersAPI) UpdateUserPassword(ctx context.Context, user *domain.User, password string) error {
|
|
return u.UpdateUserPasswordWithID(ctx, *user.Id, password)
|
|
}
|
|
|
|
func (u *usersAPI) UpdateUserPasswordWithID(ctx context.Context, userID string, password string) error {
|
|
params := &domain.PostUsersIDPasswordAllParams{
|
|
UserID: userID,
|
|
Body: domain.PostUsersIDPasswordJSONRequestBody(domain.PasswordResetBody{Password: password}),
|
|
}
|
|
return u.apiClient.PostUsersIDPassword(ctx, params)
|
|
}
|
|
|
|
func (u *usersAPI) DeleteUser(ctx context.Context, user *domain.User) error {
|
|
return u.DeleteUserWithID(ctx, *user.Id)
|
|
}
|
|
|
|
func (u *usersAPI) DeleteUserWithID(ctx context.Context, userID string) error {
|
|
params := &domain.DeleteUsersIDAllParams{
|
|
UserID: userID,
|
|
}
|
|
return u.apiClient.DeleteUsersID(ctx, params)
|
|
}
|
|
|
|
func (u *usersAPI) Me(ctx context.Context) (*domain.User, error) {
|
|
params := &domain.GetMeParams{}
|
|
response, err := u.apiClient.GetMe(ctx, params)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return userResponseToUser(response), nil
|
|
}
|
|
|
|
func (u *usersAPI) MeUpdatePassword(ctx context.Context, oldPassword, newPassword string) error {
|
|
u.lock.Lock()
|
|
defer u.lock.Unlock()
|
|
me, err := u.Me(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
creds := base64.StdEncoding.EncodeToString([]byte(me.Name + ":" + oldPassword))
|
|
auth := u.httpService.Authorization()
|
|
defer u.httpService.SetAuthorization(auth)
|
|
u.httpService.SetAuthorization("Basic " + creds)
|
|
params := &domain.PutMePasswordAllParams{
|
|
Body: domain.PutMePasswordJSONRequestBody(domain.PasswordResetBody{Password: newPassword}),
|
|
}
|
|
return u.apiClient.PutMePassword(ctx, params)
|
|
}
|
|
|
|
func (u *usersAPI) SignIn(ctx context.Context, username, password string) error {
|
|
u.lock.Lock()
|
|
defer u.lock.Unlock()
|
|
if u.httpClient.Jar == nil {
|
|
jar, err := cookiejar.New(&cookiejar.Options{PublicSuffixList: publicsuffix.List})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
u.httpClient.Jar = jar
|
|
u.deleteCookieJar = true
|
|
}
|
|
creds := base64.StdEncoding.EncodeToString([]byte(username + ":" + password))
|
|
u.httpService.SetAuthorization("Basic " + creds)
|
|
defer u.httpService.SetAuthorization("")
|
|
return u.apiClient.PostSignin(ctx, &domain.PostSigninParams{})
|
|
}
|
|
|
|
func (u *usersAPI) SignOut(ctx context.Context) error {
|
|
u.lock.Lock()
|
|
defer u.lock.Unlock()
|
|
err := u.apiClient.PostSignout(ctx, &domain.PostSignoutParams{})
|
|
if u.deleteCookieJar {
|
|
u.httpClient.Jar = nil
|
|
}
|
|
return err
|
|
}
|
|
|
|
func userResponseToUser(ur *domain.UserResponse) *domain.User {
|
|
if ur == nil {
|
|
return nil
|
|
}
|
|
user := &domain.User{
|
|
Id: ur.Id,
|
|
Name: ur.Name,
|
|
Status: userResponseStatusToUserStatus(ur.Status),
|
|
}
|
|
return user
|
|
}
|
|
|
|
func userResponseStatusToUserStatus(urs *domain.UserResponseStatus) *domain.UserStatus {
|
|
if urs == nil {
|
|
return nil
|
|
}
|
|
us := domain.UserStatus(*urs)
|
|
return &us
|
|
}
|
|
|
|
func userResponsesToUsers(urs *[]domain.UserResponse) *[]domain.User {
|
|
if urs == nil {
|
|
return nil
|
|
}
|
|
us := make([]domain.User, len(*urs))
|
|
for i, ur := range *urs {
|
|
us[i] = *userResponseToUser(&ur)
|
|
}
|
|
return &us
|
|
}
|