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

fix: Hello world action exposed to the internet in code first archetypes #1920

Merged
merged 2 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package ${package}.hello;

import kalix.javasdk.action.Action;
import kalix.javasdk.annotations.Acl;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@RequestMapping
/**
* This is a simple Action that returns "Hello World!" and it's exposed to the Internet.
* Locally, you can access it by running `curl http://localhost:9000/hello`.
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it intentional to have the annotation before the class comment?
Look non-standard to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I saw the same in the main class:

@SpringBootApplication
// Allow all other Kalix services deployed in the same project to access the components of this
// Kalix service, but disallow access from the internet. This can be overridden explicitly
// per component or method using annotations.
// Documentation at https://docs.kalix.io/services/using-acls.html
@Acl(allow = @Acl.Matcher(service = "*"))
public class Main {

  private static final Logger logger = LoggerFactory.getLogger(Main.class);

  public static void main(String[] args) {
    logger.info("Starting Kalix Application");
    SpringApplication.run(Main.class, args);
  }
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is different.

The following is a javadoc.

/**
 *
 */

While the comment in the Main.class is a comment about the Acl annotation that is just under it.

@Acl(allow = @Acl.Matcher(principal = Acl.Principal.INTERNET))
public class HelloWorld extends Action {

@GetMapping("/hello")
public Action.Effect<String> hello() {
return effects().reply("Hello World!");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<dockerImage>${D}{kalixContainerRegistry}/${D}{kalixOrganization}/${D}{project.artifactId}</dockerImage>
<dockerTag>${project.version}-${build.timestamp}</dockerTag>
<maven.build.timestamp.format>yyyyMMddHHmmss</maven.build.timestamp.format>
<mainClass>${package}.Main</mainClass>
<mainClass>${package}.MainKt</mainClass>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a Kotling expert, but without this, the mvn kalix:runAll command doesn't work.

ennru marked this conversation as resolved.
Show resolved Hide resolved

<jdk.target>17</jdk.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package ${package}.hello;

import kalix.javasdk.action.Action
import kalix.javasdk.annotations.Acl
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping


@RequestMapping
/**
* This is a simple Action that returns "Hello World!" and it's exposed to the Internet.
* Locally, you can access it by running `curl http://localhost:9000/hello`.
*/
@Acl(allow = [Acl.Matcher(principal = Acl.Principal.INTERNET)])
class HelloWorld : Action() {

@GetMapping("/hello")
fun hello(): Effect<String> {
return effects().reply("Hello World!")
}
}