-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [cli] added support for backend if no config file found on init
Signed-off-by: Miguel_LZPF <[email protected]>
- Loading branch information
1 parent
53f1355
commit 75a1afa
Showing
9 changed files
with
134 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,5 +31,6 @@ build | |
|
||
report.json | ||
|
||
.hsca-config*.yaml | ||
hsca-config.yaml | ||
./docs/* |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
cli/src/app/service/configuration/BackendConfigurationService.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* | ||
* Hedera Stablecoin CLI | ||
* | ||
* Copyright (C) 2023 Hedera Hashgraph, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
import { DEFAULT_BACKEND_ENDPOINT } from '../../../core/Constants'; | ||
import { configurationService, language, utilsService } from '../../../index'; | ||
import IBackendConfig from '../../../domain/configuration/interfaces/BackendConfig'; | ||
import Service from '../Service'; | ||
|
||
export default class BackendConfigurationService extends Service { | ||
constructor() { | ||
super('Backend Configuration'); | ||
} | ||
|
||
public async configureBackend(): Promise<IBackendConfig> { | ||
const configuration = configurationService.getConfiguration(); | ||
let endpoint: URL | undefined; | ||
|
||
// Try to get the endpoint up to 5 times | ||
for (let tries = 0; tries < 5; tries++) { | ||
try { | ||
const answer = configuration.backend?.endpoint | ||
? configuration.backend.endpoint | ||
: await utilsService.defaultSingleAsk( | ||
language.getText('configuration.askBackendUrl'), | ||
DEFAULT_BACKEND_ENDPOINT, | ||
); | ||
endpoint = new URL(answer); | ||
if (endpoint) break; // If we have a valid endpoint, break the loop | ||
} catch (error) { | ||
utilsService.showError( | ||
`${error}\n${language.getText('general.incorrectParam')}`, | ||
); | ||
} | ||
} | ||
|
||
// If we still don't have a valid endpoint, use the default one | ||
if (!endpoint) { | ||
endpoint = new URL(DEFAULT_BACKEND_ENDPOINT); | ||
} | ||
|
||
// Update the configuration and return it | ||
configuration.backend = { | ||
endpoint: endpoint.toString(), | ||
} as IBackendConfig; | ||
configurationService.setConfiguration(configuration); | ||
return configuration.backend; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters