Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enanched project settings CLI managment #864

Merged
merged 5 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions templates/cli/lib/commands/pull.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ const pullProject = async () => {

})

localConfig.setProject(response.$id, response.name);
localConfig.setProject(response.$id, response.name, response);

success();
} catch (e) {
throw e;
Expand Down Expand Up @@ -169,7 +170,7 @@ const pull = new Command("pull")

pull
.command("project")
.description("Pulling your {{ spec.title|caseUcfirst }} project name")
.description("Pulling your {{ spec.title|caseUcfirst }} project name, services and auth settings")
.action(actionRunner(pullProject));

pull
Expand Down
65 changes: 60 additions & 5 deletions templates/cli/lib/commands/push.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,17 @@ const {
teamsUpdateName,
teamsCreate
} = require("./teams");
const { projectsUpdate } = require("./projects");
const {
projectsUpdate,
projectsUpdateServiceStatus,
projectsUpdateAuthStatus,
projectsUpdateAuthDuration,
projectsUpdateAuthLimit,
projectsUpdateAuthSessionsLimit,
projectsUpdateAuthPasswordDictionary,
projectsUpdateAuthPasswordHistory,
projectsUpdatePersonalDataCheck,
} = require("./projects");
const { checkDeployConditions } = require('../utils');

const STEP_SIZE = 100; // Resources
Expand Down Expand Up @@ -258,11 +268,56 @@ const pushResources = async ({ all, yes } = {}) => {

const pushProject = async () => {
try {
const projectId = localConfig.getProject().projectId;
const projectName = localConfig.getProject().projectName;

log(`Updating project ${projectName} ( ${projectId} )`);

await projectsUpdate({
projectId: localConfig.getProject().projectId,
name: localConfig.getProject().projectName,
projectId,
name: projectName,
parseOutput: false
})
});

const settings = localConfig.getProject().projectSettings;

if (settings.services) {
log('Updating service statuses');
for (let [service, status] of Object.entries(settings.services)) {
await projectsUpdateServiceStatus({
projectId,
service,
status,
parseOutput: false
});
}
}

if (settings.auth) {
if (settings.auth.security) {
log('Updating auth security settings');
await projectsUpdateAuthDuration({ projectId, duration: settings.auth.security.duration, parseOutput: false });
await projectsUpdateAuthLimit({ projectId, limit: settings.auth.security.limit, parseOutput: false });
await projectsUpdateAuthSessionsLimit({ projectId, limit: settings.auth.security.sessionsLimit, parseOutput: false });
await projectsUpdateAuthPasswordDictionary({ projectId, enabled: settings.auth.security.passwordDictionary, parseOutput: false });
await projectsUpdateAuthPasswordHistory({ projectId, limit: settings.auth.security.passwordHistory, parseOutput: false });
await projectsUpdatePersonalDataCheck({ projectId, enabled: settings.auth.security.personalDataCheck, parseOutput: false });
}

if (settings.auth.methods) {
log('Updating auth login methods');

for (let [method, status] of Object.entries(settings.auth.methods)) {
await projectsUpdateAuthStatus({
projectId,
method,
status,
parseOutput: false
});
}
}
}

success();
} catch (e) {
throw e;
Expand Down Expand Up @@ -1131,7 +1186,7 @@ push

push
.command("project")
.description("Push project name.")
.description("Push project name, services and auth settings")
.action(actionRunner(pushProject));

push
Expand Down
42 changes: 41 additions & 1 deletion templates/cli/lib/config.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -329,13 +329,53 @@ class Local extends Config {
return {
projectId: this.get("projectId"),
projectName: this.get("projectName"),
projectSettings: this.get('projectSettings')
};
}

setProject(projectId, projectName) {
setProject(projectId, projectName, projectSettings = {}) {
this.set("projectId", projectId);
this.set("projectName", projectName);

const settings = {
services: {
account: projectSettings.serviceStatusForAccount,
avatars: projectSettings.serviceStatusForAvatars,
databases: projectSettings.serviceStatusForDatabases,
locale: projectSettings.serviceStatusForLocale,
health: projectSettings.serviceStatusForHealth,
storage: projectSettings.serviceStatusForStorage,
teams: projectSettings.serviceStatusForTeams,
users: projectSettings.serviceStatusForUsers,
functions: projectSettings.serviceStatusForFunctions,
graphql: projectSettings.serviceStatusForGraphql,
messaging: projectSettings.serviceStatusForMessaging,

},
auth: {
methods: {
jwt: projectSettings.authJWT,
phone: projectSettings.authPhone,
invites: projectSettings.authInvites,
anonymous: projectSettings.authAnonymous,
"email-otp": projectSettings.authEmailOtp,
"magic-url": projectSettings.authUsersAuthMagicURL,
"email-password": projectSettings.authEmailPassword
},
security: {
duration: projectSettings.authDuration,
limit: projectSettings.authLimit,
sessionsLimit: projectSettings.authSessionsLimit,
passwordHistory: projectSettings.authPasswordHistory,
passwordDictionary: projectSettings.authPasswordDictionary,
personalDataCheck: projectSettings.authPersonalDataCheck
}
}
};

this.set('projectSettings', settings)
}

}

class Global extends Config {
Expand Down
Loading