mirror of
https://github.com/czhu12/canine.git
synced 2026-04-30 00:19:52 -05:00
updates to portainer login
This commit is contained in:
@@ -6,7 +6,9 @@
|
||||
<div class="flex items-center gap-1.5 text-xs px-2 py-1 rounded-md bg-blue-500/10 text-blue-400 border border-blue-500/20 transition-all duration-300 hover:bg-blue-500/25 hover:border-blue-500/40 hover:text-blue-300 cursor-pointer">
|
||||
<iconify-icon icon="lucide:server" width="14" height="14"></iconify-icon>
|
||||
<span class="font-medium">Managed via Portainer</span>
|
||||
<iconify-icon icon="lucide:external-link" width="12" height="12" class="opacity-80 group-hover/badge:opacity-100 transition-opacity duration-200 hidden" data-stack-manager-url-target="verifyUrlSuccess"></iconify-icon>
|
||||
<div class="tooltip tooltip-bottom flex hidden" data-tip="Portainer is reachable" data-stack-manager-url-target="verifyUrlSuccess">
|
||||
<iconify-icon icon="lucide:external-link" width="12" height="12" class="opacity-80 group-hover/badge:opacity-100 transition-opacity duration-200"></iconify-icon>
|
||||
</div>
|
||||
<div class="tooltip tooltip-bottom flex hidden" data-tip="Portainer URL cannot be reached" data-stack-manager-url-target="verifyUrlError">
|
||||
<iconify-icon icon="lucide:alert-circle" width="12" height="12" class="text-red-400 opacity-80 group-hover/badge:opacity-100 transition-opacity duration-200"></iconify-icon>
|
||||
</div>
|
||||
|
||||
+16
-1
@@ -13,6 +13,7 @@ module Portainer
|
||||
class UnauthorizedError < StandardError; end
|
||||
class ConnectionError < StandardError; end
|
||||
class PermissionDeniedError < StandardError; end
|
||||
class AuthenticationError < StandardError; end
|
||||
|
||||
def initialize(provider_url, jwt)
|
||||
@jwt = jwt
|
||||
@@ -61,7 +62,21 @@ module Portainer
|
||||
)
|
||||
end
|
||||
|
||||
response.parsed_response['jwt'] if response.success?
|
||||
if response.success?
|
||||
jwt = response.parsed_response['jwt']
|
||||
username_response = get(
|
||||
"#{provider_url}/api/users/me",
|
||||
headers: { 'Authorization' => "Bearer #{jwt}" },
|
||||
)
|
||||
|
||||
return Portainer::Data::User.new(
|
||||
id: username_response.parsed_response['Id'],
|
||||
username: username_response.parsed_response['Username'],
|
||||
jwt:
|
||||
)
|
||||
else
|
||||
raise AuthenticationError, "Invalid username or password"
|
||||
end
|
||||
rescue Socket::ResolutionError
|
||||
raise ConnectionError, "Portainer URL is not resolvable"
|
||||
rescue Net::ReadTimeout
|
||||
|
||||
@@ -1,4 +1,14 @@
|
||||
class Portainer::Data
|
||||
class User
|
||||
attr_accessor :id, :username, :jwt
|
||||
|
||||
def initialize(id:, username:, jwt:)
|
||||
@id = id
|
||||
@username = username
|
||||
@jwt = jwt
|
||||
end
|
||||
end
|
||||
|
||||
class Registry
|
||||
attr_accessor :id, :name, :url, :username, :password, :authentication
|
||||
|
||||
|
||||
+10
-7
@@ -9,17 +9,12 @@ class Portainer::Login
|
||||
context.user = User.find_or_initialize_by(
|
||||
email: context.username + "@oncanine.run",
|
||||
)
|
||||
jwt = Portainer::Client.authenticate(
|
||||
portainer_user = Portainer::Client.authenticate(
|
||||
username: context.username,
|
||||
auth_code: context.password,
|
||||
provider_url: provider_url
|
||||
)
|
||||
|
||||
if jwt.nil?
|
||||
context.user.errors.add(:base, "Invalid username or password")
|
||||
context.fail_and_return!
|
||||
end
|
||||
|
||||
password = Devise.friendly_token
|
||||
context.user.assign_attributes(
|
||||
password:,
|
||||
@@ -27,12 +22,20 @@ class Portainer::Login
|
||||
)
|
||||
context.user.save!
|
||||
provider = context.user.providers.find_or_initialize_by(provider: "portainer")
|
||||
provider.assign_attributes(access_token: jwt)
|
||||
provider.auth = {
|
||||
info: {
|
||||
username: portainer_user.username
|
||||
}
|
||||
}.to_json
|
||||
provider.access_token: portainer_user.jwt
|
||||
provider.save!
|
||||
|
||||
unless context.account.users.include?(context.user)
|
||||
context.account.account_users.create!(user: context.user)
|
||||
end
|
||||
rescue Portainer::Client::AuthenticationError => e
|
||||
context.user.errors.add(:base, "Invalid username or password")
|
||||
context.fail_and_return!
|
||||
rescue Portainer::Client::ConnectionError => e
|
||||
context.fail_and_return!(e.message)
|
||||
rescue StandardError => e
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
class Portainer::Onboarding::AuthenticateWithPortainer
|
||||
extend LightService::Action
|
||||
expects :username, :password, :provider_url
|
||||
promises :jwt
|
||||
promises :portainer_user
|
||||
|
||||
executed do |context|
|
||||
context.jwt = Portainer::Client.authenticate(
|
||||
context.portainer_user = Portainer::Client.authenticate(
|
||||
auth_code: context.password,
|
||||
username: context.username,
|
||||
provider_url: context.provider_url
|
||||
)
|
||||
context.fail_and_return!("Invalid username or password") if context.jwt.blank?
|
||||
rescue Portainer::Client::AuthenticationError => e
|
||||
context.fail_and_return!(e.message)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class Portainer::Onboarding::CreateUserWithStackManager
|
||||
extend LightService::Action
|
||||
expects :jwt, :username, :provider_url, :account_name
|
||||
expects :portainer_user, :username, :provider_url, :account_name
|
||||
promises :user, :account, :stack_manager
|
||||
|
||||
executed do |context|
|
||||
@@ -19,7 +19,12 @@ class Portainer::Onboarding::CreateUserWithStackManager
|
||||
context.user.save!
|
||||
|
||||
provider = context.user.providers.find_or_initialize_by(provider: "portainer")
|
||||
provider.assign_attributes(access_token: context.jwt)
|
||||
provider.auth = {
|
||||
info: {
|
||||
username: context.portainer_user.username
|
||||
}
|
||||
}.to_json
|
||||
provider.access_token = context.portainer_user.jwt
|
||||
provider.save!
|
||||
|
||||
if context.user.accounts.empty?
|
||||
|
||||
Reference in New Issue
Block a user