Browse Source

Projects and roles syncing are fully operational only now. Forget about previous commit, please

Rufus Deponian 3 years ago
parent
commit
52bcef3140
3 changed files with 9 additions and 4 deletions
  1. 5 3
      main.go
  2. 3 0
      project_and_roles_template.conf
  3. 1 1
      utils.go

+ 5 - 3
main.go

@@ -14,9 +14,9 @@ func main() {
 	osclient.syncProjects()
 	// fmt.Println("Deleting projects...")
 	// osclient.deleteAllProjects()
-	fmt.Println("Syncing role assignments")
+	fmt.Println("Syncing role assignments...")
 	osclient.syncRoleAssignments()
-	// fmt.Println("Deleting role assignments")
+	// fmt.Println("Deleting role assignments...")
 	// osclient.deleteAllRoleAssignments()
 }
 
@@ -54,6 +54,8 @@ func (osclient OpenstackIdentityClient) deleteAllProjects() {
 }
 
 func (osclient OpenstackIdentityClient) syncRoleAssignments() {
+	osclient.deleteAllRoleAssignments()
+
 	openstackProjects := osclient.getProjectsMap()
 	openstackUsers := osclient.getOpenstackUsersMap()
 	units := getCleanUnitsCodeMap(osclient.config)
@@ -115,7 +117,7 @@ func (osclient OpenstackIdentityClient) deleteAllRoleAssignments() {
 		}
 		unassignmentResult := roles.Unassign(osclient.client, osclient.userRoleID, unassignOpts)
 		checkErr(unassignmentResult.ExtractErr())
-		fmt.Printf("[%v/%v] %s --- %s\n", index, amount, roleAssignment.User.ID, roleAssignment.Scope.Project.ID)
+		fmt.Printf("[%v/%v] Role of user %s on project %s deleted\n", index, amount, roleAssignment.User.ID, roleAssignment.Scope.Project.ID)
 		index++
 	}
 }

+ 3 - 0
project_and_roles_template.conf

@@ -18,3 +18,6 @@ projects_domain_id = domain-id
 
 # ID роли, которая будет предоставлена пользователям на проектах
 user_role_id = role-id
+
+# Данные о регионе, который будет использоваться при создание compute-клиента
+region = Moscow

+ 1 - 1
utils.go

@@ -68,7 +68,7 @@ func initIdentityClient() OpenstackIdentityClient {
 	checkErr(err)
 
 	client, err := openstack.NewIdentityV3(provider, gophercloud.EndpointOpts{
-		Region: "Moscow",
+		Region: section.ValueOf("region"),
 	})
 	checkErr(err)