ToModule converts the addedModule to a Module. If the addedModule is a local Module, this is just returned. If the addedModule is a remote Module, the ModuleDataProvider and CommitProvider are queried to get the Module.
( ctx context.Context, moduleDataProvider ModuleDataProvider, commitProvider CommitProvider, )
| 99 | // If the addedModule is a local Module, this is just returned. |
| 100 | // If the addedModule is a remote Module, the ModuleDataProvider and CommitProvider are queried to get the Module. |
| 101 | func (a *addedModule) ToModule( |
| 102 | ctx context.Context, |
| 103 | moduleDataProvider ModuleDataProvider, |
| 104 | commitProvider CommitProvider, |
| 105 | ) (Module, error) { |
| 106 | // If the addedModule is a local Module, just return it. |
| 107 | if a.localModule != nil { |
| 108 | return a.localModule, nil |
| 109 | } |
| 110 | // Else, get the remote Module. |
| 111 | getModuleData := sync.OnceValues( |
| 112 | func() (ModuleData, error) { |
| 113 | moduleDatas, err := moduleDataProvider.GetModuleDatasForModuleKeys( |
| 114 | ctx, |
| 115 | []ModuleKey{a.remoteModuleKey}, |
| 116 | ) |
| 117 | if err != nil { |
| 118 | return nil, fmt.Errorf("could not get module data for remote module %q: %w", a.remoteModuleKey.FullName().String(), err) |
| 119 | } |
| 120 | if len(moduleDatas) != 1 { |
| 121 | return nil, syserror.Newf("expected 1 ModuleData, got %d", len(moduleDatas)) |
| 122 | } |
| 123 | moduleData := moduleDatas[0] |
| 124 | if moduleData.ModuleKey().FullName() == nil { |
| 125 | return nil, syserror.New("got nil FullName for a ModuleKey returned from a ModuleDataProvider") |
| 126 | } |
| 127 | if a.remoteModuleKey.FullName().String() != moduleData.ModuleKey().FullName().String() { |
| 128 | return nil, syserror.Newf( |
| 129 | "mismatched FullName from ModuleDataProvider: input %q, output %q", |
| 130 | a.remoteModuleKey.FullName().String(), |
| 131 | moduleData.ModuleKey().FullName().String(), |
| 132 | ) |
| 133 | } |
| 134 | return moduleData, nil |
| 135 | }, |
| 136 | ) |
| 137 | getBucket := sync.OnceValues( |
| 138 | func() (storage.ReadBucket, error) { |
| 139 | moduleData, err := getModuleData() |
| 140 | if err != nil { |
| 141 | return nil, err |
| 142 | } |
| 143 | // ModuleData.Bucket has sync.OnceValues and getStorageMatchers applied since it can |
| 144 | // only be constructed via NewModuleData. |
| 145 | // |
| 146 | // TODO FUTURE: This is a bit shady. |
| 147 | return moduleData.Bucket() |
| 148 | }, |
| 149 | ) |
| 150 | getV1BufYAMLObjectData := func() (ObjectData, error) { |
| 151 | moduleData, err := getModuleData() |
| 152 | if err != nil { |
| 153 | return nil, err |
| 154 | } |
| 155 | return moduleData.V1Beta1OrV1BufYAMLObjectData() |
| 156 | } |
| 157 | getV1BufLockObjectData := func() (ObjectData, error) { |
| 158 | moduleData, err := getModuleData() |
no test coverage detected