(rk *key.RequestKey)
| 77 | } |
| 78 | |
| 79 | func (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 | |
| 119 | func (m *Manager) UpdateKey(id string, uk *key.UpdateKey) (*key.ResponseKey, error) { |
| 120 | uk.UpdatedAt = time.Now().Unix() |
nothing calls this directly
no test coverage detected