Exemple #1
0
        public void TestLogTrigger()
        {
            tf.Client.CreateService(new CreateServiceRequest(Service));

            byte[] contents = File.ReadAllBytes(Directory.GetCurrentDirectory() + "/hello.zip");
            var    code     = new Code(Convert.ToBase64String(contents));

            tf.Client.CreateFunction(new CreateFunctionRequest(Service, Function, "python3", "index.handler", code, "desc"));

            string triggerName = "my-log-trigger";

            SouceConfig source            = new SouceConfig(tf.LogStore + "_source");
            LogConfig   logConfig         = new LogConfig(tf.LogProject, tf.LogStore);
            JobConfig   jobConfig         = new JobConfig(60, 10);
            var         functionParameter = new Dictionary <string, object> {
            };

            var logTriggerConfig = new LogTriggerConfig(source, jobConfig, functionParameter, logConfig, false);

            string sourceArn = string.Format("acs:log:{0}:{1}:project/{2}", tf.Region, tf.AccountID, tf.LogProject);
            var    response  = tf.Client.CreateTrigger(new CreateTriggerRequest(Service, Function, triggerName, "log",
                                                                                sourceArn, tf.InvocationRole, logTriggerConfig, "log trigger desc"));

            this.Triggers.Add(triggerName);

            Assert.Equal(triggerName, response.Data.TriggerName);
            Assert.Equal("log trigger desc", response.Data.Description);
            Assert.Equal("log", response.Data.TriggerType);
            Assert.Equal(sourceArn, response.Data.SourceArn);
            Assert.Equal(tf.InvocationRole, response.Data.InvocationRole);
            Assert.Equal(JsonConvert.DeserializeObject <LogTriggerConfig>(response.Data.TriggerConfig.ToString()), logTriggerConfig);
        }
Exemple #2
0
        public void TestListTriggers()
        {
            tf.Client.CreateService(new CreateServiceRequest(Service));

            byte[] contents = File.ReadAllBytes(Directory.GetCurrentDirectory() + "/hello.zip");
            var    code     = new Code(Convert.ToBase64String(contents));

            tf.Client.CreateFunction(new CreateFunctionRequest(Service, Function, "python3", "index.handler", code, "desc"));

            string triggerName = "my-oss-trigger";

            string[] events           = { "oss:ObjectCreated:PostObject", "oss:ObjectCreated:PutObject" };
            var      ossTriggerConfig = new OSSTriggerConfig(events, "pre", ".zip");


            string sourceArn = string.Format("acs:oss:{0}:{1}:{2}", tf.Region, tf.AccountID, tf.CodeBucket);

            tf.Client.CreateTrigger(new CreateTriggerRequest(Service, Function, triggerName, "oss",
                                                             sourceArn, tf.InvocationRole, ossTriggerConfig, "oss trigger desc"));

            this.Triggers.Add(triggerName);

            triggerName = "my-log-trigger";
            SouceConfig source            = new SouceConfig(tf.LogStore + "_source");
            LogConfig   logConfig         = new LogConfig(tf.LogProject, tf.LogStore);
            JobConfig   jobConfig         = new JobConfig(60, 10);
            var         functionParameter = new Dictionary <string, object> {
            };

            var logTriggerConfig = new LogTriggerConfig(source, jobConfig, functionParameter, logConfig, false);

            sourceArn = string.Format("acs:log:{0}:{1}:project/{2}", tf.Region, tf.AccountID, tf.LogProject);
            tf.Client.CreateTrigger(new CreateTriggerRequest(Service, Function, triggerName, "log",
                                                             sourceArn, tf.InvocationRole, logTriggerConfig, "log trigger desc"));

            this.Triggers.Add(triggerName);

            var response = tf.Client.ListTriggers(new ListTriggersRequest(Service, Function));

            Console.WriteLine(response.Content);
            Assert.Equal(2, response.Data.Triggers.GetLength(0));

            var response2 = tf.Client.ListTriggers(new ListTriggersRequest(Service, Function, 10, "my-log-"));

            Console.WriteLine(response2.Content);
            Assert.Equal(1, response2.Data.Triggers.GetLength(0));
            Assert.Equal(triggerName, response2.Data.Triggers[0].TriggerName);
            Assert.Equal("log trigger desc", response2.Data.Triggers[0].Description);
            Assert.Equal("log", response2.Data.Triggers[0].TriggerType);
            Assert.Equal(sourceArn, response2.Data.Triggers[0].SourceArn);
            Assert.Equal(tf.InvocationRole, response2.Data.Triggers[0].InvocationRole);
            Assert.Equal(JsonConvert.DeserializeObject <LogTriggerConfig>(response2.Data.Triggers[0].TriggerConfig.ToString()), logTriggerConfig);
        }