MCPcopy Create free account
hub / github.com/cloudbase/garm / CreateOrganization

Method CreateOrganization

database/sql/organizations.go:32–80  ·  view source on GitHub ↗
(ctx context.Context, name string, credentials params.ForgeCredentials, webhookSecret string, poolBalancerType params.PoolBalancerType, agentMode bool)

Source from the content-addressed store, hash-verified

30)
31
32func (s *sqlDatabase) CreateOrganization(ctx context.Context, name string, credentials params.ForgeCredentials, webhookSecret string, poolBalancerType params.PoolBalancerType, agentMode bool) (param params.Organization, err error) {
33 if webhookSecret == "" {
34 return params.Organization{}, errors.New("creating org: missing secret")
35 }
36 secret, err := util.Seal([]byte(webhookSecret), []byte(s.cfg.Passphrase))
37 if err != nil {
38 return params.Organization{}, fmt.Errorf("error encoding secret: %w", err)
39 }
40
41 defer func() {
42 if err == nil {
43 s.sendNotify(common.OrganizationEntityType, common.CreateOperation, param)
44 }
45 }()
46 newOrg := Organization{
47 Name: name,
48 WebhookSecret: secret,
49 PoolBalancerType: poolBalancerType,
50 AgentMode: agentMode,
51 }
52
53 err = s.conn.Transaction(func(tx *gorm.DB) error {
54 switch credentials.ForgeType {
55 case params.GithubEndpointType:
56 newOrg.CredentialsID = &credentials.ID
57 case params.GiteaEndpointType:
58 newOrg.GiteaCredentialsID = &credentials.ID
59 default:
60 return fmt.Errorf("unsupported credentials type: %w", runnerErrors.ErrBadRequest)
61 }
62
63 newOrg.EndpointName = &credentials.Endpoint.Name
64 q := tx.Create(&newOrg)
65 if q.Error != nil {
66 return fmt.Errorf("error creating org: %w", q.Error)
67 }
68 return nil
69 })
70 if err != nil {
71 return params.Organization{}, fmt.Errorf("error creating org: %w", err)
72 }
73
74 ret, err := s.GetOrganizationByID(ctx, newOrg.ID.String())
75 if err != nil {
76 return params.Organization{}, fmt.Errorf("error creating org: %w", err)
77 }
78
79 return ret, nil
80}
81
82func (s *sqlDatabase) GetOrganization(ctx context.Context, name, endpointName string) (params.Organization, error) {
83 org, err := s.getOrg(ctx, name, endpointName)

Calls 3

sendNotifyMethod · 0.95
GetOrganizationByIDMethod · 0.95
StringMethod · 0.45