MCPcopy Create free account
hub / github.com/bricks-cloud/BricksLLM / CreateKey

Method CreateKey

internal/manager/key.go:79–117  ·  view source on GitHub ↗
(rk *key.RequestKey)

Source from the content-addressed store, hash-verified

77}
78
79func (m *Manager) CreateKey(rk *key.RequestKey) (*key.ResponseKey, error) {
80 rk.CreatedAt = time.Now().Unix()
81 rk.UpdatedAt = time.Now().Unix()
82 rk.KeyId = util.NewUuid()
83
84 if err := rk.Validate(); err != nil {
85 return nil, err
86 }
87
88 if !rk.IsKeyNotHashed {
89 rk.Key = hasher.Hash(rk.Key)
90 }
91
92 if len(rk.SettingId) != 0 {
93 if _, err := m.s.GetProviderSetting(rk.SettingId, false); err != nil {
94 return nil, err
95 }
96 }
97
98 if len(rk.SettingIds) != 0 {
99 existing, err := m.s.GetProviderSettings(false, rk.SettingIds)
100 if err != nil {
101 return nil, err
102 }
103
104 if len(existing) == 0 {
105 return nil, errors.New("provider settings not found")
106 }
107 }
108
109 if len(rk.PolicyId) != 0 {
110 _, err := m.s.GetPolicyById(rk.PolicyId)
111 if err != nil {
112 return nil, err
113 }
114 }
115
116 return m.s.CreateKey(rk)
117}
118
119func (m *Manager) UpdateKey(id string, uk *key.UpdateKey) (*key.ResponseKey, error) {
120 uk.UpdatedAt = time.Now().Unix()

Callers

nothing calls this directly

Calls 7

NewUuidFunction · 0.92
HashFunction · 0.92
ValidateMethod · 0.65
GetProviderSettingMethod · 0.65
GetProviderSettingsMethod · 0.65
GetPolicyByIdMethod · 0.65
CreateKeyMethod · 0.65

Tested by

no test coverage detected