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

Method CreateEnterprise

database/sql/enterprise.go:32–81  ·  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) CreateEnterprise(ctx context.Context, name string, credentials params.ForgeCredentials, webhookSecret string, poolBalancerType params.PoolBalancerType, agentMode bool) (paramEnt params.Enterprise, err error) {
33 if webhookSecret == "" {
34 return params.Enterprise{}, errors.New("creating enterprise: missing secret")
35 }
36 if credentials.ForgeType != params.GithubEndpointType {
37 return params.Enterprise{}, fmt.Errorf("enterprises are not supported on this forge type: %w", runnerErrors.ErrBadRequest)
38 }
39
40 secret, err := util.Seal([]byte(webhookSecret), []byte(s.cfg.Passphrase))
41 if err != nil {
42 return params.Enterprise{}, fmt.Errorf("error encoding secret: %w", err)
43 }
44
45 defer func() {
46 if err == nil {
47 s.sendNotify(common.EnterpriseEntityType, common.CreateOperation, paramEnt)
48 }
49 }()
50 newEnterprise := Enterprise{
51 Name: name,
52 WebhookSecret: secret,
53 PoolBalancerType: poolBalancerType,
54 AgentMode: agentMode,
55 }
56 err = s.conn.Transaction(func(tx *gorm.DB) error {
57 newEnterprise.CredentialsID = &credentials.ID
58 newEnterprise.EndpointName = &credentials.Endpoint.Name
59
60 q := tx.Create(&newEnterprise)
61 if q.Error != nil {
62 return fmt.Errorf("error creating enterprise: %w", q.Error)
63 }
64
65 newEnterprise, err = s.getEnterpriseByID(ctx, tx, newEnterprise.ID.String(), "Pools", "Credentials", "Endpoint", "Credentials.Endpoint")
66 if err != nil {
67 return fmt.Errorf("error creating enterprise: %w", err)
68 }
69 return nil
70 })
71 if err != nil {
72 return params.Enterprise{}, fmt.Errorf("error creating enterprise: %w", err)
73 }
74
75 ret, err := s.GetEnterpriseByID(ctx, newEnterprise.ID.String())
76 if err != nil {
77 return params.Enterprise{}, fmt.Errorf("error creating enterprise: %w", err)
78 }
79
80 return ret, nil
81}
82
83func (s *sqlDatabase) GetEnterprise(ctx context.Context, name, endpointName string) (params.Enterprise, error) {
84 enterprise, err := s.getEnterprise(ctx, name, endpointName)

Calls 4

sendNotifyMethod · 0.95
getEnterpriseByIDMethod · 0.95
GetEnterpriseByIDMethod · 0.95
StringMethod · 0.45