// NewOrganizationController creates an organization controller.
509844
func NewOrganizationController(service *goa.Service, app application.Application) *OrganizationController {
	return &OrganizationController{Controller: service.NewController("OrganizationController"), app: app}
}
1001036
func (s *OrganizationService) CreateOrganization(ctx context.Context, o *platform.Organization) error {
	if o.Name == "" {
		return kerrors.InvalidDataf("organization name is required")
	}

	url, err := newURL(s.Addr, organizationPath)
	if err != nil {
		return err
	}

	octets, err := json.Marshal(o)
	if err != nil {
		return err
	}

	req, err := http.NewRequest("POST", url.String(), bytes.NewReader(octets))
	if err != nil {
		return err
	}

	req.Header.Set("Content-Type", "application/json")
	SetToken(s.Token, req)

	hc := newClient(url.Scheme, s.InsecureSkipVerify)

	resp, err := hc.Do(req)
	if err != nil {
		return err
	}

	// TODO(jsternberg): Should this check for a 201 explicitly?
	if err := CheckError(resp, true); err != nil {
		return err
	}

	if err := json.NewDecoder(resp.Body).Decode(o); err != nil {
		return err
	}

	return nil
}
321307
func (s *OrganizationService) DeleteOrganization(ctx context.Context, id platform.ID) error {
	u, err := newURL(s.Addr, organizationIDPath(id))
	if err != nil {
		return err
	}

	req, err := http.NewRequest("DELETE", u.String(), nil)
	if err != nil {
		return err
	}
	SetToken(s.Token, req)

	hc := newClient(u.Scheme, s.InsecureSkipVerify)
	resp, err := hc.Do(req)
	if err != nil {
		return err
	}

	return CheckErrorStatus(http.StatusNoContent, resp, true)
}
975249
func (s *ListMailboxPermissionsInput) SetOrganizationId(v string) *ListMailboxPermissionsInput {
	s.OrganizationId = &v
	return s
}
555183
func NewOrganizationConfig(name string, orgGroup *cb.ConfigGroup, mspConfigHandler *MSPConfigHandler) (*OrganizationConfig, error) {
	if len(orgGroup.Groups) > 0 {
		return nil, fmt.Errorf("organizations do not support sub-groups")
	}

	oc := &OrganizationConfig{
		protos:           &OrganizationProtos{},
		name:             name,
		mspConfigHandler: mspConfigHandler,
	}

	if err := DeserializeProtoValuesFromGroup(orgGroup, oc.protos); err != nil {
		return nil, errors.Wrap(err, "failed to deserialize values")
	}

	if err := oc.Validate(); err != nil {
		return nil, err
	}

	return oc, nil
}
1158720
func (s *Service) CreateOrganization(ctx context.Context, o *influxdb.Organization) error {
	return s.kv.Update(ctx, func(tx Tx) error {
		if err := s.createOrganization(ctx, tx, o); err != nil {
			return err
		}

		// Attempt to add user as owner of organization, if that is not possible allow the
		// organization to be created anyways.
		if err := s.addOrgOwner(ctx, tx, o.ID); err != nil {
			s.Logger.Info("failed to make user owner of organization", zap.Error(err))
		}

		return nil
	})
}
296959
func (s *UpdateServiceSettingsInput) SetOrganizationConfiguration(v *OrganizationConfiguration) *UpdateServiceSettingsInput {
	s.OrganizationConfiguration = v
	return s
}
646364
func (s *JoinDomainInput) SetOrganizationalUnit(v string) *JoinDomainInput {
	s.OrganizationalUnit = &v
	return s
}
426846
func (s *AssociateDelegateToResourceInput) SetOrganizationId(v string) *AssociateDelegateToResourceInput {
	s.OrganizationId = &v
	return s
}
1056329
func (s *CreateGroupInput) SetOrganizationId(v string) *CreateGroupInput {
	s.OrganizationId = &v
	return s
}
482547
func (s *DeleteGroupInput) SetOrganizationId(v string) *DeleteGroupInput {
	s.OrganizationId = &v
	return s
}
499012
func (api OrganizationsAPI) CreateNewOrganization(w http.ResponseWriter, r *http.Request) {
	var org organization.Organization

	if err := json.NewDecoder(r.Body).Decode(&org); err != nil {
		log.Debug("Error decoding the organization:", err)
		http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
		return
	}
	org.Globalid = strings.Trim(org.Globalid, " ")
	if !org.IsValid() {
		log.Debug("Invalid organization")
		http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
		return
	}

	api.actualOrganizationCreation(org, w, r)

}
1209324
func (c *Client) CreateOrganization(ctx context.Context, o *platform.Organization) error {
	op := getOp(platform.OpCreateOrganization)
	return c.db.Update(func(tx *bolt.Tx) error {
		unique := c.uniqueOrganizationName(ctx, tx, o)
		if !unique {
			return &platform.Error{
				Code: platform.EConflict,
				Op:   op,
				Msg:  fmt.Sprintf("organization with name %s already exists", o.Name),
			}
		}

		o.ID = c.IDGenerator.ID()
		if err := c.appendOrganizationEventToLog(ctx, tx, o.ID, organizationCreatedEvent); err != nil {
			return &platform.Error{
				Err: err,
				Op:  op,
			}
		}

		if err := c.putOrganization(ctx, tx, o); err != nil {
			return &platform.Error{
				Err: err,
				Op:  op,
			}
		}
		return nil
	})
}
342633
func (s *CreateResourceInput) SetOrganizationId(v string) *CreateResourceInput {
	s.OrganizationId = &v
	return s
}
358954
func (api *API) CreateOrganizationAccessRule(organizationID string, accessRule AccessRule) (*AccessRuleResponse, error) {
	return api.createAccessRule("/accounts/"+organizationID, accessRule)
}
354970
func newController(config ControllerConfig, manager *residentManager) (*Controller, error) {
	if err := config.Validate(); err != nil {
		return nil, errors.Trace(err)
	}

	c := &Controller{
		manager: manager,
		changes: config.Changes,
		notify:  config.Notify,
		models:  make(map[string]*Model),
		hub: pubsub.NewSimpleHub(&pubsub.SimpleHubConfig{
			// TODO: (thumper) add a get child method to loggers.
			Logger: loggo.GetLogger("juju.core.cache.hub"),
		}),
		metrics: createControllerGauges(),
	}

	manager.dying = c.tomb.Dying()
	c.tomb.Go(c.loop)
	return c, nil
}
1199233
func (o *Organizations) DefaultOrganization(ctx context.Context) (*chronograf.Organization, error) {
	return nil, fmt.Errorf("unable to get default organizations from the filestore")
}