2016-10-07 10:39:28 -04:00
//
2019-02-01 14:26:40 -05:00
// Copyright 2018, Sander van Harmelen
2016-10-07 10:39:28 -04:00
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package cloudstack
import (
"encoding/json"
"fmt"
"net/url"
"strconv"
"strings"
)
type CreateUserParams struct {
p map [ string ] interface { }
}
func ( p * CreateUserParams ) toURLValues ( ) url . Values {
u := url . Values { }
if p . p == nil {
return u
}
if v , found := p . p [ "account" ] ; found {
u . Set ( "account" , v . ( string ) )
}
if v , found := p . p [ "domainid" ] ; found {
u . Set ( "domainid" , v . ( string ) )
}
if v , found := p . p [ "email" ] ; found {
u . Set ( "email" , v . ( string ) )
}
if v , found := p . p [ "firstname" ] ; found {
u . Set ( "firstname" , v . ( string ) )
}
if v , found := p . p [ "lastname" ] ; found {
u . Set ( "lastname" , v . ( string ) )
}
if v , found := p . p [ "password" ] ; found {
u . Set ( "password" , v . ( string ) )
}
if v , found := p . p [ "timezone" ] ; found {
u . Set ( "timezone" , v . ( string ) )
}
if v , found := p . p [ "userid" ] ; found {
u . Set ( "userid" , v . ( string ) )
}
if v , found := p . p [ "username" ] ; found {
u . Set ( "username" , v . ( string ) )
}
return u
}
func ( p * CreateUserParams ) SetAccount ( v string ) {
if p . p == nil {
p . p = make ( map [ string ] interface { } )
}
p . p [ "account" ] = v
return
}
func ( p * CreateUserParams ) SetDomainid ( v string ) {
if p . p == nil {
p . p = make ( map [ string ] interface { } )
}
p . p [ "domainid" ] = v
return
}
func ( p * CreateUserParams ) SetEmail ( v string ) {
if p . p == nil {
p . p = make ( map [ string ] interface { } )
}
p . p [ "email" ] = v
return
}
func ( p * CreateUserParams ) SetFirstname ( v string ) {
if p . p == nil {
p . p = make ( map [ string ] interface { } )
}
p . p [ "firstname" ] = v
return
}
func ( p * CreateUserParams ) SetLastname ( v string ) {
if p . p == nil {
p . p = make ( map [ string ] interface { } )
}
p . p [ "lastname" ] = v
return
}
func ( p * CreateUserParams ) SetPassword ( v string ) {
if p . p == nil {
p . p = make ( map [ string ] interface { } )
}
p . p [ "password" ] = v
return
}
func ( p * CreateUserParams ) SetTimezone ( v string ) {
if p . p == nil {
p . p = make ( map [ string ] interface { } )
}
p . p [ "timezone" ] = v
return
}
func ( p * CreateUserParams ) SetUserid ( v string ) {
if p . p == nil {
p . p = make ( map [ string ] interface { } )
}
p . p [ "userid" ] = v
return
}
func ( p * CreateUserParams ) SetUsername ( v string ) {
if p . p == nil {
p . p = make ( map [ string ] interface { } )
}
p . p [ "username" ] = v
return
}
// You should always use this function to get a new CreateUserParams instance,
// as then you are sure you have configured all required params
func ( s * UserService ) NewCreateUserParams ( account string , email string , firstname string , lastname string , password string , username string ) * CreateUserParams {
p := & CreateUserParams { }
p . p = make ( map [ string ] interface { } )
p . p [ "account" ] = account
p . p [ "email" ] = email
p . p [ "firstname" ] = firstname
p . p [ "lastname" ] = lastname
p . p [ "password" ] = password
p . p [ "username" ] = username
return p
}
// Creates a user for an account that already exists
func ( s * UserService ) CreateUser ( p * CreateUserParams ) ( * CreateUserResponse , error ) {
resp , err := s . cs . newRequest ( "createUser" , p . toURLValues ( ) )
if err != nil {
return nil , err
}
2019-02-01 14:26:40 -05:00
if resp , err = getRawValue ( resp ) ; err != nil {
return nil , err
}
2016-10-07 10:39:28 -04:00
var r CreateUserResponse
if err := json . Unmarshal ( resp , & r ) ; err != nil {
return nil , err
}
2019-02-01 14:26:40 -05:00
2016-10-07 10:39:28 -04:00
return & r , nil
}
type CreateUserResponse struct {
2019-02-01 14:26:40 -05:00
Account string ` json:"account" `
Accountid string ` json:"accountid" `
Accounttype int ` json:"accounttype" `
Apikey string ` json:"apikey" `
Created string ` json:"created" `
Domain string ` json:"domain" `
Domainid string ` json:"domainid" `
Email string ` json:"email" `
Firstname string ` json:"firstname" `
Id string ` json:"id" `
Iscallerchilddomain bool ` json:"iscallerchilddomain" `
Isdefault bool ` json:"isdefault" `
2019-05-26 05:58:26 -04:00
JobID string ` json:"jobid" `
Jobstatus int ` json:"jobstatus" `
2019-02-01 14:26:40 -05:00
Lastname string ` json:"lastname" `
Roleid string ` json:"roleid" `
Rolename string ` json:"rolename" `
Roletype string ` json:"roletype" `
Secretkey string ` json:"secretkey" `
State string ` json:"state" `
Timezone string ` json:"timezone" `
Username string ` json:"username" `
Usersource string ` json:"usersource" `
2016-10-07 10:39:28 -04:00
}
type DeleteUserParams struct {
p map [ string ] interface { }
}
func ( p * DeleteUserParams ) toURLValues ( ) url . Values {
u := url . Values { }
if p . p == nil {
return u
}
if v , found := p . p [ "id" ] ; found {
u . Set ( "id" , v . ( string ) )
}
return u
}
func ( p * DeleteUserParams ) SetId ( v string ) {
if p . p == nil {
p . p = make ( map [ string ] interface { } )
}
p . p [ "id" ] = v
return
}
// You should always use this function to get a new DeleteUserParams instance,
// as then you are sure you have configured all required params
func ( s * UserService ) NewDeleteUserParams ( id string ) * DeleteUserParams {
p := & DeleteUserParams { }
p . p = make ( map [ string ] interface { } )
p . p [ "id" ] = id
return p
}
// Deletes a user for an account
func ( s * UserService ) DeleteUser ( p * DeleteUserParams ) ( * DeleteUserResponse , error ) {
resp , err := s . cs . newRequest ( "deleteUser" , p . toURLValues ( ) )
if err != nil {
return nil , err
}
var r DeleteUserResponse
if err := json . Unmarshal ( resp , & r ) ; err != nil {
return nil , err
}
2019-02-01 14:26:40 -05:00
2016-10-07 10:39:28 -04:00
return & r , nil
}
type DeleteUserResponse struct {
2019-02-01 14:26:40 -05:00
Displaytext string ` json:"displaytext" `
2019-05-26 05:58:26 -04:00
JobID string ` json:"jobid" `
Jobstatus int ` json:"jobstatus" `
2019-02-01 14:26:40 -05:00
Success bool ` json:"success" `
2016-10-07 10:39:28 -04:00
}
2019-02-01 14:26:40 -05:00
func ( r * DeleteUserResponse ) UnmarshalJSON ( b [ ] byte ) error {
var m map [ string ] interface { }
err := json . Unmarshal ( b , & m )
if err != nil {
return err
}
if success , ok := m [ "success" ] . ( string ) ; ok {
m [ "success" ] = success == "true"
b , err = json . Marshal ( m )
if err != nil {
return err
}
}
2019-05-26 05:58:26 -04:00
if ostypeid , ok := m [ "ostypeid" ] . ( float64 ) ; ok {
m [ "ostypeid" ] = strconv . Itoa ( int ( ostypeid ) )
b , err = json . Marshal ( m )
if err != nil {
return err
}
}
2019-02-01 14:26:40 -05:00
type alias DeleteUserResponse
return json . Unmarshal ( b , ( * alias ) ( r ) )
}
type DisableUserParams struct {
2016-10-07 10:39:28 -04:00
p map [ string ] interface { }
}
2019-02-01 14:26:40 -05:00
func ( p * DisableUserParams ) toURLValues ( ) url . Values {
2016-10-07 10:39:28 -04:00
u := url . Values { }
if p . p == nil {
return u
}
if v , found := p . p [ "id" ] ; found {
u . Set ( "id" , v . ( string ) )
}
return u
}
2019-02-01 14:26:40 -05:00
func ( p * DisableUserParams ) SetId ( v string ) {
2016-10-07 10:39:28 -04:00
if p . p == nil {
p . p = make ( map [ string ] interface { } )
}
2019-02-01 14:26:40 -05:00
p . p [ "id" ] = v
2016-10-07 10:39:28 -04:00
return
}
2019-02-01 14:26:40 -05:00
// You should always use this function to get a new DisableUserParams instance,
// as then you are sure you have configured all required params
func ( s * UserService ) NewDisableUserParams ( id string ) * DisableUserParams {
p := & DisableUserParams { }
p . p = make ( map [ string ] interface { } )
p . p [ "id" ] = id
return p
}
// Disables a user account
func ( s * UserService ) DisableUser ( p * DisableUserParams ) ( * DisableUserResponse , error ) {
resp , err := s . cs . newRequest ( "disableUser" , p . toURLValues ( ) )
if err != nil {
return nil , err
2016-10-07 10:39:28 -04:00
}
2019-02-01 14:26:40 -05:00
var r DisableUserResponse
if err := json . Unmarshal ( resp , & r ) ; err != nil {
return nil , err
}
// If we have a async client, we need to wait for the async result
if s . cs . async {
b , err := s . cs . GetAsyncJobResult ( r . JobID , s . cs . timeout )
if err != nil {
if err == AsyncTimeoutErr {
return & r , err
}
return nil , err
}
b , err = getRawValue ( b )
if err != nil {
return nil , err
}
if err := json . Unmarshal ( b , & r ) ; err != nil {
return nil , err
}
}
return & r , nil
2016-10-07 10:39:28 -04:00
}
2019-02-01 14:26:40 -05:00
type DisableUserResponse struct {
Account string ` json:"account" `
Accountid string ` json:"accountid" `
Accounttype int ` json:"accounttype" `
Apikey string ` json:"apikey" `
Created string ` json:"created" `
Domain string ` json:"domain" `
Domainid string ` json:"domainid" `
Email string ` json:"email" `
Firstname string ` json:"firstname" `
Id string ` json:"id" `
Iscallerchilddomain bool ` json:"iscallerchilddomain" `
Isdefault bool ` json:"isdefault" `
2019-05-26 05:58:26 -04:00
JobID string ` json:"jobid" `
Jobstatus int ` json:"jobstatus" `
2019-02-01 14:26:40 -05:00
Lastname string ` json:"lastname" `
Roleid string ` json:"roleid" `
Rolename string ` json:"rolename" `
Roletype string ` json:"roletype" `
Secretkey string ` json:"secretkey" `
State string ` json:"state" `
Timezone string ` json:"timezone" `
Username string ` json:"username" `
Usersource string ` json:"usersource" `
}
type EnableUserParams struct {
p map [ string ] interface { }
}
func ( p * EnableUserParams ) toURLValues ( ) url . Values {
u := url . Values { }
2016-10-07 10:39:28 -04:00
if p . p == nil {
2019-02-01 14:26:40 -05:00
return u
2016-10-07 10:39:28 -04:00
}
2019-02-01 14:26:40 -05:00
if v , found := p . p [ "id" ] ; found {
u . Set ( "id" , v . ( string ) )
}
return u
2016-10-07 10:39:28 -04:00
}
2019-02-01 14:26:40 -05:00
func ( p * EnableUserParams ) SetId ( v string ) {
2016-10-07 10:39:28 -04:00
if p . p == nil {
p . p = make ( map [ string ] interface { } )
}
2019-02-01 14:26:40 -05:00
p . p [ "id" ] = v
2016-10-07 10:39:28 -04:00
return
}
2019-02-01 14:26:40 -05:00
// You should always use this function to get a new EnableUserParams instance,
// as then you are sure you have configured all required params
func ( s * UserService ) NewEnableUserParams ( id string ) * EnableUserParams {
p := & EnableUserParams { }
p . p = make ( map [ string ] interface { } )
p . p [ "id" ] = id
return p
}
// Enables a user account
func ( s * UserService ) EnableUser ( p * EnableUserParams ) ( * EnableUserResponse , error ) {
resp , err := s . cs . newRequest ( "enableUser" , p . toURLValues ( ) )
if err != nil {
return nil , err
2016-10-07 10:39:28 -04:00
}
2019-02-01 14:26:40 -05:00
var r EnableUserResponse
if err := json . Unmarshal ( resp , & r ) ; err != nil {
return nil , err
}
return & r , nil
2016-10-07 10:39:28 -04:00
}
2019-02-01 14:26:40 -05:00
type EnableUserResponse struct {
Account string ` json:"account" `
Accountid string ` json:"accountid" `
Accounttype int ` json:"accounttype" `
Apikey string ` json:"apikey" `
Created string ` json:"created" `
Domain string ` json:"domain" `
Domainid string ` json:"domainid" `
Email string ` json:"email" `
Firstname string ` json:"firstname" `
Id string ` json:"id" `
Iscallerchilddomain bool ` json:"iscallerchilddomain" `
Isdefault bool ` json:"isdefault" `
2019-05-26 05:58:26 -04:00
JobID string ` json:"jobid" `
Jobstatus int ` json:"jobstatus" `
2019-02-01 14:26:40 -05:00
Lastname string ` json:"lastname" `
Roleid string ` json:"roleid" `
Rolename string ` json:"rolename" `
Roletype string ` json:"roletype" `
Secretkey string ` json:"secretkey" `
State string ` json:"state" `
Timezone string ` json:"timezone" `
Username string ` json:"username" `
Usersource string ` json:"usersource" `
}
type GetUserParams struct {
p map [ string ] interface { }
}
func ( p * GetUserParams ) toURLValues ( ) url . Values {
u := url . Values { }
2016-10-07 10:39:28 -04:00
if p . p == nil {
2019-02-01 14:26:40 -05:00
return u
2016-10-07 10:39:28 -04:00
}
2019-02-01 14:26:40 -05:00
if v , found := p . p [ "userapikey" ] ; found {
u . Set ( "userapikey" , v . ( string ) )
}
return u
2016-10-07 10:39:28 -04:00
}
2019-02-01 14:26:40 -05:00
func ( p * GetUserParams ) SetUserapikey ( v string ) {
2016-10-07 10:39:28 -04:00
if p . p == nil {
p . p = make ( map [ string ] interface { } )
}
p . p [ "userapikey" ] = v
return
}
2019-02-01 14:26:40 -05:00
// You should always use this function to get a new GetUserParams instance,
// as then you are sure you have configured all required params
func ( s * UserService ) NewGetUserParams ( userapikey string ) * GetUserParams {
p := & GetUserParams { }
p . p = make ( map [ string ] interface { } )
p . p [ "userapikey" ] = userapikey
return p
}
// Find user account by API key
func ( s * UserService ) GetUser ( p * GetUserParams ) ( * GetUserResponse , error ) {
resp , err := s . cs . newRequest ( "getUser" , p . toURLValues ( ) )
if err != nil {
return nil , err
}
var r GetUserResponse
if err := json . Unmarshal ( resp , & r ) ; err != nil {
return nil , err
}
return & r , nil
}
type GetUserResponse struct {
Account string ` json:"account" `
Accountid string ` json:"accountid" `
Accounttype int ` json:"accounttype" `
Apikey string ` json:"apikey" `
Created string ` json:"created" `
Domain string ` json:"domain" `
Domainid string ` json:"domainid" `
Email string ` json:"email" `
Firstname string ` json:"firstname" `
Id string ` json:"id" `
Iscallerchilddomain bool ` json:"iscallerchilddomain" `
Isdefault bool ` json:"isdefault" `
2019-05-26 05:58:26 -04:00
JobID string ` json:"jobid" `
Jobstatus int ` json:"jobstatus" `
2019-02-01 14:26:40 -05:00
Lastname string ` json:"lastname" `
Roleid string ` json:"roleid" `
Rolename string ` json:"rolename" `
Roletype string ` json:"roletype" `
Secretkey string ` json:"secretkey" `
State string ` json:"state" `
Timezone string ` json:"timezone" `
Username string ` json:"username" `
Usersource string ` json:"usersource" `
}
type GetVirtualMachineUserDataParams struct {
p map [ string ] interface { }
}
func ( p * GetVirtualMachineUserDataParams ) toURLValues ( ) url . Values {
u := url . Values { }
2016-10-07 10:39:28 -04:00
if p . p == nil {
2019-02-01 14:26:40 -05:00
return u
2016-10-07 10:39:28 -04:00
}
2019-02-01 14:26:40 -05:00
if v , found := p . p [ "virtualmachineid" ] ; found {
u . Set ( "virtualmachineid" , v . ( string ) )
}
return u
2016-10-07 10:39:28 -04:00
}
2019-02-01 14:26:40 -05:00
func ( p * GetVirtualMachineUserDataParams ) SetVirtualmachineid ( v string ) {
2016-10-07 10:39:28 -04:00
if p . p == nil {
p . p = make ( map [ string ] interface { } )
}
2019-02-01 14:26:40 -05:00
p . p [ "virtualmachineid" ] = v
2016-10-07 10:39:28 -04:00
return
}
2019-02-01 14:26:40 -05:00
// You should always use this function to get a new GetVirtualMachineUserDataParams instance,
2016-10-07 10:39:28 -04:00
// as then you are sure you have configured all required params
2019-02-01 14:26:40 -05:00
func ( s * UserService ) NewGetVirtualMachineUserDataParams ( virtualmachineid string ) * GetVirtualMachineUserDataParams {
p := & GetVirtualMachineUserDataParams { }
2016-10-07 10:39:28 -04:00
p . p = make ( map [ string ] interface { } )
2019-02-01 14:26:40 -05:00
p . p [ "virtualmachineid" ] = virtualmachineid
2016-10-07 10:39:28 -04:00
return p
}
2019-02-01 14:26:40 -05:00
// Returns user data associated with the VM
func ( s * UserService ) GetVirtualMachineUserData ( p * GetVirtualMachineUserDataParams ) ( * GetVirtualMachineUserDataResponse , error ) {
resp , err := s . cs . newRequest ( "getVirtualMachineUserData" , p . toURLValues ( ) )
2016-10-07 10:39:28 -04:00
if err != nil {
return nil , err
}
2019-02-01 14:26:40 -05:00
var r GetVirtualMachineUserDataResponse
2016-10-07 10:39:28 -04:00
if err := json . Unmarshal ( resp , & r ) ; err != nil {
return nil , err
}
2019-02-01 14:26:40 -05:00
2016-10-07 10:39:28 -04:00
return & r , nil
}
2019-02-01 14:26:40 -05:00
type GetVirtualMachineUserDataResponse struct {
2019-05-26 05:58:26 -04:00
JobID string ` json:"jobid" `
Jobstatus int ` json:"jobstatus" `
2019-02-01 14:26:40 -05:00
Userdata string ` json:"userdata" `
Virtualmachineid string ` json:"virtualmachineid" `
2016-10-07 10:39:28 -04:00
}
type ListUsersParams struct {
p map [ string ] interface { }
}
func ( p * ListUsersParams ) toURLValues ( ) url . Values {
u := url . Values { }
if p . p == nil {
return u
}
if v , found := p . p [ "account" ] ; found {
u . Set ( "account" , v . ( string ) )
}
if v , found := p . p [ "accounttype" ] ; found {
vv := strconv . FormatInt ( v . ( int64 ) , 10 )
u . Set ( "accounttype" , vv )
}
if v , found := p . p [ "domainid" ] ; found {
u . Set ( "domainid" , v . ( string ) )
}
if v , found := p . p [ "id" ] ; found {
u . Set ( "id" , v . ( string ) )
}
if v , found := p . p [ "isrecursive" ] ; found {
vv := strconv . FormatBool ( v . ( bool ) )
u . Set ( "isrecursive" , vv )
}
if v , found := p . p [ "keyword" ] ; found {
u . Set ( "keyword" , v . ( string ) )
}
if v , found := p . p [ "listall" ] ; found {
vv := strconv . FormatBool ( v . ( bool ) )
u . Set ( "listall" , vv )
}
if v , found := p . p [ "page" ] ; found {
vv := strconv . Itoa ( v . ( int ) )
u . Set ( "page" , vv )
}
if v , found := p . p [ "pagesize" ] ; found {
vv := strconv . Itoa ( v . ( int ) )
u . Set ( "pagesize" , vv )
}
if v , found := p . p [ "state" ] ; found {
u . Set ( "state" , v . ( string ) )
}
if v , found := p . p [ "username" ] ; found {
u . Set ( "username" , v . ( string ) )
}
return u
}
func ( p * ListUsersParams ) SetAccount ( v string ) {
if p . p == nil {
p . p = make ( map [ string ] interface { } )
}
p . p [ "account" ] = v
return
}
func ( p * ListUsersParams ) SetAccounttype ( v int64 ) {
if p . p == nil {
p . p = make ( map [ string ] interface { } )
}
p . p [ "accounttype" ] = v
return
}
func ( p * ListUsersParams ) SetDomainid ( v string ) {
if p . p == nil {
p . p = make ( map [ string ] interface { } )
}
p . p [ "domainid" ] = v
return
}
func ( p * ListUsersParams ) SetId ( v string ) {
if p . p == nil {
p . p = make ( map [ string ] interface { } )
}
p . p [ "id" ] = v
return
}
func ( p * ListUsersParams ) SetIsrecursive ( v bool ) {
if p . p == nil {
p . p = make ( map [ string ] interface { } )
}
p . p [ "isrecursive" ] = v
return
}
func ( p * ListUsersParams ) SetKeyword ( v string ) {
if p . p == nil {
p . p = make ( map [ string ] interface { } )
}
p . p [ "keyword" ] = v
return
}
func ( p * ListUsersParams ) SetListall ( v bool ) {
if p . p == nil {
p . p = make ( map [ string ] interface { } )
}
p . p [ "listall" ] = v
return
}
func ( p * ListUsersParams ) SetPage ( v int ) {
if p . p == nil {
p . p = make ( map [ string ] interface { } )
}
p . p [ "page" ] = v
return
}
func ( p * ListUsersParams ) SetPagesize ( v int ) {
if p . p == nil {
p . p = make ( map [ string ] interface { } )
}
p . p [ "pagesize" ] = v
return
}
func ( p * ListUsersParams ) SetState ( v string ) {
if p . p == nil {
p . p = make ( map [ string ] interface { } )
}
p . p [ "state" ] = v
return
}
func ( p * ListUsersParams ) SetUsername ( v string ) {
if p . p == nil {
p . p = make ( map [ string ] interface { } )
}
p . p [ "username" ] = v
return
}
// You should always use this function to get a new ListUsersParams instance,
// as then you are sure you have configured all required params
func ( s * UserService ) NewListUsersParams ( ) * ListUsersParams {
p := & ListUsersParams { }
p . p = make ( map [ string ] interface { } )
return p
}
// This is a courtesy helper function, which in some cases may not work as expected!
func ( s * UserService ) GetUserByID ( id string , opts ... OptionFunc ) ( * User , int , error ) {
p := & ListUsersParams { }
p . p = make ( map [ string ] interface { } )
p . p [ "id" ] = id
2019-02-01 14:26:40 -05:00
for _ , fn := range append ( s . cs . options , opts ... ) {
2016-10-07 10:39:28 -04:00
if err := fn ( s . cs , p ) ; err != nil {
return nil , - 1 , err
}
}
l , err := s . ListUsers ( p )
if err != nil {
if strings . Contains ( err . Error ( ) , fmt . Sprintf (
"Invalid parameter id value=%s due to incorrect long value format, " +
"or entity does not exist" , id ) ) {
return nil , 0 , fmt . Errorf ( "No match found for %s: %+v" , id , l )
}
return nil , - 1 , err
}
if l . Count == 0 {
return nil , l . Count , fmt . Errorf ( "No match found for %s: %+v" , id , l )
}
if l . Count == 1 {
return l . Users [ 0 ] , l . Count , nil
}
return nil , l . Count , fmt . Errorf ( "There is more then one result for User UUID: %s!" , id )
}
// Lists user accounts
func ( s * UserService ) ListUsers ( p * ListUsersParams ) ( * ListUsersResponse , error ) {
resp , err := s . cs . newRequest ( "listUsers" , p . toURLValues ( ) )
if err != nil {
return nil , err
}
var r ListUsersResponse
if err := json . Unmarshal ( resp , & r ) ; err != nil {
return nil , err
}
2019-02-01 14:26:40 -05:00
2016-10-07 10:39:28 -04:00
return & r , nil
}
type ListUsersResponse struct {
Count int ` json:"count" `
Users [ ] * User ` json:"user" `
}
type User struct {
2019-02-01 14:26:40 -05:00
Account string ` json:"account" `
Accountid string ` json:"accountid" `
Accounttype int ` json:"accounttype" `
Apikey string ` json:"apikey" `
Created string ` json:"created" `
Domain string ` json:"domain" `
Domainid string ` json:"domainid" `
Email string ` json:"email" `
Firstname string ` json:"firstname" `
Id string ` json:"id" `
Iscallerchilddomain bool ` json:"iscallerchilddomain" `
Isdefault bool ` json:"isdefault" `
2019-05-26 05:58:26 -04:00
JobID string ` json:"jobid" `
Jobstatus int ` json:"jobstatus" `
2019-02-01 14:26:40 -05:00
Lastname string ` json:"lastname" `
Roleid string ` json:"roleid" `
Rolename string ` json:"rolename" `
Roletype string ` json:"roletype" `
Secretkey string ` json:"secretkey" `
State string ` json:"state" `
Timezone string ` json:"timezone" `
Username string ` json:"username" `
Usersource string ` json:"usersource" `
2016-10-07 10:39:28 -04:00
}
type LockUserParams struct {
p map [ string ] interface { }
}
func ( p * LockUserParams ) toURLValues ( ) url . Values {
u := url . Values { }
if p . p == nil {
return u
}
if v , found := p . p [ "id" ] ; found {
u . Set ( "id" , v . ( string ) )
}
return u
}
func ( p * LockUserParams ) SetId ( v string ) {
if p . p == nil {
p . p = make ( map [ string ] interface { } )
}
p . p [ "id" ] = v
return
}
// You should always use this function to get a new LockUserParams instance,
// as then you are sure you have configured all required params
func ( s * UserService ) NewLockUserParams ( id string ) * LockUserParams {
p := & LockUserParams { }
p . p = make ( map [ string ] interface { } )
p . p [ "id" ] = id
return p
}
// Locks a user account
func ( s * UserService ) LockUser ( p * LockUserParams ) ( * LockUserResponse , error ) {
resp , err := s . cs . newRequest ( "lockUser" , p . toURLValues ( ) )
if err != nil {
return nil , err
}
var r LockUserResponse
if err := json . Unmarshal ( resp , & r ) ; err != nil {
return nil , err
}
2019-02-01 14:26:40 -05:00
2016-10-07 10:39:28 -04:00
return & r , nil
}
type LockUserResponse struct {
2019-02-01 14:26:40 -05:00
Account string ` json:"account" `
Accountid string ` json:"accountid" `
Accounttype int ` json:"accounttype" `
Apikey string ` json:"apikey" `
Created string ` json:"created" `
Domain string ` json:"domain" `
Domainid string ` json:"domainid" `
Email string ` json:"email" `
Firstname string ` json:"firstname" `
Id string ` json:"id" `
Iscallerchilddomain bool ` json:"iscallerchilddomain" `
Isdefault bool ` json:"isdefault" `
2019-05-26 05:58:26 -04:00
JobID string ` json:"jobid" `
Jobstatus int ` json:"jobstatus" `
2019-02-01 14:26:40 -05:00
Lastname string ` json:"lastname" `
Roleid string ` json:"roleid" `
Rolename string ` json:"rolename" `
Roletype string ` json:"roletype" `
Secretkey string ` json:"secretkey" `
State string ` json:"state" `
Timezone string ` json:"timezone" `
Username string ` json:"username" `
Usersource string ` json:"usersource" `
2016-10-07 10:39:28 -04:00
}
2019-02-01 14:26:40 -05:00
type RegisterUserKeysParams struct {
2016-10-07 10:39:28 -04:00
p map [ string ] interface { }
}
2019-02-01 14:26:40 -05:00
func ( p * RegisterUserKeysParams ) toURLValues ( ) url . Values {
2016-10-07 10:39:28 -04:00
u := url . Values { }
if p . p == nil {
return u
}
if v , found := p . p [ "id" ] ; found {
u . Set ( "id" , v . ( string ) )
}
return u
}
2019-02-01 14:26:40 -05:00
func ( p * RegisterUserKeysParams ) SetId ( v string ) {
2016-10-07 10:39:28 -04:00
if p . p == nil {
p . p = make ( map [ string ] interface { } )
}
p . p [ "id" ] = v
return
}
2019-02-01 14:26:40 -05:00
// You should always use this function to get a new RegisterUserKeysParams instance,
2016-10-07 10:39:28 -04:00
// as then you are sure you have configured all required params
2019-02-01 14:26:40 -05:00
func ( s * UserService ) NewRegisterUserKeysParams ( id string ) * RegisterUserKeysParams {
p := & RegisterUserKeysParams { }
2016-10-07 10:39:28 -04:00
p . p = make ( map [ string ] interface { } )
p . p [ "id" ] = id
return p
}
2019-02-01 14:26:40 -05:00
// This command allows a user to register for the developer API, returning a secret key and an API key. This request is made through the integration API port, so it is a privileged command and must be made on behalf of a user. It is up to the implementer just how the username and password are entered, and then how that translates to an integration API request. Both secret key and API key should be returned to the user
func ( s * UserService ) RegisterUserKeys ( p * RegisterUserKeysParams ) ( * RegisterUserKeysResponse , error ) {
resp , err := s . cs . newRequest ( "registerUserKeys" , p . toURLValues ( ) )
2016-10-07 10:39:28 -04:00
if err != nil {
return nil , err
}
2019-02-01 14:26:40 -05:00
if resp , err = getRawValue ( resp ) ; err != nil {
return nil , err
}
var r RegisterUserKeysResponse
2016-10-07 10:39:28 -04:00
if err := json . Unmarshal ( resp , & r ) ; err != nil {
return nil , err
}
return & r , nil
}
2019-02-01 14:26:40 -05:00
type RegisterUserKeysResponse struct {
Apikey string ` json:"apikey" `
2019-05-26 05:58:26 -04:00
JobID string ` json:"jobid" `
Jobstatus int ` json:"jobstatus" `
2019-02-01 14:26:40 -05:00
Secretkey string ` json:"secretkey" `
2016-10-07 10:39:28 -04:00
}
2019-02-01 14:26:40 -05:00
type UpdateUserParams struct {
2016-10-07 10:39:28 -04:00
p map [ string ] interface { }
}
2019-02-01 14:26:40 -05:00
func ( p * UpdateUserParams ) toURLValues ( ) url . Values {
2016-10-07 10:39:28 -04:00
u := url . Values { }
if p . p == nil {
return u
}
2019-05-26 05:58:26 -04:00
if v , found := p . p [ "currentpassword" ] ; found {
u . Set ( "currentpassword" , v . ( string ) )
}
2019-02-01 14:26:40 -05:00
if v , found := p . p [ "email" ] ; found {
u . Set ( "email" , v . ( string ) )
2016-10-07 10:39:28 -04:00
}
2019-02-01 14:26:40 -05:00
if v , found := p . p [ "firstname" ] ; found {
u . Set ( "firstname" , v . ( string ) )
2016-10-07 10:39:28 -04:00
}
if v , found := p . p [ "id" ] ; found {
u . Set ( "id" , v . ( string ) )
}
2019-02-01 14:26:40 -05:00
if v , found := p . p [ "lastname" ] ; found {
u . Set ( "lastname" , v . ( string ) )
2016-10-07 10:39:28 -04:00
}
2019-02-01 14:26:40 -05:00
if v , found := p . p [ "password" ] ; found {
u . Set ( "password" , v . ( string ) )
2016-10-07 10:39:28 -04:00
}
2019-02-01 14:26:40 -05:00
if v , found := p . p [ "timezone" ] ; found {
u . Set ( "timezone" , v . ( string ) )
2016-10-07 10:39:28 -04:00
}
2019-02-01 14:26:40 -05:00
if v , found := p . p [ "userapikey" ] ; found {
u . Set ( "userapikey" , v . ( string ) )
2016-10-07 10:39:28 -04:00
}
2019-02-01 14:26:40 -05:00
if v , found := p . p [ "username" ] ; found {
u . Set ( "username" , v . ( string ) )
2016-10-07 10:39:28 -04:00
}
2019-02-01 14:26:40 -05:00
if v , found := p . p [ "usersecretkey" ] ; found {
u . Set ( "usersecretkey" , v . ( string ) )
2016-10-07 10:39:28 -04:00
}
return u
}
2019-05-26 05:58:26 -04:00
func ( p * UpdateUserParams ) SetCurrentpassword ( v string ) {
if p . p == nil {
p . p = make ( map [ string ] interface { } )
}
p . p [ "currentpassword" ] = v
return
}
2019-02-01 14:26:40 -05:00
func ( p * UpdateUserParams ) SetEmail ( v string ) {
2016-10-07 10:39:28 -04:00
if p . p == nil {
p . p = make ( map [ string ] interface { } )
}
2019-02-01 14:26:40 -05:00
p . p [ "email" ] = v
2016-10-07 10:39:28 -04:00
return
}
2019-02-01 14:26:40 -05:00
func ( p * UpdateUserParams ) SetFirstname ( v string ) {
2016-10-07 10:39:28 -04:00
if p . p == nil {
p . p = make ( map [ string ] interface { } )
}
2019-02-01 14:26:40 -05:00
p . p [ "firstname" ] = v
2016-10-07 10:39:28 -04:00
return
}
2019-02-01 14:26:40 -05:00
func ( p * UpdateUserParams ) SetId ( v string ) {
2016-10-07 10:39:28 -04:00
if p . p == nil {
p . p = make ( map [ string ] interface { } )
}
2019-02-01 14:26:40 -05:00
p . p [ "id" ] = v
2016-10-07 10:39:28 -04:00
return
}
2019-02-01 14:26:40 -05:00
func ( p * UpdateUserParams ) SetLastname ( v string ) {
2016-10-07 10:39:28 -04:00
if p . p == nil {
p . p = make ( map [ string ] interface { } )
}
2019-02-01 14:26:40 -05:00
p . p [ "lastname" ] = v
2016-10-07 10:39:28 -04:00
return
}
2019-02-01 14:26:40 -05:00
func ( p * UpdateUserParams ) SetPassword ( v string ) {
2016-10-07 10:39:28 -04:00
if p . p == nil {
p . p = make ( map [ string ] interface { } )
}
2019-02-01 14:26:40 -05:00
p . p [ "password" ] = v
2016-10-07 10:39:28 -04:00
return
}
2019-02-01 14:26:40 -05:00
func ( p * UpdateUserParams ) SetTimezone ( v string ) {
2016-10-07 10:39:28 -04:00
if p . p == nil {
p . p = make ( map [ string ] interface { } )
}
2019-02-01 14:26:40 -05:00
p . p [ "timezone" ] = v
2016-10-07 10:39:28 -04:00
return
}
2019-02-01 14:26:40 -05:00
func ( p * UpdateUserParams ) SetUserapikey ( v string ) {
2016-10-07 10:39:28 -04:00
if p . p == nil {
p . p = make ( map [ string ] interface { } )
}
2019-02-01 14:26:40 -05:00
p . p [ "userapikey" ] = v
2016-10-07 10:39:28 -04:00
return
}
2019-02-01 14:26:40 -05:00
func ( p * UpdateUserParams ) SetUsername ( v string ) {
2016-10-07 10:39:28 -04:00
if p . p == nil {
p . p = make ( map [ string ] interface { } )
}
2019-02-01 14:26:40 -05:00
p . p [ "username" ] = v
2016-10-07 10:39:28 -04:00
return
}
2019-02-01 14:26:40 -05:00
func ( p * UpdateUserParams ) SetUsersecretkey ( v string ) {
2016-10-07 10:39:28 -04:00
if p . p == nil {
p . p = make ( map [ string ] interface { } )
}
2019-02-01 14:26:40 -05:00
p . p [ "usersecretkey" ] = v
2016-10-07 10:39:28 -04:00
return
}
2019-02-01 14:26:40 -05:00
// You should always use this function to get a new UpdateUserParams instance,
2016-10-07 10:39:28 -04:00
// as then you are sure you have configured all required params
2019-02-01 14:26:40 -05:00
func ( s * UserService ) NewUpdateUserParams ( id string ) * UpdateUserParams {
p := & UpdateUserParams { }
2016-10-07 10:39:28 -04:00
p . p = make ( map [ string ] interface { } )
2019-02-01 14:26:40 -05:00
p . p [ "id" ] = id
2016-10-07 10:39:28 -04:00
return p
}
2019-02-01 14:26:40 -05:00
// Updates a user account
func ( s * UserService ) UpdateUser ( p * UpdateUserParams ) ( * UpdateUserResponse , error ) {
resp , err := s . cs . newRequest ( "updateUser" , p . toURLValues ( ) )
2016-10-07 10:39:28 -04:00
if err != nil {
return nil , err
}
2019-02-01 14:26:40 -05:00
var r UpdateUserResponse
2016-10-07 10:39:28 -04:00
if err := json . Unmarshal ( resp , & r ) ; err != nil {
return nil , err
}
2019-02-01 14:26:40 -05:00
2016-10-07 10:39:28 -04:00
return & r , nil
}
2019-02-01 14:26:40 -05:00
type UpdateUserResponse struct {
Account string ` json:"account" `
Accountid string ` json:"accountid" `
Accounttype int ` json:"accounttype" `
Apikey string ` json:"apikey" `
Created string ` json:"created" `
Domain string ` json:"domain" `
Domainid string ` json:"domainid" `
Email string ` json:"email" `
Firstname string ` json:"firstname" `
Id string ` json:"id" `
Iscallerchilddomain bool ` json:"iscallerchilddomain" `
Isdefault bool ` json:"isdefault" `
2019-05-26 05:58:26 -04:00
JobID string ` json:"jobid" `
Jobstatus int ` json:"jobstatus" `
2019-02-01 14:26:40 -05:00
Lastname string ` json:"lastname" `
Roleid string ` json:"roleid" `
Rolename string ` json:"rolename" `
Roletype string ` json:"roletype" `
Secretkey string ` json:"secretkey" `
State string ` json:"state" `
Timezone string ` json:"timezone" `
Username string ` json:"username" `
Usersource string ` json:"usersource" `
2016-10-07 10:39:28 -04:00
}