Exemplo n.º 1
0
        public static string GenerateUserPolicyDocument(string bucketName)
        {
            string resourcearn  = "arn:aws:s3:::" + bucketName + "/*";
            string resourcearn2 = "arn:aws:s3:::" + bucketName;
            var    actionGet    = new ActionIdentifier("s3:*");
            var    actions      = new List <ActionIdentifier>();

            actions.Add(actionGet);
            var resource  = new Resource(resourcearn);
            var resource2 = new Resource(resourcearn2);
            var resources = new List <Resource>();

            resources.Add(resource);
            resources.Add(resource2);
            var statement = new Amazon.Auth.AccessControlPolicy.Statement(Amazon.Auth.AccessControlPolicy.Statement.StatementEffect.Allow)
            {
                Actions   = actions,
                Id        = bucketName + "Statmentid",
                Resources = resources
            };
            var statements = new List <Amazon.Auth.AccessControlPolicy.Statement>();

            statements.Add(statement);
            var policy = new Policy
            {
                Id         = bucketName + "Policy",
                Version    = "2012-10-17",
                Statements = statements
            };

            return(policy.ToJson());
        }
Exemplo n.º 2
0
        public void addAction(ActionIdentifier ident, Action action, int stacking_delay)
        {
            BatchAction a = new BatchAction(ident);

            a.addAction(action);
            addBatch(a, stacking_delay);
        }
Exemplo n.º 3
0
        public static string GenerateRolePolicyDocument()
        {
            // Create a policy that looks like this:

            /*
             * {
             * "Version" : "2012-10-17",
             * "Id"  : "DemoEC2Permissions",
             * "Statement" : [
             *  {
             *    "Sid" : "DemoEC2PermissionsStatement",
             *    "Effect" : "Allow",
             *    "Action" : [
             *      "s3:Get*",
             *      "s3:List*"
             *    ],
             *    "Resource" : "*"
             *  }
             * ]
             * }
             */

            var actionGet  = new ActionIdentifier("s3:Get*");
            var actionList = new ActionIdentifier("s3:List*");
            var actions    = new List <ActionIdentifier>();

            actions.Add(actionGet);
            actions.Add(actionList);

            var resource  = new Resource("*");
            var resources = new List <Resource>();

            resources.Add(resource);

            var statement = new Amazon.Auth.AccessControlPolicy.Statement(Amazon.Auth.AccessControlPolicy.Statement.StatementEffect.Allow)
            {
                Actions   = actions,
                Id        = "DemoEC2PermissionsStatement",
                Resources = resources
            };
            var statements = new List <Amazon.Auth.AccessControlPolicy.Statement>();

            statements.Add(statement);

            var policy = new Policy
            {
                Id         = "DemoEC2Permissions",
                Version    = "2012-10-17",
                Statements = statements
            };

            return(policy.ToJson());
        }
Exemplo n.º 4
0
        public static void Main(string[] args)
        {
            const bool useEasySubscription = false;
            var        sns = new AmazonSimpleNotificationServiceClient();
            var        sqs = new AmazonSQSClient();

            string nameOfNewTopic = args[0];  //Sanitise this to ensure no illegal characters.
            var    emailAddress   = args[1];

            try
            {
                var topicArn = sns.CreateTopic(
                    new CreateTopicRequest {
                    Name = nameOfNewTopic
                }).TopicArn;

                sns.SetTopicAttributes(new SetTopicAttributesRequest
                {
                    TopicArn       = topicArn,
                    AttributeName  = "DisplayName",
                    AttributeValue = "Sample Notifications"
                });

                RetrieveAllTopics(sns);

                if (string.IsNullOrEmpty(emailAddress) == false)
                {
                    // Subscribe an endpoint - in this case, an email address
                    Console.WriteLine();
                    Console.WriteLine("Subscribing email address {0} to topic...", emailAddress);
                    sns.Subscribe(new SubscribeRequest
                    {
                        TopicArn = topicArn,
                        Protocol = "email",
                        Endpoint = emailAddress
                    });

                    // When using email, recipient must confirm subscription
                    Console.WriteLine();
                    Console.WriteLine("Please check your email and press enter when you are subscribed...");
                    Console.ReadLine();
                }

                Console.WriteLine();
                var sqsRequest = new CreateQueueRequest
                {
                    QueueName = "MyExperimentQueue"
                };

                var createQueueResponse = sqs.CreateQueue(sqsRequest);
                var myQueueUrl          = createQueueResponse.QueueUrl;

                var myQueueArn = sqs.GetQueueAttributes(
                    new GetQueueAttributesRequest
                {
                    QueueUrl       = myQueueUrl,
                    AttributeNames = new List <string> {
                        "All"
                    }
                }).QueueARN;

                ListQueues(sqs);

                if (myQueueArn != null)
                {
                    //https://aws.amazon.com/blogs/developer/subscribing-an-sqs-queue-to-an-sns-topic/

                    if (useEasySubscription)
                    {
                        sns.SubscribeQueue(topicArn, sqs, myQueueUrl);
                    }
                    else
                    {
                        var subscribeRequest = new SubscribeRequest(topicArn, "SQS", myQueueArn);

                        sns.Subscribe(subscribeRequest);

                        ActionIdentifier[] actions = new ActionIdentifier[2];
                        actions[0] = SQSActionIdentifiers.SendMessage;
                        actions[1] = SQSActionIdentifiers.ReceiveMessage;

                        Policy sqsPolicy = new Policy()
                                           .WithStatements(new Statement(Statement.StatementEffect.Allow)
                                                           .WithPrincipals(Principal.AllUsers)
                                                           .WithResources(new Resource(myQueueArn))
                                                           .WithConditions(ConditionFactory.NewSourceArnCondition(topicArn))
                                                           .WithActionIdentifiers(actions));


                        var attributeDictionary = new Dictionary <string, string>();
                        attributeDictionary.Add("Policy", sqsPolicy.ToJson());
                        var attributes = new SetQueueAttributesRequest {
                            QueueUrl = myQueueUrl, Attributes = attributeDictionary
                        };

                        sqs.SetQueueAttributes(attributes);
                    }

                    Thread.Sleep(TimeSpan.FromSeconds(5));

                    // Publish message
                    Console.WriteLine();
                    Console.WriteLine("Publishing message to topic...");
                    sns.Publish(new PublishRequest
                    {
                        Subject  = "Test",
                        Message  = "Testing testing 1 2 3",
                        TopicArn = topicArn
                    });
                    var receivedMessageResponse = ReceiveMessage(sqs, myQueueUrl);

                    DeleteReceivedMessage(receivedMessageResponse, myQueueUrl, sqs);
                }

                //Console.WriteLine();
                //Console.WriteLine("Deleting topic...");
                //sns.DeleteTopic(new DeleteTopicRequest
                //{
                //    TopicArn = topicArn
                //});
            }
            catch (AmazonSimpleNotificationServiceException ex)
            {
                Console.WriteLine("Caught Exception: " + ex.Message);
                Console.WriteLine("Response Status Code: " + ex.StatusCode);
                Console.WriteLine("Error Code: " + ex.ErrorCode);
                Console.WriteLine("Error Type: " + ex.ErrorType);
                Console.WriteLine("Request ID: " + ex.RequestId);
            }

            Console.WriteLine();
            Console.WriteLine("Press enter to exit...");
            Console.ReadLine();
        }
Exemplo n.º 5
0
 /// <exclude />
 public PageAddActionToken(Guid pageTypeId, ActionIdentifier actionIdentifier, IEnumerable <PermissionType> permissionTypes) : base(actionIdentifier, permissionTypes)
 {
     _pageTypeId = pageTypeId;
 }
Exemplo n.º 6
0
 /// <exclude />
 public PageAddActionToken(Guid pageTypeId, ActionIdentifier actionIdentifier) : base(actionIdentifier)
 {
     _pageTypeId = pageTypeId;
 }
Exemplo n.º 7
0
 public BatchAction(ActionIdentifier type)
 {
     this.type = type;
     actions   = new List <Action>();
 }