MCPcopy Create free account
hub / github.com/barnybug/cli53 / parseAWSConfigProfile

Function parseAWSConfigProfile

util.go:200–261  ·  view source on GitHub ↗
(file *os.File, profile string, settings *awsProfileSettings)

Source from the content-addressed store, hash-verified

198}
199
200func parseAWSConfigProfile(file *os.File, profile string, settings *awsProfileSettings) (bool, error) {
201 scanner := bufio.NewScanner(file)
202 targetSections := map[string]struct{}{"profile " + profile: {}}
203 if profile == "default" {
204 targetSections = map[string]struct{}{"default": {}}
205 }
206
207 found := false
208 inTarget := false
209
210 for scanner.Scan() {
211 line := strings.TrimSpace(scanner.Text())
212 if line == "" || strings.HasPrefix(line, "#") || strings.HasPrefix(line, ";") {
213 continue
214 }
215 if strings.HasPrefix(line, "[") && strings.HasSuffix(line, "]") {
216 section := strings.TrimSpace(line[1 : len(line)-1])
217 _, inTarget = targetSections[section]
218 found = found || inTarget
219 continue
220 }
221 if !inTarget {
222 continue
223 }
224
225 key, value, ok := strings.Cut(line, "=")
226 if !ok {
227 continue
228 }
229 key = strings.TrimSpace(strings.ToLower(key))
230 value = strings.TrimSpace(value)
231
232 switch key {
233 case "region":
234 settings.Region = value
235 case "role_arn":
236 settings.RoleARN = value
237 case "source_profile":
238 settings.SourceProfileName = value
239 case "external_id":
240 settings.ExternalID = value
241 case "role_session_name":
242 settings.RoleSessionName = value
243 case "mfa_serial":
244 settings.MFASerial = value
245 case "login_session":
246 settings.LoginSession = value
247 case "duration_seconds":
248 seconds, err := strconv.Atoi(value)
249 if err != nil {
250 return false, fmt.Errorf("invalid duration_seconds %q", value)
251 }
252 settings.Duration = time.Duration(seconds) * time.Second
253 }
254 }
255
256 if err := scanner.Err(); err != nil {
257 return false, err

Callers 1

loadAWSProfileSettingsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected