BinaryNinja::Collaboration::Remote Class Reference

Public Member Functions

 Remote (BNRemote *remote)
 
std::string GetUniqueId ()
 
std::string GetName ()
 
std::string GetAddress ()
 
bool HasLoadedMetadata ()
 
bool IsConnected ()
 
std::string GetUsername ()
 
std::string GetToken ()
 
int GetServerVersion ()
 
std::string GetServerBuildId ()
 
std::vector< std::pair< std::string, std::string > > GetAuthBackends ()
 
bool HasPulledProjects ()
 
bool HasPulledUsers ()
 
bool HasPulledGroups ()
 
bool IsAdmin ()
 
bool IsEnterprise ()
 Determine if a remote is the same as the currently connected Enterprise Server On non-Enterprise clients, this always returns false. More...
 
bool LoadMetadata ()
 Load remote metadata, including version, id, and auth backends. More...
 
std::string RequestAuthenticationToken (const std::string &username, const std::string &password)
 Request an authentication token for a user given a username and password. More...
 
void Connect (const std::string &username, const std::string &token)
 Establish a connection to the remote, using a username and token. More...
 
void Disconnect ()
 Disconnect from the remote. More...
 
std::vector< Ref< RemoteProject > > GetProjects ()
 Get all projects in the Remote. More...
 
Ref< RemoteProjectGetProjectById (const std::string &id)
 Get a project in the remote by its id. More...
 
Ref< RemoteProjectGetProjectByName (const std::string &name)
 Get a project in the remote by its name. More...
 
void PullProjects (std::function< bool(size_t, size_t)> progress={})
 Pull list of projects from the remote. More...
 
Ref< RemoteProjectCreateProject (const std::string &name, const std::string &description)
 Create a new project on the remote (and pull it) More...
 
Ref< RemoteProjectImportLocalProject (Ref< Project > localProject, std::function< bool(size_t, size_t)> progress={})
 Create a new project on the remote from a local project. More...
 
void PushProject (Ref< RemoteProject > project, const std::vector< std::pair< std::string, std::string > > &extraFields={})
 Push fields of a modified project to the remote. More...
 
void DeleteProject (const Ref< RemoteProject > project)
 Delete a project from the remote. More...
 
std::vector< Ref< CollabGroup > > GetGroups ()
 Get all groups in the Project. More...
 
Ref< CollabGroupGetGroupById (uint64_t id)
 Get a group in the project by its id. More...
 
Ref< CollabGroupGetGroupByName (const std::string &name)
 Get a group in the project by its name. More...
 
std::vector< std::pair< uint64_t, std::string > > SearchGroups (const std::string &prefix)
 Search groups on the remote. More...
 
void PullGroups (std::function< bool(size_t, size_t)> progress={})
 Pull list of groups from the remote. More...
 
Ref< CollabGroupCreateGroup (const std::string &name, const std::vector< std::string > &usernames)
 Create a new group on the remote (and pull it) More...
 
void PushGroup (Ref< CollabGroup > group, const std::vector< std::pair< std::string, std::string > > &extraFields={})
 Push fields of a modified group to the remote. More...
 
void DeleteGroup (const Ref< CollabGroup > group)
 Delete a group from the remote. More...
 
std::vector< Ref< CollabUser > > GetUsers ()
 Get all users in the Remote. More...
 
Ref< CollabUserGetUserById (const std::string &id)
 Get a user in the remote by their id. More...
 
Ref< CollabUserGetUserByUsername (const std::string &username)
 Get a user in the remote by their username. More...
 
Ref< CollabUserGetCurrentUser ()
 Get the currently logged-in user's CollabUser object. More...
 
std::vector< std::pair< std::string, std::string > > SearchUsers (const std::string &prefix)
 Search users on the remote. More...
 
void PullUsers (std::function< bool(size_t, size_t)> progress={})
 Pull list of users from the remote. More...
 
Ref< CollabUserCreateUser (const std::string &username, const std::string &email, bool is_active, const std::string &password, const std::vector< uint64_t > &groupIds, const std::vector< uint64_t > &userPermissionIds)
 Create a new user on the remote (and pull it) More...
 
void PushUser (Ref< CollabUser > user, const std::vector< std::pair< std::string, std::string > > &extraFields={})
 Push fields of a modified user to the remote. More...
 
int Request (Http::Request request, Http::Response &ret)
 Perform an arbitrary HTTP request. More...
 
- Public Member Functions inherited from BinaryNinja::CoreRefCountObject< BNRemote, BNNewRemoteReference, BNFreeRemote >
 CoreRefCountObject ()
 
virtual ~CoreRefCountObject ()
 
BNRemoteGetObject () const
 
void AddRef ()
 
void Release ()
 
void AddRefForRegistration ()
 
void ReleaseForRegistration ()
 
void AddRefForCallback ()
 
void ReleaseForCallback ()
 

Additional Inherited Members

- Static Public Member Functions inherited from BinaryNinja::CoreRefCountObject< BNRemote, BNNewRemoteReference, BNFreeRemote >
static BNRemoteGetObject (CoreRefCountObject *obj)
 
static BNRemoteGetObject (const CoreRefCountObject *obj)
 
- Public Attributes inherited from BinaryNinja::CoreRefCountObject< BNRemote, BNNewRemoteReference, BNFreeRemote >
std::atomic< int > m_refs
 
bool m_registeredRef
 
BNRemotem_object
 

Constructor & Destructor Documentation

◆ Remote()

Remote::Remote ( BNRemote remote)

Member Function Documentation

◆ GetUniqueId()

std::string Remote::GetUniqueId ( )

◆ GetName()

std::string Remote::GetName ( )

◆ GetAddress()

std::string Remote::GetAddress ( )

◆ HasLoadedMetadata()

bool Remote::HasLoadedMetadata ( )

◆ IsConnected()

bool Remote::IsConnected ( )

◆ GetUsername()

std::string Remote::GetUsername ( )

◆ GetToken()

std::string Remote::GetToken ( )

◆ GetServerVersion()

int Remote::GetServerVersion ( )

◆ GetServerBuildId()

std::string Remote::GetServerBuildId ( )

◆ GetAuthBackends()

std::vector< std::pair< std::string, std::string > > Remote::GetAuthBackends ( )

◆ HasPulledProjects()

bool Remote::HasPulledProjects ( )

◆ HasPulledUsers()

bool Remote::HasPulledUsers ( )

◆ HasPulledGroups()

bool Remote::HasPulledGroups ( )

◆ IsAdmin()

bool Remote::IsAdmin ( )

◆ IsEnterprise()

bool Remote::IsEnterprise ( )

Determine if a remote is the same as the currently connected Enterprise Server On non-Enterprise clients, this always returns false.

Returns
True if the remote is the same

◆ LoadMetadata()

bool Remote::LoadMetadata ( )

Load remote metadata, including version, id, and auth backends.

Exceptions
RemoteExceptionIf there is an error in any request, or if the remote version is not supported

◆ RequestAuthenticationToken()

std::string Remote::RequestAuthenticationToken ( const std::string &  username,
const std::string &  password 
)

Request an authentication token for a user given a username and password.

Parameters
usernameCollabUser's username
passwordCollabUser's password
Returns
Authentication token
Exceptions
RemoteExceptionIf there is an error in any request

◆ Connect()

void Remote::Connect ( const std::string &  username,
const std::string &  token 
)

Establish a connection to the remote, using a username and token.

Parameters
usernameCollabUser's username
tokenCollabUser's authentication token
Exceptions
RemoteExceptionIf there is an error in any request

◆ Disconnect()

void Remote::Disconnect ( )

Disconnect from the remote.

◆ GetProjects()

std::vector< Ref< RemoteProject > > Remote::GetProjects ( )

Get all projects in the Remote.

Returns
All projects
Exceptions
RemoteExceptionif projects have not been pulled or if the remote is not connected

◆ GetProjectById()

Ref< RemoteProject > Remote::GetProjectById ( const std::string &  id)

Get a project in the remote by its id.

Parameters
idProject's id
Returns
Project, or null shared_ptr if not found
Exceptions
RemoteExceptionIf projects have not been pulled or if the remote is not connected

◆ GetProjectByName()

Ref< RemoteProject > Remote::GetProjectByName ( const std::string &  name)

Get a project in the remote by its name.

Parameters
nameProject's name
Returns
Project, or null shared_ptr if not found
Exceptions
RemoteExceptionIf projects have not been pulled or if the remote is not connected

◆ PullProjects()

void Remote::PullProjects ( std::function< bool(size_t, size_t)>  progress = {})

Pull list of projects from the remote.

Necessary before calling GetProjects()

Parameters
progressFunction to call on progress updates
Exceptions
RemoteExceptionIf there is an error in any request or if the remote is not connected

◆ CreateProject()

Ref< RemoteProject > Remote::CreateProject ( const std::string &  name,
const std::string &  description 
)

Create a new project on the remote (and pull it)

Parameters
nameProject name
descriptionProject description
Returns
Reference to the created project
Exceptions
RemoteExceptionIf there is an error in any request or if the remote is not connected

◆ ImportLocalProject()

Ref< RemoteProject > Remote::ImportLocalProject ( Ref< Project localProject,
std::function< bool(size_t, size_t)>  progress = {} 
)

Create a new project on the remote from a local project.

Parameters
localProjectThe local project that should be copied to the server
progressFunction to call on progress updates
Returns
Reference to the created project
Exceptions
RemoteExceptionIf there is an error in any request or if the remote is not connected

◆ PushProject()

void Remote::PushProject ( Ref< RemoteProject project,
const std::vector< std::pair< std::string, std::string > > &  extraFields = {} 
)

Push fields of a modified project to the remote.

Parameters
projectUpdated project
extraFieldsExtra post fields for the request
Exceptions
RemoteExceptionIf there is an error in any request or if the remote is not connected

◆ DeleteProject()

void Remote::DeleteProject ( const Ref< RemoteProject project)

Delete a project from the remote.

Parameters
projectPointer to project to delete (will invalidate pointer)
Exceptions
RemoteExceptionIf there is an error in any request or if the remote is not connected

◆ GetGroups()

std::vector< Ref< CollabGroup > > Remote::GetGroups ( )

Get all groups in the Project.

Returns
All groups
Exceptions
RemoteExceptionif groups have not been pulled or if the remote is not connected

◆ GetGroupById()

Ref< CollabGroup > Remote::GetGroupById ( uint64_t  id)

Get a group in the project by its id.

Parameters
idGroup's id
Returns
Group, or null shared_ptr if not found
Exceptions
RemoteExceptionIf groups have not been pulled or if the remote is not connected

◆ GetGroupByName()

Ref< CollabGroup > Remote::GetGroupByName ( const std::string &  name)

Get a group in the project by its name.

Will check for both name and <project id>/name

Parameters
nameGroup's name
Returns
Group, or null shared_ptr if not found
Exceptions
RemoteExceptionIf groups have not been pulled or if the remote is not connected

◆ SearchGroups()

std::vector< std::pair< uint64_t, std::string > > Remote::SearchGroups ( const std::string &  prefix)

Search groups on the remote.

Parameters
prefixPrefix to search for
Exceptions
RemoteExceptionIf there is an error in any request or if the remote is not connected

◆ PullGroups()

void Remote::PullGroups ( std::function< bool(size_t, size_t)>  progress = {})

Pull list of groups from the remote.

Necessary before calling GetGroups()

Parameters
progressFunction to call on progress updates
Exceptions
RemoteExceptionIf there is an error in any request or if the remote is not connected

◆ CreateGroup()

Ref< CollabGroup > Remote::CreateGroup ( const std::string &  name,
const std::vector< std::string > &  usernames 
)

Create a new group on the remote (and pull it)

Parameters
nameGroup name
Returns
Reference to the created group
Exceptions
RemoteExceptionIf there is an error in any request or if the remote is not connected

◆ PushGroup()

void Remote::PushGroup ( Ref< CollabGroup group,
const std::vector< std::pair< std::string, std::string > > &  extraFields = {} 
)

Push fields of a modified group to the remote.

Parameters
groupUpdated group
extraFieldsExtra post fields for the request
Exceptions
RemoteExceptionIf there is an error in any request or if the remote is not connected

◆ DeleteGroup()

void Remote::DeleteGroup ( const Ref< CollabGroup group)

Delete a group from the remote.

Parameters
groupPointer to group to delete (will invalidate pointer)
Exceptions
RemoteExceptionIf there is an error in any request or if the remote is not connected

◆ GetUsers()

std::vector< Ref< CollabUser > > Remote::GetUsers ( )

Get all users in the Remote.

Returns
All users
Exceptions
RemoteExceptionif users have not been pulled or if the remote is not connected

◆ GetUserById()

Ref< CollabUser > Remote::GetUserById ( const std::string &  id)

Get a user in the remote by their id.

Parameters
idCollabUser's id
Returns
CollabUser, or null shared_ptr if not found
Exceptions
RemoteExceptionIf users have not been pulled or if the remote is not connected

◆ GetUserByUsername()

Ref< CollabUser > Remote::GetUserByUsername ( const std::string &  username)

Get a user in the remote by their username.

Parameters
usernameCollabUser's username
Returns
CollabUser, or null shared_ptr if not found
Exceptions
RemoteExceptionIf users have not been pulled or if the remote is not connected

◆ GetCurrentUser()

Ref< CollabUser > Remote::GetCurrentUser ( )

Get the currently logged-in user's CollabUser object.

Returns
The current user's CollabUser, or null shared_ptr if not found
Exceptions
RemoteExceptionif users have not been pulled or if the remote is not connected

◆ SearchUsers()

std::vector< std::pair< std::string, std::string > > Remote::SearchUsers ( const std::string &  prefix)

Search users on the remote.

Parameters
prefixPrefix to search for
Exceptions
RemoteExceptionIf there is an error in any request or if the remote is not connected

◆ PullUsers()

void Remote::PullUsers ( std::function< bool(size_t, size_t)>  progress = {})

Pull list of users from the remote.

Necessary before calling GetUsers()

Parameters
progressFunction to call on progress updates
Exceptions
RemoteExceptionIf there is an error in any request or if the remote is not connected

◆ CreateUser()

Ref< CollabUser > Remote::CreateUser ( const std::string &  username,
const std::string &  email,
bool  is_active,
const std::string &  password,
const std::vector< uint64_t > &  groupIds,
const std::vector< uint64_t > &  userPermissionIds 
)

Create a new user on the remote (and pull it)

Parameters
nameCollabUser name
emailCollabUser email
is_activeIf the user should initially be active
passwordCollabUser password
groupIdsList of group ids the user will be added to
userPermissionIdsList of permission ids the user will be granted
Returns
Reference to the created user
Exceptions
RemoteExceptionIf there is an error in any request or if the remote is not connected

◆ PushUser()

void Remote::PushUser ( Ref< CollabUser user,
const std::vector< std::pair< std::string, std::string > > &  extraFields = {} 
)

Push fields of a modified user to the remote.

Parameters
userUpdated user
extraFieldsExtra post fields for the request (eg password)
Exceptions
RemoteExceptionIf there is an error in any request or if the remote is not connected

◆ Request()

int Remote::Request ( Http::Request  request,
Http::Response ret 
)

Perform an arbitrary HTTP request.

An "Authorization: Token <token>" header will be added with the Remote's token for the current login session.

Parameters
requestRequest structure with headers and content.
responseResponse structure with body
Returns
Zero or greater on success