Documentation
¶
Overview ¶
Package api provides clients for InfluxDB server APIs
Examples ¶
Users API
// Create influxdb client
client := influxdb2.NewClient("http://localhost:9999", "my-token")
// Find organization
org, err := client.OrganizationsApi().FindOrganizationByName(context.Background(), "my-org")
if err != nil {
panic(err)
}
// Get users API client
usersApi := client.UsersApi()
// Create new user
user, err := usersApi.CreateUserWithName(context.Background(), "user-01")
if err != nil {
panic(err)
}
// Set user password
err = usersApi.UpdateUserPassword(context.Background(), user, "pass-at-least-8-chars")
if err != nil {
panic(err)
}
// Add user to organization
_, err = client.OrganizationsApi().AddMember(context.Background(), org, user)
if err != nil {
panic(err)
}
Organizations API
// Create influxdb client
client := influxdb2.NewClient("http://localhost:9999", "my-token")
// Get Organizations API client
orgApi := client.OrganizationsApi()
// Create new organization
org, err := orgApi.CreateOrganizationWithName(context.Background(), "org-2")
if err != nil {
panic(err)
}
orgDescription := "My second org "
org.Description = &orgDescription
org, err = orgApi.UpdateOrganization(context.Background(), org)
if err != nil {
panic(err)
}
// Find user to set owner
user, err := client.UsersApi().FindUserByName(context.Background(), "user-01")
if err != nil {
panic(err)
}
// Add another owner (first owner is the one who create organization
_, err = orgApi.AddOwner(context.Background(), org, user)
if err != nil {
panic(err)
}
// Create new user to add to org
newUser, err := client.UsersApi().CreateUserWithName(context.Background(), "user-02")
if err != nil {
panic(err)
}
// Add new user to organization
_, err = orgApi.AddMember(context.Background(), org, newUser)
if err != nil {
panic(err)
}
Authorizations API
// Create influxdb client
client := influxdb2.NewClient("http://localhost:9999", "my-token")
// Find user to grant permission
user, err := client.UsersApi().FindUserByName(context.Background(), "user-01")
if err != nil {
panic(err)
}
// Find organization
org, err := client.OrganizationsApi().FindOrganizationByName(context.Background(), "my-org")
if err != nil {
panic(err)
}
// create write permission for buckets
permissionWrite := &domain.Permission{
Action: domain.PermissionActionWrite,
Resource: domain.Resource{
Type: domain.ResourceTypeBuckets,
},
}
// create read permission for buckets
permissionRead := &domain.Permission{
Action: domain.PermissionActionRead,
Resource: domain.Resource{
Type: domain.ResourceTypeBuckets,
},
}
// group permissions
permissions := []domain.Permission{*permissionWrite, *permissionRead}
// create authorization object using info above
auth := &domain.Authorization{
OrgID: org.Id,
Permissions: &permissions,
User: &user.Name,
UserID: user.Id,
}
// grant permission and create token
authCreated, err := client.AuthorizationsApi().CreateAuthorization(context.Background(), auth)
if err != nil {
panic(err)
}
// Use token
fmt.Println("Token: ", *authCreated.Token)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuthorizationsApi ¶
type AuthorizationsApi interface {
// GetAuthorizations returns all authorizations
GetAuthorizations(ctx context.Context) (*[]domain.Authorization, error)
// FindAuthorizationsByUserName returns all authorizations for given userName
FindAuthorizationsByUserName(ctx context.Context, userName string) (*[]domain.Authorization, error)
// FindAuthorizationsByUserId returns all authorizations for given userID
FindAuthorizationsByUserId(ctx context.Context, userId string) (*[]domain.Authorization, error)
// FindAuthorizationsByOrgName returns all authorizations for given organization name
FindAuthorizationsByOrgName(ctx context.Context, orgName string) (*[]domain.Authorization, error)
// FindAuthorizationsByUserId returns all authorizations for given organization id
FindAuthorizationsByOrgId(ctx context.Context, orgId string) (*[]domain.Authorization, error)
// CreateAuthorization creates new authorization
CreateAuthorization(ctx context.Context, authorization *domain.Authorization) (*domain.Authorization, error)
// CreateAuthorizationWithOrgId creates new authorization with given permissions scoped to given orgId
CreateAuthorizationWithOrgId(ctx context.Context, orgId string, permissions []domain.Permission) (*domain.Authorization, error)
// UpdateAuthorizationStatus updates status of authorization with authId
UpdateAuthorizationStatus(ctx context.Context, authId string, status domain.AuthorizationUpdateRequestStatus) (*domain.Authorization, error)
// DeleteAuthorization deletes authorization with authId
DeleteAuthorization(ctx context.Context, authId string) error
}
AuthorizationsApi provides methods for organizing Authorization in a InfluxDB server
func NewAuthorizationApi ¶
func NewAuthorizationApi(service ihttp.Service) AuthorizationsApi
type OrganizationsApi ¶
type OrganizationsApi interface {
// GetOrganizations returns all organizations
GetOrganizations(ctx context.Context) (*[]domain.Organization, error)
// FindOrganizationByName returns an organization found using orgName
FindOrganizationByName(ctx context.Context, orgName string) (*domain.Organization, error)
// FindOrganizationById returns an organization found using orgId
FindOrganizationById(ctx context.Context, orgId string) (*domain.Organization, error)
// FindOrganizationsByUserId returns organizations an user with userID belongs to
FindOrganizationsByUserId(ctx context.Context, orgId string) (*[]domain.Organization, error)
// CreateOrganization creates new organization
CreateOrganization(ctx context.Context, org *domain.Organization) (*domain.Organization, error)
// CreateOrganizationWithName creates new organization with orgName and with status active
CreateOrganizationWithName(ctx context.Context, orgName string) (*domain.Organization, error)
// UpdateOrganization updates organization
UpdateOrganization(ctx context.Context, org *domain.Organization) (*domain.Organization, error)
// DeleteOrganization deletes an organization
DeleteOrganization(ctx context.Context, org *domain.Organization) error
// DeleteOrganizationWithId deletes an organization with orgId
DeleteOrganizationWithId(ctx context.Context, orgId string) error
// GetMembers returns members of an organization
GetMembers(ctx context.Context, org *domain.Organization) (*[]domain.ResourceMember, error)
// GetMembersWithId returns members of an organization with orgId
GetMembersWithId(ctx context.Context, orgId string) (*[]domain.ResourceMember, error)
// AddMember add a user to an organization
AddMember(ctx context.Context, org *domain.Organization, user *domain.User) (*domain.ResourceMember, error)
// AddMember add a member with id memberId to an organization with orgId
AddMemberWithId(ctx context.Context, orgId, memberId string) (*domain.ResourceMember, error)
// RemoveMember removes a user from an organization
RemoveMember(ctx context.Context, org *domain.Organization, user *domain.User) error
// RemoveMember removes a member with id memberId from an organization with orgId
RemoveMemberWithId(ctx context.Context, orgId, memberId string) error
// GetMembers returns members of an organization
GetOwners(ctx context.Context, org *domain.Organization) (*[]domain.ResourceOwner, error)
// GetMembersWithId returns members of an organization with orgId
GetOwnersWithId(ctx context.Context, orgId string) (*[]domain.ResourceOwner, error)
// AddOwner add a user to an organization
AddOwner(ctx context.Context, org *domain.Organization, user *domain.User) (*domain.ResourceOwner, error)
// AddOwner add an owner with id memberId to an organization with orgId
AddOwnerWithId(ctx context.Context, orgId, memberId string) (*domain.ResourceOwner, error)
// RemoveOwner a user from an organization
RemoveOwner(ctx context.Context, org *domain.Organization, user *domain.User) error
// RemoveOwner removes a member with id memberId from an organization with orgId
RemoveOwnerWithId(ctx context.Context, orgId, memberId string) error
}
OrganizationsApi provides methods for managing Organizations in a InfluxDB server
func NewOrganizationsApi ¶
func NewOrganizationsApi(service ihttp.Service) OrganizationsApi
type UsersApi ¶
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 an user
UpdateUserPassword(ctx context.Context, user *domain.User, password string) error
// UpdateUserPasswordWithId sets password for an 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, password string) error
}
UsersApi provides methods for managing users in a InfluxDB server
func NewUsersApi ¶
Click to show internal directories.
Click to hide internal directories.