Skip to content

🎥 Make videos programmatically with React

code structure

Jonny Burgerb2b6ba0ad117
diff --git a/packages/lambda/src/cli/info.ts b/packages/lambda/src/cli/info.ts
index 014dc9163b..06b056a86f 100644
--- a/packages/lambda/src/cli/info.ts
+++ b/packages/lambda/src/cli/info.ts
@@ -1,14 +1,5 @@
-import {
- GetGroupPolicyCommand,
- GetUserCommand,
- ListAttachedUserPoliciesCommand,
- ListGroupPoliciesCommand,
- ListGroupsForUserCommand,
- ListUserPoliciesCommand,
-} from '@aws-sdk/client-iam';
import {iam, lambda, s3} from 'aws-policies';
-import {iamClient} from '../aws-clients';
-import {Log} from './log';
+import {validateAll} from '../iam-validation/validate-all';
// Not exhaustive, but to test out aws-policies packages
const necessaryPolicies = [
@@ -22,54 +13,5 @@ const necessaryPolicies = [
console.log('should have policies', necessaryPolicies);
export const infoCommand = async () => {
- const user = await iamClient.send(new GetUserCommand({}));
-
- const policies = await iamClient.send(
- new ListUserPoliciesCommand({
- UserName: user.User?.UserName as string,
- })
- );
- const attachedPolicies = await iamClient.send(
- new ListAttachedUserPoliciesCommand({
- UserName: user.User?.UserName as string,
- })
- );
- const groups = await iamClient.send(
- new ListGroupsForUserCommand({
- UserName: user.User?.UserName as string,
- })
- );
- const policiesForGroups = await Promise.all(
- (groups.Groups ?? []).map(async (group) => {
- const response = await iamClient.send(
- new ListGroupPoliciesCommand({
- GroupName: group.GroupName,
- })
- );
- return (response.PolicyNames ?? []).map((policy) => {
- return {
- policyName: policy,
- groupName: group.GroupName,
- };
- });
- })
- );
- const groupPolicies = await Promise.all(
- policiesForGroups.flat(1).map(({groupName, policyName}) => {
- return iamClient.send(
- new GetGroupPolicyCommand({
- GroupName: groupName,
- PolicyName: policyName,
- })
- );
- })
- );
- Log.info(policies);
- Log.info(attachedPolicies);
- Log.info(groups);
- Log.info(
- groupPolicies.map((p) => {
- return JSON.parse(decodeURIComponent(p.PolicyDocument as string));
- })
- );
+ await validateAll();
};
diff --git a/packages/lambda/src/iam-validation/validate-all.ts b/packages/lambda/src/iam-validation/validate-all.ts
new file mode 100644
index 0000000000..3f2f935b7d
--- /dev/null
+++ b/packages/lambda/src/iam-validation/validate-all.ts
@@ -0,0 +1,65 @@
+import {
+ GetGroupPolicyCommand,
+ GetUserCommand,
+ ListAttachedUserPoliciesCommand,
+ ListGroupPoliciesCommand,
+ ListGroupsForUserCommand,
+ ListUserPoliciesCommand,
+} from '@aws-sdk/client-iam';
+import {iamClient} from '../aws-clients';
+import {Log} from '../cli/log';
+
+export const validateAll = async () => {
+ const user = await iamClient.send(new GetUserCommand({}));
+
+ const policies = await iamClient.send(
+ new ListUserPoliciesCommand({
+ UserName: user.User?.UserName as string,
+ })
+ );
+ const attachedPolicies = await iamClient.send(
+ new ListAttachedUserPoliciesCommand({
+ UserName: user.User?.UserName as string,
+ })
+ );
+ const groups = await iamClient.send(
+ new ListGroupsForUserCommand({
+ UserName: user.User?.UserName as string,
+ })
+ );
+ const policiesForGroups = await Promise.all(
+ (groups.Groups ?? []).map(async (group) => {
+ const response = await iamClient.send(
+ new ListGroupPoliciesCommand({
+ GroupName: group.GroupName,
+ })
+ );
+ return (response.PolicyNames ?? []).map((policy) => {
+ return {
+ policyName: policy,
+ groupName: group.GroupName,
+ };
+ });
+ })
+ );
+ const groupPolicies = await Promise.all(
+ policiesForGroups.flat(1).map(({groupName, policyName}) => {
+ return iamClient.send(
+ new GetGroupPolicyCommand({
+ GroupName: groupName,
+ PolicyName: policyName,
+ })
+ );
+ })
+ );
+ Log.info(policies);
+ Log.info(attachedPolicies);
+ Log.info(groups);
+ Log.info(
+ groupPolicies
+ .map((p) => {
+ return decodeURIComponent(p.PolicyDocument as string);
+ })
+ .join('\n')
+ );
+};