···107107 "minimum" => 80,
108108 "maximum" => 65535
109109 },
110110- "organization" => %{
111111- "type" => "object",
112112- "properties" => %{
113113- "mode" => %{
114114- "type" => "string",
115115- "enum" => ["single", "multi"],
116116- "default" => "single",
117117- "description" =>
118118- "Whether to run in single or multiple organization mode. Will create all new resources in a default organization if set to single."
119119- },
120120- "name" => %{
121121- "type" => "string",
122122- "default" => "default organization",
123123- "description" => "Name of the default organization in single org mode"
124124- }
125125- }
126126- },
110110+ # this isn't actually supported yet
111111+ # "organization" => %{
112112+ # "type" => "object",
113113+ # "properties" => %{
114114+ # "mode" => %{
115115+ # "type" => "string",
116116+ # "enum" => ["single", "multi"],
117117+ # "default" => "single",
118118+ # "description" =>
119119+ # "Whether to run in single or multiple organization mode. Will create all new resources in a default organization if set to single."
120120+ # },
121121+ # "name" => %{
122122+ # "type" => "string",
123123+ # "default" => "default organization",
124124+ # "description" => "Name of the default organization in single org mode"
125125+ # }
126126+ # }
127127+ # },
127128 "public_url" => %{
128129 "type" => "string",
129130 "format" => "uri"
+9
apps/sower/lib/sower/orchestration.ex
···171171 alias Sower.Orchestration.Subscription
172172173173 @doc """
174174+ Find deployments for an agent
175175+ """
176176+ def deployments_for_agent(%Agent{} = agent) do
177177+ agent.subscriptions
178178+ |> Enum.map(& &1.deployments)
179179+ |> dbg()
180180+ end
181181+182182+ @doc """
174183 Returns the list of subscriptions.
175184176185 ## Examples
+30-2
apps/sower/lib/sower/repo/seeds/preseed.ex
···1818 end
19192020 def for_dev(email) do
2121- name = email |> String.split("@") |> List.first()
2121+ Application.load(:sower)
22222323- simple_org_and_key(%Org{name: name, email: email}, Path.absname(".dev-api-token"))
2323+ token_file = Path.absname(".dev-api-token")
2424+2525+ Ecto.Migrator.with_repo(Sower.Repo, fn _repo ->
2626+ case Sower.Repo.all_by(Sower.Accounts.User, [email: email], skip_org_id: true) do
2727+ [] ->
2828+ Logger.error(msg: "User for email not found. Did you log in first?")
2929+ Kernel.exit(1)
3030+3131+ [user] ->
3232+ case Sower.Accounts.Organization.list() do
3333+ [_org] ->
3434+ access_token =
3535+ Org.access_token(user, "dev token", %{
3636+ "expires_at" => Date.add(Date.utc_today(), 30)
3737+ })
3838+3939+ File.write!(token_file, access_token.token)
4040+ Logger.info("Wrote #{token_file}")
4141+4242+ orgs ->
4343+ Logger.error(
4444+ msg: "Can't handle no organizations or more than one organization.",
4545+ organizations: orgs
4646+ )
4747+4848+ Kernel.exit(1)
4949+ end
5050+ end
5151+ end)
2452 end
25532654 defp simple_org_and_key(%Org{} = org, token_file) do
+2-1
apps/sower/lib/sower/seed.ex
···6666 end
67676868 def list() do
6969- Repo.all(Seed)
6969+ query = from s in Seed, order_by: [desc: s.updated_at]
7070+ Repo.all(query)
7071 end
71727273 def latest(name, seed_type) do
···4848 live "/agents/:sid/show/edit", AgentLive.Show, :edit
49495050 live "/deployments", DeploymentLive.Index, :index
5151- live "/deployments/new", DeploymentLive.Form, :new
5251 live "/deployments/:sid", DeploymentLive.Show, :show
5353- live "/deployments/:sid/edit", DeploymentLive.Form, :edit
54525553 get "/forges/:sid/login", Forge.OauthController, :login
5654 get "/forges/oauth/callback", Forge.OauthController, :callback
+8-6
apps/sower/priv/repo/seeds.exs
···1010# We recommend using the bang functions (`insert!`, `update!`
1111# and so on) as they will fail if something goes wrong.
12121313-alias Sower.Repo.Seeds.Org
1414-1515-user = Org.new_org_and_user(%Org{name: "default organization", email: "default@sower.dev"})
1616-1717-user |> Org.access_token()
1818-user |> Org.fake_seeds()
1313+# if you want fake environment
1414+# alias Sower.Repo.Seeds.Org
1515+#
1616+# user = Org.new_org_and_user(%Org{name: "default organization", email: "default@sower.dev"})
1717+#
1818+# user |> Org.access_token()
1919+#
2020+# user |> Org.fake_seeds()
+6-2
config/config.exs
···88import Config
991010config :sower, ecto_repos: [Sower.Repo]
1111-config :sower, Sower.Repo, migration_primary_key: [type: :identity]
1111+1212+config :sower, Sower.Repo,
1313+ migration_primary_key: [type: :identity],
1414+ # store with usec mostly to avoid having to truncate utc_now()
1515+ migration_timestamps: [type: :utc_datetime_usec]
12161317# Configures the endpoint
1418config :sower, SowerWeb.Endpoint,
···58625963config :sower, :generators,
6064 migration: true,
6161- timestamp_type: :utc_datetime
6565+ timestamp_type: :utc_datetime_usec
62666367# Import environment specific config. This must remain at the bottom
6468# of this file so it overrides the configuration defined above.