MCPcopy Create free account
hub / github.com/belak/gitdir / EnsureAdminUser

Method EnsureAdminUser

config.go:139–178  ·  view source on GitHub ↗

EnsureUser will load the current admin config and ensure the given user exists.

(username string, pubKey *models.PublicKey)

Source from the content-addressed store, hash-verified

137// EnsureUser will load the current admin config and ensure the given user
138// exists.
139func (c *Config) EnsureAdminUser(username string, pubKey *models.PublicKey) error {
140 adminRepo, err := c.openAdminRepo()
141 if err != nil {
142 return err
143 }
144
145 // Ensure the base config before we try and add a user.
146 err = c.ensureAdminConfig(adminRepo)
147 if err != nil {
148 return err
149 }
150
151 // Ensure User
152 err = c.ensureAdminUser(adminRepo, username, pubKey)
153 if err != nil {
154 return err
155 }
156
157 // Load config
158 err = c.loadConfig(adminRepo)
159 if err != nil {
160 return err
161 }
162
163 // We only commit at the very end, after everything has been loaded. This
164 // ensures we have a valid config.
165 status, err := adminRepo.Worktree.Status()
166 if err != nil {
167 return err
168 }
169
170 if !status.IsClean() {
171 err = adminRepo.Commit(fmt.Sprintf("Added %s to config as admin", username), nil)
172 if err != nil {
173 return err
174 }
175 }
176
177 return nil
178}
179
180func (c *Config) flatten() {
181 // Add all user public keys to the config.

Callers 1

EnsureAdminUserMethod · 0.95

Calls 5

openAdminRepoMethod · 0.95
ensureAdminConfigMethod · 0.95
ensureAdminUserMethod · 0.95
loadConfigMethod · 0.95
CommitMethod · 0.80

Tested by

no test coverage detected