MCPcopy Create free account
hub / github.com/cloudbase/garm / sqlGiteaToCommonForgeCredentials

Method sqlGiteaToCommonForgeCredentials

database/sql/util.go:1034–1080  ·  view source on GitHub ↗
(creds GiteaCredentials)

Source from the content-addressed store, hash-verified

1032}
1033
1034func (s *sqlDatabase) sqlGiteaToCommonForgeCredentials(creds GiteaCredentials) (params.ForgeCredentials, error) {
1035 if len(creds.Payload) == 0 {
1036 return params.ForgeCredentials{}, errors.New("empty credentials payload")
1037 }
1038 data, err := util.Unseal(creds.Payload, []byte(s.cfg.Passphrase))
1039 if err != nil {
1040 return params.ForgeCredentials{}, fmt.Errorf("error unsealing credentials: %w", err)
1041 }
1042
1043 ep, err := s.sqlToCommonGithubEndpoint(creds.Endpoint)
1044 if err != nil {
1045 return params.ForgeCredentials{}, fmt.Errorf("error converting github endpoint: %w", err)
1046 }
1047
1048 commonCreds := params.ForgeCredentials{
1049 ID: creds.ID,
1050 Name: creds.Name,
1051 Description: creds.Description,
1052 APIBaseURL: creds.Endpoint.APIBaseURL,
1053 BaseURL: creds.Endpoint.BaseURL,
1054 CABundle: creds.Endpoint.CACertBundle,
1055 AuthType: creds.AuthType,
1056 CreatedAt: creds.CreatedAt,
1057 UpdatedAt: creds.UpdatedAt,
1058 ForgeType: creds.Endpoint.EndpointType,
1059 Endpoint: ep,
1060 CredentialsPayload: data,
1061 }
1062
1063 for _, repo := range creds.Repositories {
1064 commonRepo, err := s.sqlToCommonRepository(repo, false)
1065 if err != nil {
1066 return params.ForgeCredentials{}, fmt.Errorf("error converting github repository: %w", err)
1067 }
1068 commonCreds.Repositories = append(commonCreds.Repositories, commonRepo)
1069 }
1070
1071 for _, org := range creds.Organizations {
1072 commonOrg, err := s.sqlToCommonOrganization(org, false)
1073 if err != nil {
1074 return params.ForgeCredentials{}, fmt.Errorf("error converting github organization: %w", err)
1075 }
1076 commonCreds.Organizations = append(commonCreds.Organizations, commonOrg)
1077 }
1078
1079 return commonCreds, nil
1080}
1081
1082func (s *sqlDatabase) sqlToCommonGithubEndpoint(ep GithubEndpoint) (params.ForgeEndpoint, error) {
1083 ret := params.ForgeEndpoint{

Callers 7

sqlToCommonRepositoryMethod · 0.95
GetGiteaCredentialsMethod · 0.95
ListGiteaCredentialsMethod · 0.95

Calls 3

sqlToCommonRepositoryMethod · 0.95

Tested by

no test coverage detected