Code Monkey home page Code Monkey logo

laravel-digitalocean's Introduction

Laravel DigitalOcean

Laravel DigitalOcean was created by, and is maintained by Graham Campbell, and is a DigitalOcean PHP API Client bridge for Laravel. It utilises my Laravel Manager package. Feel free to check out the change log, releases, security policy, license, code of conduct, and contribution guidelines.

Banner

Build Status StyleCI Status Software License Packagist Downloads Latest Version

Installation

This version requires PHP 7.4-8.3 and supports Laravel 8-11.

DigitalOcean L5.5 L5.6 L5.7 L5.8 L6 L7 L8 L9 L10 L11
5.4
6.0
7.3
8.4
9.0
10.4

To get the latest version, simply require the project using Composer:

$ composer require "graham-campbell/digitalocean:^10.4"

Once installed, if you are not using automatic package discovery, then you need to register the GrahamCampbell\DigitalOcean\DigitalOceanServiceProvider service provider in your config/app.php.

You can also optionally alias our facade:

        'DigitalOcean' => GrahamCampbell\DigitalOcean\Facades\DigitalOcean::class,

Configuration

Laravel DigitalOcean requires connection configuration.

To get started, you'll need to publish all vendor assets:

$ php artisan vendor:publish

This will create a config/digitalocean.php file in your app that you can modify to set your configuration. Also, make sure you check for changes to the original config file in this package between releases.

There are two config options:

Default Connection Name

This option ('default') is where you may specify which of the connections below you wish to use as your default connection for all work. Of course, you may use many connections at once using the manager class. The default value for this setting is 'main'.

DigitalOcean Connections

This option ('connections') is where each of the connections are setup for your application. Example configuration has been included, but you may add as many connections as you would like. Note that the 2 supported authentication methods are: "none" and "token".

Usage

DigitalOceanManager

This is the class of most interest. It is bound to the ioc container as 'digitalocean' and can be accessed using the Facades\DigitalOcean facade. This class implements the ManagerInterface by extending AbstractManager. The interface and abstract class are both part of my Laravel Manager package, so you may want to go and checkout the docs for how to use the manager class over at that repo. Note that the connection class returned will always be an instance of DigitalOceanV2\Client.

Facades\DigitalOcean

This facade will dynamically pass static method calls to the 'digitalocean' object in the ioc container which by default is the DigitalOceanManager class.

DigitalOceanServiceProvider

This class contains no public methods of interest. This class should be added to the providers array in config/app.php. This class will setup ioc bindings.

Real Examples

Here you can see an example of just how simple this package is to use. Out of the box, the default adapter is main. After you enter your authentication details in the config file, it will just work:

use GrahamCampbell\DigitalOcean\Facades\DigitalOcean;
// you can alias this in config/app.php if you like

DigitalOcean::droplet()->powerOn(12345);
// we're done here - how easy was that, it just works!

DigitalOcean::size()->getAll();
// this example is simple, and there are far more methods available

The digitalocean manager will behave like it is a DigitalOceanV2\Client class. If you want to call specific connections, you can do with the connection method:

use GrahamCampbell\DigitalOcean\Facades\DigitalOcean;

// select the your_connection_name connection, then get going
DigitalOcean::connection('your_connection_name')->droplet()->getById(12345);

With that in mind, note that:

use GrahamCampbell\DigitalOcean\Facades\DigitalOcean;

// writing this:
DigitalOcean::connection('main')->region()->getAll();

// is identical to writing this:
DigitalOcean::region()->getAll();

// and is also identical to writing this:
DigitalOcean::connection()->region()->getAll();

// this is because the main connection is configured to be the default
DigitalOcean::getDefaultConnection(); // this will return main

// we can change the default connection
DigitalOcean::setDefaultConnection('alternative'); // the default is now alternative

If you prefer to use dependency injection over facades like me, then you can easily inject the manager like so:

use GrahamCampbell\DigitalOcean\DigitalOceanManager;

class Foo
{
    private DigitalOceanManager $digitalocean;

    public function __construct(DigitalOceanManager $digitalocean)
    {
        $this->digitalocean = $digitalocean;
    }

    public function bar()
    {
        $this->digitalocean->region()->getAll();
    }
}

app(Foo::class)->bar();

For more information on how to use the DigitalOceanV2\Client class we are calling behind the scenes here, check out the docs at https://github.com/DigitalOceanPHP/Client/tree/4.9.0#examples, and the manager class at https://github.com/GrahamCampbell/Laravel-Manager#usage.

Further Information

There are other classes in this package that are not documented here. This is because they are not intended for public use and are used internally by this package.

Security

If you discover a security vulnerability within this package, please send an email to [email protected]. All security vulnerabilities will be promptly addressed. You may view our full security policy here.

License

Laravel DigitalOcean is licensed under The MIT License (MIT).

For Enterprise

Available as part of the Tidelift Subscription

The maintainers of graham-campbell/digitalocean and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. Learn more.

laravel-digitalocean's People

Contributors

cozylife avatar grahamcampbell avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-digitalocean's Issues

Droplets list count

Hi there.

Is there any way to change "per_page" parameter for droplets list?
As I understand method getAll() doesn't allow this

public function getAll(?string $tag = null)
    {
        $droplets = $this->get('droplets', null === $tag ? [] : ['tag_name' => $tag]);

        return \array_map(function ($droplet) {
            return new DropletEntity($droplet);
        }, $droplets->droplets);
    }

DO docs says that "per_page" default value is 20, but I have more then 20 droplets, so I can't get them all.

Getting a single Droplet?

Isn't there a method for getting just a single droplet for the specific ID?
Like:

    public function power($droplet_id) {

        dd(DigitalOcean::droplet($droplet_id));
        return redirect()->back();
    }

Not compatible Laravel 5.6

The package is not compatible with laravel 5.6.x

Problem 1
    - Conclusion: don't install graham-campbell/digitalocean v4.0.1
    - Conclusion: don't install graham-campbell/digitalocean v4.0.0
    - Conclusion: remove laravel/framework v5.6.1
    - Installation request for graham-campbell/digitalocean ^4.0 -> satisfiable by graham-campbell/digitalocean[4.0.x-dev, v4.0.0, v4.0.1].
    - Conclusion: don't install laravel/framework v5.6.1
    - graham-campbell/digitalocean 4.0.x-dev requires illuminate/support 5.1.*|5.2.*|5.3.*|5.4.*|5.5.* -> satisfiable by illuminate/support[5.1.x-dev, 5.2.x-dev, 5.3.x-dev, 5.4.x-dev, 5.5.x-dev, v5.1.1, v5.1.13, v5.1.16, v5.1.2, v5.1.20, v5.1.22, v5.1.25, v5.1.28, v5.1.30, v5.1.31, v5.1.41, v5.1.6, v5.1.8, v5.2.0, v5.2.19, v5.2.21, v5.2.24, v5.2.25, v5.2.26, v5.2.27, v5.2.28, v5.2.31, v5.2.32, v5.2.37, v5.2.43, v5.2.45, v5.2.6, v5.2.7, v5.3.0, v5.3.16, v5.3.23, v5.3.4, v5.4.0, v5.4.13, v5.4.17, v5.4.19, v5.4.27, v5.4.36, v5.4.9, v5.5.0, v5.5.16, v5.5.17, v5.5.2, v5.5.28, v5.5.33, v5.5.34].
    - don't install illuminate/support 5.1.x-dev|don't install laravel/framework v5.6.1
    - don't install illuminate/support 5.2.x-dev|don't install laravel/framework v5.6.1
    - don't install illuminate/support 5.3.x-dev|don't install laravel/framework v5.6.1
    - don't install illuminate/support 5.4.x-dev|don't install laravel/framework v5.6.1
    - don't install illuminate/support 5.5.x-dev|don't install laravel/framework v5.6.1
    - don't install illuminate/support v5.1.1|don't install laravel/framework v5.6.1
    - don't install illuminate/support v5.1.13|don't install laravel/framework v5.6.1
    - don't install illuminate/support v5.1.16|don't install laravel/framework v5.6.1
    - don't install illuminate/support v5.1.2|don't install laravel/framework v5.6.1
    - don't install illuminate/support v5.1.20|don't install laravel/framework v5.6.1
    - don't install illuminate/support v5.1.22|don't install laravel/framework v5.6.1
    - don't install illuminate/support v5.1.25|don't install laravel/framework v5.6.1
    - don't install illuminate/support v5.1.28|don't install laravel/framework v5.6.1
    - don't install illuminate/support v5.1.30|don't install laravel/framework v5.6.1
    - don't install illuminate/support v5.1.31|don't install laravel/framework v5.6.1
    - don't install illuminate/support v5.1.41|don't install laravel/framework v5.6.1
    - don't install illuminate/support v5.1.6|don't install laravel/framework v5.6.1
    - don't install illuminate/support v5.1.8|don't install laravel/framework v5.6.1
    - don't install illuminate/support v5.2.0|don't install laravel/framework v5.6.1
    - don't install illuminate/support v5.2.19|don't install laravel/framework v5.6.1
    - don't install illuminate/support v5.2.21|don't install laravel/framework v5.6.1
    - don't install illuminate/support v5.2.24|don't install laravel/framework v5.6.1
    - don't install illuminate/support v5.2.25|don't install laravel/framework v5.6.1
    - don't install illuminate/support v5.2.26|don't install laravel/framework v5.6.1
    - don't install illuminate/support v5.2.27|don't install laravel/framework v5.6.1
    - don't install illuminate/support v5.2.28|don't install laravel/framework v5.6.1
    - don't install illuminate/support v5.2.31|don't install laravel/framework v5.6.1
    - don't install illuminate/support v5.2.32|don't install laravel/framework v5.6.1
    - don't install illuminate/support v5.2.37|don't install laravel/framework v5.6.1
    - don't install illuminate/support v5.2.43|don't install laravel/framework v5.6.1
    - don't install illuminate/support v5.2.45|don't install laravel/framework v5.6.1
    - don't install illuminate/support v5.2.6|don't install laravel/framework v5.6.1
    - don't install illuminate/support v5.2.7|don't install laravel/framework v5.6.1
    - don't install illuminate/support v5.3.0|don't install laravel/framework v5.6.1
    - don't install illuminate/support v5.3.16|don't install laravel/framework v5.6.1
    - don't install illuminate/support v5.3.23|don't install laravel/framework v5.6.1
    - don't install illuminate/support v5.3.4|don't install laravel/framework v5.6.1
    - don't install illuminate/support v5.4.0|don't install laravel/framework v5.6.1
    - don't install illuminate/support v5.4.13|don't install laravel/framework v5.6.1
    - don't install illuminate/support v5.4.17|don't install laravel/framework v5.6.1
    - don't install illuminate/support v5.4.19|don't install laravel/framework v5.6.1
    - don't install illuminate/support v5.4.27|don't install laravel/framework v5.6.1
    - don't install illuminate/support v5.4.36|don't install laravel/framework v5.6.1
    - don't install illuminate/support v5.4.9|don't install laravel/framework v5.6.1
    - don't install illuminate/support v5.5.0|don't install laravel/framework v5.6.1
    - don't install illuminate/support v5.5.16|don't install laravel/framework v5.6.1
    - don't install illuminate/support v5.5.17|don't install laravel/framework v5.6.1
    - don't install illuminate/support v5.5.2|don't install laravel/framework v5.6.1
    - don't install illuminate/support v5.5.28|don't install laravel/framework v5.6.1
    - don't install illuminate/support v5.5.33|don't install laravel/framework v5.6.1
    - don't install illuminate/support v5.5.34|don't install laravel/framework v5.6.1
    - Installation request for laravel/framework (locked at v5.6.1, required as 5.6.*) -> satisfiable by laravel/framework[v5.6.1].

#17

Unable to configure

Hi,

I installed the package as per the instructions with guzzlehttp. I have put my DO token in config/digitalocean.php but no matter which connection I try to use, I always get Connection {connection_name} is not configured.
Please guide me as to where am I going wrong.
Thanks!

What is this used for?

Is there any information that explaines what this package is used for? I don't know what 'bridge to' means...

config/digitalocean.php not being created?

Probably a non-issue but I'm running through the guide to get this setup

composer.json file:

    "graham-campbell/digitalocean": "^3.2",
    "guzzlehttp/guzzle": "^6.0",

When I run a composer update in the /vendor/ folder I get guzzlehttp and graham-campbell folders as expcted. However when I run php artisan vendor:publish it doesn't generate the digitalocean.php file

Running XAMPP on a fresh install on Laravel Boilerplate (http://laravel-boilerplate.com/)

Issues running publish:config

when I try and run (using Laravel 5)

php artisan publish:config graham-campbell/digitalocean

I get an error:

exception 'BadMethodCallException' with message 'Call to undefined method [package]' in /home/vagrant/code/l5try/vendor/laravel/framework/src/Illuminate/Support/ServiceProvider.php:140
Stack trace:

I'm just trying to confirm if this is something I did wrong or if it's because L5 is still in flux.

Thanks

Laravel 10 Support

Hi,

When can we expect laravel 10 support, at the moment I am unable to upgrade since this package requires graham-campbell/manager ^4.7 which requires illuminate/support ^5.5 || ^6.0 || ^7.0 || ^8.0 || ^9.0 and there is a version conflict here.

When attempting to update, I get the following:

 Updating dependencies
 Your requirements could not be resolved to an installable set of packages.
 
   Problem 1
     - illuminate/support[v5.6.0, ..., 5.8.x-dev] require php ^7.1.3 -> your php version (8.2.1) does not satisfy that requirement.
     - illuminate/support[v6.0.0, ..., v6.19.1] require php ^7.2 -> your php version (8.2.1) does not satisfy that requirement.
     - illuminate/support[v7.0.0, ..., v7.28.4] require php ^7.2.5 -> your php version (8.2.1) does not satisfy that requirement.
     - illuminate/support[v8.0.0, ..., v8.11.2] require php ^7.3 -> your php version (8.2.1) does not satisfy that requirement.
     - Root composer.json requires graham-campbell/digitalocean ^9.0 -> satisfiable by graham-campbell/digitalocean[v9.0.0, 9.0.x-dev].
     - Conclusion: don't install laravel/framework v10.0.1 (conflict analysis result)
     - Conclusion: don't install laravel/framework v10.0.2 (conflict analysis result)
     - Conclusion: don't install laravel/framework v10.0.3 (conflict analysis result)
     - graham-campbell/digitalocean[v9.0.0, ..., 9.0.x-dev] require graham-campbell/manager ^4.7 -> satisfiable by graham-campbell/manager[v4.7.0, 4.7.x-dev].
     - Conclusion: don't install laravel/framework v10.0.0 (conflict analysis result)
     - graham-campbell/manager[v4.7.0, ..., 4.7.x-dev] require illuminate/support ^5.5 || ^6.0 || ^7.0 || ^8.0 || ^9.0 -> satisfiable by illuminate/support[v5.5.0, ..., 5.8.x-dev, v6.0.0, ..., 6.x-dev, v7.0.0, ..., 7.x-dev, v8.0.0, ..., 8.x-dev, v9.0.0-beta.1, ..., 9.x-dev].
     - Only one of these can be installed: illuminate/support[v5.5.0, ..., 5.8.x-dev, v6.0.0, ..., 6.x-dev, v7.0.0, ..., 7.x-dev, v8.0.0, ..., 8.x-dev, v9.0.0-beta.1, ..., 9.x-dev, v10.0.0, ..., 10.x-dev], laravel/framework[v10.0.0, ..., 10.x-dev]. laravel/framework replaces illuminate/support and thus cannot coexist with it.
     - Root composer.json requires laravel/framework ^10.0 -> satisfiable by laravel/framework[v10.0.0, ..., 10.x-dev].

Volume() issue

$volume   = DigitalOcean::volume()->getAll();
dd($volume);

[]

Is the volume method broke or is it different method to access this block storage data.

Problem with pulling data

Hi,

When I am trying to call the index function I've got this error returned:

FatalThrowableError in GuzzleHttpAdapter.php line 133:
Call to a member function getBody() on null

My functions:

public function __construct(DigitalOceanManager $digitalocean)
{
  $this->digitalocean = $digitalocean;
}

public function index()
{
  dd($this->digitalocean->droplet()->getAll());
}

Can someone help me please?

Dynamically set the API access token

I have the bridge working beautifully with my static token setting as described in your setup documentation (using guzzle5). Everything works as expected but I would like to be able to set the token 'on the fly' if you will.

Can you explain how I can override the token?

TTL not set while creating domain record

Hi Graham
I have been trying set TTL on the domain record create and update methods but no luck.

The toin0u library did not state it either
// return the DomainRecord entity 123 of the domain 'baz.dk' updated with new-name, new-data, priority 1, port 2, weight 3, flags 0, tag issue (name, data, priority, port, weight, flags and tag are nullable)
$updated = $domainRecord->update('baz.dk', 123, 'new-name', 'new-data', 1, 2, 3, 0, 'issue');

kindly assist

composer problem

composer update

Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

Problem 1

  • The requested package graham-campbell/digitalocean could not be found in any version, there may be a typo in the package name.

Potential causes:

Read http://getcomposer.org/doc/articles/troubleshooting.md for further common problems.

composer.json

"require": {
"laravel/framework": "4.2.",
"graham-campbell/digitalocean": "~1.0",
"hashids/hashids": "1.0.0",
"jenssegers/agent": "
"
},

Installed

Hey,

I was hope you could give me some pointers on how to get this working? So far I have go this installed and added a token. How do I say list the droplets on my account or see if its even corrected to my the API successfully?

Cheers.

Help needed. Dynamic API token

So far I have this put in a InitializeDO method. Not sure if it's the right way but it works just fine. Correct me if there's a better way to set the API token dynamically.

$this->adapter = new Adapters\ConnectionFactory();
$config = [
	'driver'  => 'guzzlehttp',
	'token'   => Auth::user()->do_api_token
];
$this->adapter->make($config);
$this->dof = new DigitalOceanFactory($this->adapter);
$this->dof->make($config);
$this->do = $this->dof->make($config);

The problem is that I can't access the user(Auth::user()) in the consturctor of the controller, so I'm calling InitializeDO in each one of my methods(index, show, edit, etc.). I don't think this is the best approach.
And here comes my question, how can I write this, so it's called just once and working with $this->do afterwards?

Laravel 5.7 Call to a member function getBody() on null

    "graham-campbell/digitalocean": "^5.1",
    "guzzlehttp/guzzle": "^6.3",
    "kriswallsmith/buzz": "^0.17.2"

when calling any function for example DigitalOcean::size()->getAll();

Issue with C:\xampp\htdocs\front\myadmin\vendor\toin0u\digitalocean-v2\src\Adapter\GuzzleHttpAdapter.php

Line 132: $body = (string) $this->response->getBody();

Any ideas

FatalErrorException in GuzzleHttpAdapter.php line 135:

Got this installed and setup - updated my digitalocean.php config file with my tokens.

Running any command e.g.
DigitalOcean::connection('main')->region()->getAll();

Results in:
FatalErrorException in GuzzleHttpAdapter.php line 135:
Call to a member function getBody() on null

I am using guzzlehttp.

Token is correct if I run a DO API call manually via command line. I am running the site locally on XAMPP (no SSL)

Save Files

Hi There

With this package could I save files in a DO Volume ?

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.