|
2 | 2 | // Use of this source code is governed by MIT
|
3 | 3 | // license that can be found in the LICENSE file.
|
4 | 4 |
|
5 |
| -// Package api provides clients for InfluxDB server APIs |
6 |
| -// |
7 |
| -// Examples |
8 |
| -// |
9 |
| -// Users API |
10 |
| -// |
11 |
| -// // Create influxdb client |
12 |
| -// client := influxdb2.NewClient("http://localhost:9999", "my-token") |
13 |
| -// |
14 |
| -// // Find organization |
15 |
| -// org, err := client.OrganizationsApi().FindOrganizationByName(context.Background(), "my-org") |
16 |
| -// if err != nil { |
17 |
| -// panic(err) |
18 |
| -// } |
19 |
| -// |
20 |
| -// // Get users API client |
21 |
| -// usersApi := client.UsersApi() |
22 |
| -// |
23 |
| -// // Create new user |
24 |
| -// user, err := usersApi.CreateUserWithName(context.Background(), "user-01") |
25 |
| -// if err != nil { |
26 |
| -// panic(err) |
27 |
| -// } |
28 |
| -// |
29 |
| -// // Set user password |
30 |
| -// err = usersApi.UpdateUserPassword(context.Background(), user, "pass-at-least-8-chars") |
31 |
| -// if err != nil { |
32 |
| -// panic(err) |
33 |
| -// } |
34 |
| -// |
35 |
| -// // Add user to organization |
36 |
| -// _, err = client.OrganizationsApi().AddMember(context.Background(), org, user) |
37 |
| -// if err != nil { |
38 |
| -// panic(err) |
39 |
| -// } |
40 |
| -// |
41 |
| -// Organizations API |
42 |
| -// |
43 |
| -// // Create influxdb client |
44 |
| -// client := influxdb2.NewClient("http://localhost:9999", "my-token") |
45 |
| -// |
46 |
| -// // Get Organizations API client |
47 |
| -// orgApi := client.OrganizationsApi() |
48 |
| -// |
49 |
| -// // Create new organization |
50 |
| -// org, err := orgApi.CreateOrganizationWithName(context.Background(), "org-2") |
51 |
| -// if err != nil { |
52 |
| -// panic(err) |
53 |
| -// } |
54 |
| -// |
55 |
| -// orgDescription := "My second org " |
56 |
| -// org.Description = &orgDescription |
57 |
| -// |
58 |
| -// org, err = orgApi.UpdateOrganization(context.Background(), org) |
59 |
| -// if err != nil { |
60 |
| -// panic(err) |
61 |
| -// } |
62 |
| -// |
63 |
| -// // Find user to set owner |
64 |
| -// user, err := client.UsersApi().FindUserByName(context.Background(), "user-01") |
65 |
| -// if err != nil { |
66 |
| -// panic(err) |
67 |
| -// } |
68 |
| -// |
69 |
| -// // Add another owner (first owner is the one who create organization |
70 |
| -// _, err = orgApi.AddOwner(context.Background(), org, user) |
71 |
| -// if err != nil { |
72 |
| -// panic(err) |
73 |
| -// } |
74 |
| -// |
75 |
| -// // Create new user to add to org |
76 |
| -// newUser, err := client.UsersApi().CreateUserWithName(context.Background(), "user-02") |
77 |
| -// if err != nil { |
78 |
| -// panic(err) |
79 |
| -// } |
80 |
| -// |
81 |
| -// // Add new user to organization |
82 |
| -// _, err = orgApi.AddMember(context.Background(), org, newUser) |
83 |
| -// if err != nil { |
84 |
| -// panic(err) |
85 |
| -// } |
86 |
| -// |
87 |
| -// Authorizations API |
88 |
| -// |
89 |
| -// // Create influxdb client |
90 |
| -// client := influxdb2.NewClient("http://localhost:9999", "my-token") |
91 |
| -// |
92 |
| -// // Find user to grant permission |
93 |
| -// user, err := client.UsersApi().FindUserByName(context.Background(), "user-01") |
94 |
| -// if err != nil { |
95 |
| -// panic(err) |
96 |
| -// } |
97 |
| -// |
98 |
| -// // Find organization |
99 |
| -// org, err := client.OrganizationsApi().FindOrganizationByName(context.Background(), "my-org") |
100 |
| -// if err != nil { |
101 |
| -// panic(err) |
102 |
| -// } |
103 |
| -// |
104 |
| -// // create write permission for buckets |
105 |
| -// permissionWrite := &domain.Permission{ |
106 |
| -// Action: domain.PermissionActionWrite, |
107 |
| -// Resource: domain.Resource{ |
108 |
| -// Type: domain.ResourceTypeBuckets, |
109 |
| -// }, |
110 |
| -// } |
111 |
| -// |
112 |
| -// // create read permission for buckets |
113 |
| -// permissionRead := &domain.Permission{ |
114 |
| -// Action: domain.PermissionActionRead, |
115 |
| -// Resource: domain.Resource{ |
116 |
| -// Type: domain.ResourceTypeBuckets, |
117 |
| -// }, |
118 |
| -// } |
119 |
| -// |
120 |
| -// // group permissions |
121 |
| -// permissions := []domain.Permission{*permissionWrite, *permissionRead} |
122 |
| -// |
123 |
| -// // create authorization object using info above |
124 |
| -// auth := &domain.Authorization{ |
125 |
| -// OrgID: org.Id, |
126 |
| -// Permissions: &permissions, |
127 |
| -// User: &user.Name, |
128 |
| -// UserID: user.Id, |
129 |
| -// } |
130 |
| -// |
131 |
| -// // grant permission and create token |
132 |
| -// authCreated, err := client.AuthorizationsApi().CreateAuthorization(context.Background(), auth) |
133 |
| -// if err != nil { |
134 |
| -// panic(err) |
135 |
| -// } |
136 |
| -// |
137 |
| -// // Use token |
138 |
| -// fmt.Println("Token: ", *authCreated.Token) |
| 5 | +// Package api provides clients for InfluxDB server APIs. |
139 | 6 | package api
|
0 commit comments