(creds GithubCredentials)
| 975 | } |
| 976 | |
| 977 | func (s *sqlDatabase) sqlToCommonForgeCredentials(creds GithubCredentials) (params.ForgeCredentials, error) { |
| 978 | if len(creds.Payload) == 0 { |
| 979 | return params.ForgeCredentials{}, errors.New("empty credentials payload") |
| 980 | } |
| 981 | data, err := util.Unseal(creds.Payload, []byte(s.cfg.Passphrase)) |
| 982 | if err != nil { |
| 983 | return params.ForgeCredentials{}, fmt.Errorf("error unsealing credentials: %w", err) |
| 984 | } |
| 985 | |
| 986 | ep, err := s.sqlToCommonGithubEndpoint(creds.Endpoint) |
| 987 | if err != nil { |
| 988 | return params.ForgeCredentials{}, fmt.Errorf("error converting github endpoint: %w", err) |
| 989 | } |
| 990 | |
| 991 | commonCreds := params.ForgeCredentials{ |
| 992 | ID: creds.ID, |
| 993 | Name: creds.Name, |
| 994 | Description: creds.Description, |
| 995 | APIBaseURL: creds.Endpoint.APIBaseURL, |
| 996 | BaseURL: creds.Endpoint.BaseURL, |
| 997 | UploadBaseURL: creds.Endpoint.UploadBaseURL, |
| 998 | CABundle: creds.Endpoint.CACertBundle, |
| 999 | AuthType: creds.AuthType, |
| 1000 | CreatedAt: creds.CreatedAt, |
| 1001 | UpdatedAt: creds.UpdatedAt, |
| 1002 | ForgeType: creds.Endpoint.EndpointType, |
| 1003 | Endpoint: ep, |
| 1004 | CredentialsPayload: data, |
| 1005 | } |
| 1006 | |
| 1007 | for _, repo := range creds.Repositories { |
| 1008 | commonRepo, err := s.sqlToCommonRepository(repo, false) |
| 1009 | if err != nil { |
| 1010 | return params.ForgeCredentials{}, fmt.Errorf("error converting github repository: %w", err) |
| 1011 | } |
| 1012 | commonCreds.Repositories = append(commonCreds.Repositories, commonRepo) |
| 1013 | } |
| 1014 | |
| 1015 | for _, org := range creds.Organizations { |
| 1016 | commonOrg, err := s.sqlToCommonOrganization(org, false) |
| 1017 | if err != nil { |
| 1018 | return params.ForgeCredentials{}, fmt.Errorf("error converting github organization: %w", err) |
| 1019 | } |
| 1020 | commonCreds.Organizations = append(commonCreds.Organizations, commonOrg) |
| 1021 | } |
| 1022 | |
| 1023 | for _, ent := range creds.Enterprises { |
| 1024 | commonEnt, err := s.sqlToCommonEnterprise(ent, false) |
| 1025 | if err != nil { |
| 1026 | return params.ForgeCredentials{}, fmt.Errorf("error converting github enterprise %s: %w", ent.Name, err) |
| 1027 | } |
| 1028 | commonCreds.Enterprises = append(commonCreds.Enterprises, commonEnt) |
| 1029 | } |
| 1030 | |
| 1031 | return commonCreds, nil |
| 1032 | } |
| 1033 | |
| 1034 | func (s *sqlDatabase) sqlGiteaToCommonForgeCredentials(creds GiteaCredentials) (params.ForgeCredentials, error) { |
no test coverage detected