func runDisable()

in code/function/function.go [145:175]


func runDisable(project string, svc *run.APIService, serviceList []*run.Service) error {
	for _, s := range serviceList {

		location, ok := s.Metadata.Labels["cloud.googleapis.com/location"]
		if !ok {
			return fmt.Errorf("location incorrectly placed in Cloud Run metadata")
		}

		name := fmt.Sprintf("projects/%s/locations/%s/services/%s", project, location, s.Metadata.Name)

		iamPolicy, err := svc.Projects.Locations.Services.GetIamPolicy(name).Do()
		if err != nil {
			return fmt.Errorf("error getting IAM policy: %s", err)
		}

		for i, b := range iamPolicy.Bindings {
			if find(b.Members, "allUsers") {
				iamPolicy.Bindings[i] = nil
			}
		}

		setReq := &run.SetIamPolicyRequest{}
		setReq.Policy = iamPolicy

		if _, err := svc.Projects.Locations.Services.SetIamPolicy(name, setReq).Do(); err != nil {
			return fmt.Errorf("error disabling external access to services: %s", err)
		}

	}
	return nil
}