瀏覽代碼

Add setting of admin role for cloud_admin for all projects during sync

Rufus Deponian 5 年之前
父節點
當前提交
fbba5949c1
共有 3 個文件被更改,包括 23 次插入10 次删除
  1. 10 0
      main.go
  2. 二進制
      openstack-projects-sync
  3. 13 10
      utils.go

+ 10 - 0
main.go

@@ -37,6 +37,16 @@ func (osclient OpenstackIdentityClient) syncProjects() {
 			checkErr(createResult.Err)
 			fmt.Printf("Project \"%s\" created\n", *unit.BriefName)
 		}
+
+		// Add cloud_admin user as admin to project
+		projectID := allProjects[persNumber].ID
+		assignOpts := roles.AssignOpts{
+			UserID:    osclient.cloudAdminID,
+			ProjectID: projectID,
+		}
+		assignmentResult := roles.Assign(osclient.client, osclient.adminRoleID, assignOpts)
+		checkErr(assignmentResult.ExtractErr())
+		fmt.Printf("Admin role on project %s assigned to cloud_admin\n", projectID)
 	}
 }
 

二進制
openstack-projects-sync


+ 13 - 10
utils.go

@@ -41,11 +41,12 @@ func capitalize(str string) string {
 // O P E N S T A C K   C L I E N T
 
 type OpenstackIdentityClient struct {
-	client      *gophercloud.ServiceClient
-	config      *configparser.Configuration
-	domainID    string
-	userRoleID  string
-	adminRoleID string
+	client       *gophercloud.ServiceClient
+	config       *configparser.Configuration
+	domainID     string
+	userRoleID   string
+	adminRoleID  string
+	cloudAdminID string
 }
 
 func initIdentityClient() OpenstackIdentityClient {
@@ -57,6 +58,7 @@ func initIdentityClient() OpenstackIdentityClient {
 	domainID := section.ValueOf("projects_domain_id")
 	userRoleID := section.ValueOf("user_role_id")
 	adminRoleID := section.ValueOf("admin_role_id")
+	cloudAdminID := section.ValueOf("cloud_admin_id")
 
 	opts := gophercloud.AuthOptions{
 		IdentityEndpoint: section.ValueOf("identity_endpoint"),
@@ -75,11 +77,12 @@ func initIdentityClient() OpenstackIdentityClient {
 	checkErr(err)
 
 	osclient := OpenstackIdentityClient{
-		client:      client,
-		config:      config,
-		domainID:    domainID,
-		userRoleID:  userRoleID,
-		adminRoleID: adminRoleID,
+		client:       client,
+		config:       config,
+		domainID:     domainID,
+		userRoleID:   userRoleID,
+		adminRoleID:  adminRoleID,
+		cloudAdminID: cloudAdminID,
 	}
 
 	return osclient